A collection of computer systems and programming tips that you may find useful.
 
Brought to you by Craic Computing LLC, a bioinformatics consulting company.

Monday, May 10, 2010

Rails, Paperclip and ImageMagick

Ran into trouble generating Thumbnail images using the Paperclip plugin, which delegates the image manipulation to ImageMagick.

The error was "Paperclip::NotIdentifiedByImageMagickError: /tmp/stream,33194,0.jpg is not recognized by the 'identify' command".

A LOT of people have run into this - here is my solution.

In my setup I'm on MacOSX with a binary download of ImageMagick in /usr/local/ImageMagick-6.6.1/bin and I'm running Rails under Apache/Passenger. I've got Paperclip installed as a plugin.

There are 3 steps needed to get this working:

1: Make sure you have ImageMagick working at the UNIX command line level. This involves adding it to your path and exporting these environment variables (pointing to your ImageMagick installation, of course)
MAGICK_HOME=/usr/local/ImageMagick-6.6.1
DYLD_LIBRARY_PATH=/usr/local/ImageMagick-6.6.1/lib
Check that identify works with your images at the command line level. If not then fix those problems first.

2: Tell Paperclip where to find the ImageMagick executables
In config/environment.rb add this at the bottom of the file
Paperclip.options[:command_path] = "/usr/local/ImageMagick-6.6.1/bin"
At this point, after restarting Passenger, you would see that 'identify' is run from within Paperclip but is not able to identify the file... the final step is...

3: Identify needs those two exported environment variables - and Apache/Passenger (or other web servers probably) does not pass those through by default!
In your passenger vhost file add these lines:
SetEnv MAGICK_HOME /usr/local/ImageMagick-6.6.1
SetEnv DYLD_LIBRARY_PATH /usr/local/ImageMagick-6.6.1/lib
Restart apache/passenger and it should work fine.

For me, the binary installation of ImageMagick has worked fine so far. Compiling it yourself is a real pain (make sure you compile for x86-64 if you are on an Intel Mac) - but you don't need to do it. Likewise, you do not need the Rmagick gem if you are using Paperclip, at least for basic image resizing, etc.


 

1 comment:

Anonymous said...

How can you fix the identify issue when using WEBrick during development?

Archive of Tips