Sunday, July 23, 2006

The horrors of installing Gruff

Whilst most of my ruby experiences have been very pleasant surprises, getting the graphing subsystem of the project to work has been truly truly unpleasant.
The main ruby/rails graphing library that gets bandied about mostly is Gruff graphs. Admittedly once it started working, its been reasonably good (ignoring a few irritating things with bad documentation and lack of features). Its the getting it to work part that was truly horrible.

There is a LOT of stuff on the web about this, so I'll make it less painful by starting from scratch (as far as I remember anyway).

There are 3 critical ingredients to get gruff to work. These are
  1. ImageMagick
  2. RMagick
  3. Gruff
At the heart of all your problems will inevitably be ImageMagick, so this is where you really need to be careful. I've become a little wary of automatic installers such as 'apt-get install imagemagick' or 'gem install RMagick' for just because an application install doesn't mean its functional. On my home system I had almost no problem, but on the development machine at work, it was a painful mess. Some of the problems I had were.

  • uninitialized constant Gruff
  • uninitialized constant Enum
  • No decode delegate for image format JPEG
  • Can't measure text. Are the fonts installed?
  • Can't find libMagick or one of the dependent libraries.
  • Unknown format: PNG
And nearly all of them can be traced back to a bad ImageMagick/RMagick install. This page helps a lot to debug these issues, but doesn't really give you everything to get it working.

ImageMagick's main saving grace is ./configure gives a nice summary of what it thinks it has and doesn't have. In my case, it picked up bad paths for the fonts, and the debian install didn't have libjpeg or libpng installed, both of which caused issues with installing. So I installed libpng (apt-get install libpng12-dev), and it got picked up no sweat. libjpeg was a little more annoying however. I had to download libjpeg from the website, untar, make, make install and of all things, copy into /usr/local/jpeg-6b.

After that I had to run configure in a bizarre manner

CPPFLAGS=-I/usr/local/jpeg-6b LDFLAGS='-L/usr/local/jpeg-6b' ./configure --with-gs-font-dir=/usr/share/fonts/type1/gsfonts/

The gs-font-dir is to kill my 'can't measure text' problem by making sure it used the correct fonts path for the machine, rather than the default. A make;make install later, I had a installed ImageMagick with correct support for fonts/png/jpeg.

The next thing I did was to install Rmagick (again from source).
Previously when I tried to install RMagick from the gem, it installed successfully (until you tried to use it, at which point it went poof), so source I go...

Once the RMagick installed (with no errors from the make), I installed gruff from the gem, which went smoothly. And voila, everything worked! Thank goodness. Undoubtably the most unnecessarily painful thing. That said, its not that bad once you know what you're doing.

No comments: