Making RMagick suck less with Tiger July 6th
[Disclaimer: If you just want a solution to your RMagick problems, click here]
You’ve jumped on the Rails bandwagon just like you jumped on the Mac bandwagon some time ago. You love developing locally, checking in your changes into your remote repository using either Subversion or SVK. You’re working on your first big project with all your new tools. You’re reading Getting Things Done and setup your task lists to get things off of your brain.
Still reading? Great.
Now you’re off to your first major task: Resizing images uploaded by your users. You’ve been doing this in PHP for years, so you expect this to be a piece of cake. You couldn’t be further from the truth (presuming you’re actually using the combination of hard- and software I outlined above).
- So, what’s wrong?
Everything looks great on first sight. You’ve installed Ruby from Darwinports to get the `readline`-goodness. Same goes for ImageMagick, which you know from stated former PHP days. You’ve installed Rails via RubyGems. You’re sick of using backticks to call binary programs floating around on your harddrive. You fall in love with the stunning API from the RMagick folks and instantly install its gem. You feel ready to type in some test code.
You fire up your dear friend `script/console`, simply `require` the RMagick library and.. hey!
/opt/local/lib/ruby/site_ruby/1.8/powerpc-darwin8.1.0/RMagick.bundle:
[BUG] Bus Error
Now that wasn’t planned!
- Digging for a solution
What do you do in situations like this? You ask Mr. Google. Yeah right, “did not match any documents”.
You dig around a little deeper, you talk to your fellas, you get pointed to tickets, you start experimenting.
After a few hours of digging, you develop completely braindead patterns.
$ irb --prompt-mode simple
>> require 'RMagick'
/opt/local/lib/ruby/site_ruby/1.8/powerpc-darwin8.2.0/RMagick.bundle:
[BUG] Bus Error
$ irb
irb(main):001:0> require 'RMagick'
=> true
You’re about to lose your confidence in all you know and learned. You recompile heaps of darwinports packages using GCC 3.3 instead of the 4.0 default. Not even the fact that RMagick works fine in the Linux production environment your final application will run in comforts you.
- 10 hours later
That one guy who had been untiringly trying to dry your tears over this whole dilemma senselessly drops a line within your IRC conversation
i hear that graphics magick is much better
What the hell? You're still trying to make the best of it and you don't give a damn about the millions of lines of recompiled sourcecode piling up on your harddrive. You even notice that there is a darwinports package of GraphicsMagick. You fire up your terminal to install it.
After a few minutes of your PowerMac G5 (yes, that dying breed) fuming through the GraphicsMagick source code, you recompile rmagick. You ignore the warnings just as thoroughly as you ignore all End User License Agreements you ever agreed to.
You feel your heart beat up your carotid artery as you fire up the Rails `console`. You’re typing slowly. You think about every key you hit on your lovely Bluetooth Keyboard. But you’re almost there. You hit `return`.
require 'RMagick'
=> true
Holy loading RMagick, Batman!
- Is that really it?
You continue to hack on your application. You enjoy your freshly developed Image Uploading Mechanism 9000. You start uploading images. You start with a funky GIF. You upload a JPEG next. WHAMM! An exception makes its way through your Cinema Display directly into your cerebral hemisphere.
No decode delegate for this image format (jpeg)
Huh?
You realize you weren’t supposed to ignore all those warnings during the GraphicsMagick compilation. You re-run the `port` command with the `-d` option to see what’s going on behind the scenes.
checking jpeglib.h usability... no
checking jpeglib.h presence... no
checking for jpeglib.h... no
You check config.log. You remember a little more of your unix knowhow. You notice this thing is just lacking correct paths to your darwinports install in `/opt/local`. You check the Portfile. You notice there’s nothing in there to tell the build system where its libraries are. You blatantly rip off the maintainer of the ImageMagick port and stick his `configure.env` line straight into GraphicsMagick’s Portfile.
configure.env CPPFLAGS="-I${prefix}/include" LDFLAGS="-L${prefix}/lib"
You’re not ashamed of doing things like that at this point and blame it on your state of mind. You recompile GraphicsMagick (again!). You restart Webrick. You upload a JPEG again. You get redirected to your image index.
Redirection? You kidding? You look twice for an error message. You `grep` your logs. Twice. Nothing.
You sink back into your office chair. You start thinking about doing unit tests but opt to document about your findings first.
FIN
- The meat
Okay, enough narrating, you want a solution to your RMagick problem on Mac OS X 10.4? Here we go.
RMagick under Tiger doesn’t work nicely with ImageMagick for some reason which is why we’ll be using GraphicsMagick in this walkthrough
1. Edit the GraphicsMagick Portfile using your favorite editor. The file in question is located here:
`/opt/local/var/db/dports/sources/ rsync.rsync.opendarwin.org_dpupdate_dports/graphics/GraphicsMagick`
2. Paste the following line into it, the actual position doesn't matter much:
`configure.env CPPFLAGS="-I${prefix}/include" LDFLAGS="-L${prefix}/lib"`
3. Install GraphicsMagick via Darwinports:
`sudo port install GraphicsMagick`
4. (Re-)install RMagick via Rubygems:
`sudo gem install rmagick`
5. Rejoice a working RMagick environment under Mac OS X!

14 comments
Jump to comment form