Note: I’m quite certain that I’ve bastardized either capitalization of use of / lack there of of _ between the names of the different open source projects here. My apologies in advance.
RMagick, the rails library on top of ImageMagick, can do damn near anything you need to accomplish with an image. Want to add a drop shadow to every profile picture people in your social network upload? Want to resize with a gaussian blur filter? No worries — RMagick can handle it. But you pay a price for this — RMagick is both large (heavy memory usage / slow to load) and prone to leaking memory.
If you’re just looking for simple image manipulation such as basic profile resizing and cropping then you can get just this with the Mini Me of the RMagick work — MiniMagick. And it will pretty dramatically reduce the server load when users are uploading images to your Rails app.
How to Do It
Here’s how to switch over from RMagick to MiniMagick
- Do a sudo gem install mini_magick on your development, test, staging and production boxes
- If you’re using attachment_fu (as you likely are) you need to change your processor engine to mini_magick as follows: :processor => :mini_magick,
- Now we found ourselves having issues with the way mini_magick handled geometry strings and a quick bit of Google_fu led us to this wonderful blog post by Ian Drysdale who told us how to patch into attachment_fu and change the resize routine
- Depending on your crop geometry you might need to manually fix a few images (the issue is whether or not you’re cropping around a center point or from the top).
Tags: scalability
