I was already using MojoMagick in a project. I needed to add some functionality that would resize an image to fill a given space. That is, given width and height, resize the image so that it maximally fills the box (and maybe hangs over the edge). Clearly, this is a job for ImageMagick, so I thought I should be able to access this functionality through MojoMagick. Sadly, MojoMagick doesn’t expose this resizing functionality.
I decided to try moving to RMagick. RMagick seems to be all the hotness based on google searches for ImageMagick and ruby so it seemed like the way to go. And while I was upgrading, I thought I should also get on to the latest version of ImageMagick (from ~6.3 to 6.7).
Thus, I ran down a rat hole that was not terribly pleasant. Issues included:
- ImageMagick rpm required building from source (old machine, old OS)
- Much fighting with bundler and rvm versions and ldconfig to get the machine’s head on straight.
- Finally, ruby/rake segfaulting with every run – which after some reading seemed to be related to RMagick + ImageMagick upgrades that left old bits of ImageMagick around on the system. (read more at stack overflow.)
The fix? Simple: go back to MojoMagick — the dirt simple ImageMagick-Ruby library. I pulled the source from the svn repo, added enough stuff to get a bundler gem built, added the functionality I needed (which was about a 2 line change), and stuck it up on github.
Granted, RMagick is very slick and ruby-ish and has much more of ImageMagick mapped into it’s API. And on a more current system the install can be easier, though not necessarily painless (see rmagick on ubuntu at stackoverflow). But if you don’t need too many bells and whistles, the bare bones ImageMagick functionality that you get with MojoMagick might save you some trouble.
Put it in your Gemfile with
gem 'mojo_magick', :git => 'git://github.com/rcode5/mojo_magick.git'