ImageMagick and RMagick for Testing Colors
A couple weeks ago I started working on a pure-Ruby GPIO library for the Raspberry Pi to see whether I could get rid of a persistent glitch I was experiencing while driving the ShiftBrite LED modules. I still haven’t been able to pinpoint the issue but while I was at it I put together some color conversion classes. Since I couldn’t test the libraries on the LED modules directly, I needed a simple way to check that the conversion worked beyond the numbers looking OK and matching up with a few test cases from Photoshop.
I have never used the Ruby RMagick library before so killing two birds with one stone seemed a nice way to learn something new and test whether my converters were working properly.
Unfortunately, I had some troubles getting RMagick to compile properly on Mountain Lion, despite a bunch of links on doing just what I was looking to do. Luckily, I finally found this post in Japanese. Luckily, while I don’t speak Japanese, code can be a universal language and the author’s trick worked for me. Here it is again in the hopes that it will pop up a bit higher on the search indices:
Mac OS X, Mountain Lion, ImageMagick and RMagick installation using Homebrew and Rubygems:
$ brew update $ brew install imagemagick $ ln -s /usr/local/lib/libMagickCore-Q16.dylib /usr/local/lib/libMagickCore.dylib $ gem install rmagick $ rm /usr/local/lib/libMagickCore.dylib
Excellent, we’re in business! Pulled up
irb and tested a few commands, got my head around the
Magick::Draw class, and wrote up a test script. The simplest test case I could think of was to
render up a full HSV spectrum with the hue angle on the X-axis and the saturation and value levels
along the Y-axis. Here is the complete source for the test.
The results of the run showed what I wanted to see:
I’ve also been putting up this and my other Raspberry Pi sources up on GitHub. Give them a look, fork them, send me pull requests, let me know if it helps you.
blog comments powered by Disqus