ImageMagick for Rails

This extension provides an easy way to use ImageMagick commands to process images from a Rails template.

The basic idea is this: you have a directory with images, and want to process them with ImageMagick (because you want to resize them, or crop them, or rotate them etc.). Suppose that you have an image gallery, with a controller Photo to display the images. The image files are stored in the directory '/var/lib/photos'. Now, if you want to generate and display thumbnails, you'd do this:

# in the controller
class Photo < ApplicationController
  imagemagick_for '/var/lib/photos'
end

# in the view
<%= imagemagick_tag 'first_photo.jpg', 'resize(100x100)' %>

Request the view, and ta-da: the image first_photo.jpg is displayed, and it is resized to fit within 100x100 pixels. You can use many other ImageMagick commands in the same way.

Installation as a plugin

The easiest way to install this extension is by downloading and installing the extension as a plugin.

In your rails directory, run:
script/plugin install http://opensvn.csie.org/rails_imagemagick_tag/imagemagick_tag/
This will download and install the plugin from the SVN repository. You can now use the imagemagick_for and imagemagick_tag methods in your controllers and views.

Installation with gem

Another way to install this extension is by downloading and installing the gem.

Download the gem and install it. Then, to load the gem, add the following line to your environment.rb:
require_gem 'actionpack-imagemagick'
You can now use the imagemagick_for and imagemagick_tag methods.

Updates - RSS

Gijs van Tulder, gijs at vantulder.net