This post originated from an RSS feed registered with Ruby Buzz
by Patrick Lenz.
Original Post: Making RMagick suck less with Tiger
Feed Title: poocs.net
Feed URL: http://feeds.feedburner.com/poocsnet
Feed Description: Personal weblog about free and open source software, personal development projects and random geek buzz.
[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'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
GraphicsMagick? 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 cervix 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.
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
Edit the GraphicsMagick Portfile using your favorite editor. The file in question is located here: