has image plugin

Plugin details

HasImage is a plugin/gem that allows Ruby on Rails applications to have attached images. It is very small and lightweight: it only requires one column (”has_image_file”) in your model to store the uploaded image’s file name.

It is, by design, very simplistic: It only supports using a filesystem for storage, and only supports MiniMagick as an image processor. However, its code is very small, clean and hackable, so adding support for other backends or processors should be fairly easy.

HasImage works best for sites that want to show image galleries with fixed-size thumbnails. It uses ImageMagick’s crop and center gravity functions to produce thumbnails that generally look acceptable, unless the image is a panorama, or the subject matter is close to one of the margins, etc. For most sites where people upload pictures of themselves or their pets the generated thumbnails will look good almost all the time.

Websitehttp://randomba.org Repositorygit://github.com/norman/has_image.git Author Norman Clarke Tags Upload, attachment, asset, image LicenseMIT

Documentation

Install the plugin:
ruby script/plugin install git://github.com/norman/has_image.git

Point-and-drool use case:

It’s probably not what you want, but it may be useful for bootstrapping.

class Member < ActiveRecord::Base
  has_image
end



Single image, no thumbnails, with some size limits:

class Picture < ActiveRecord::Base
  has_image :resize_to => "200x200",
    :max_size => 3.megabytes,
    :min_size => 4.kilobytes
end



Image with some thumbnails:

class Photo < ActiveRecord::Base
  has_image :resize_to => "640x480",
    :thumbnails => {
      :square => "200x200",
      :medium => "320x240"
    },
    :max_size => 3.megabytes,
    :min_size => 4.kilobytes
end



HasImage also provides a view helper to make displaying the images extremely simple:

<%= image_tag_for(@photo, :thumb => :square) %>

Further Documentation

Edit plugin | Back in time (5 older versions) | Last edited by: scott, 5 months ago