I've been putting a few cycles into souping up the ongoing software to brighten up the front page with an “image of the day,” and also to make the inline versions of the pictures smaller so as to go easier on the modemistas. The programming is pretty easy, but getting the tools together is a walk through Open Source Hell. (Teaser: Contains XML Insider Goodie)

A word on pictures generally: I look at my server logs, and it's painfully obvious that while some of the technical screeds here get thousands of readers, my little photo outings are viewed only by a handful comprising my immediate relatives and those who are convinced that if they look hard enough they'll find XML Insider Secrets (see below). I don't care, I like taking pictures and I like fiddling with them and I like posting them on the web, so ignore 'em all you want.

GD · Anyhow, what I needed was to be able to read, resize, and write the images from the ongoing Perl code. There are several facilities like ImageMagick that rely on using the X Window System libraries, but first of all I try to stay from X when I can, and second there's no good reason for the guy who runs the servers where ongoing lives to install and maintain X software.

So I settled on GD, a nice C-callable library that's been around forever (we use it in Visual net) and has a nice associated Perl module maintained by the redoubtable Lincoln Stein.

Well, normally, on Mac OS X if you want to use some Open Source stuff, you use the very slick fink package manager; for example, if you're looking for the “Find Outer Otter” package it usually suffices to say sudo fink install foo and go for lunch while fink compiles it all.

Sure enough, fink knows about libgd and GD.pm, so I stood back and let 'er rip. Sigh, it turns out that fink doesn't include Perl, it assumes you got it with OS X or did it yourself, and it has modules for Perl 5.6. Well, I did get my own, and I'm running Perl 5.8, which you need if you want to do a lot of Unicode processing. So it didn't work.

CPAN Hell · So, this meant I had to do it myself. Well, if you are looking for anything in the land of Perl, the place to look is CPAN, the Comprehensive Perl Action Network, where approximately everything can be found, not just once but on mirrors everywhere. I use the term “found” loosely - the chance of anyone who's not a much harder-core Perl geek than me finding some random package on CPAN is approximately zero. There seem to be search facilities, but I've never got them to do anything useful. To start with, the central organizing principle of CPAN is that everything lives in a directory named after its author.

Fortunately, there's the “CPAN Shell”, which gives you a command-line prompt and you can say things like install GD. Mind you, whenever I do this, the shell spends fifteen minutes trying (and failing) to download package directories using some form of FTP that clearly Just Doesn't Work, before it switches modes and starts fetching things with some other FTP mode that does.

OK, I fetched GD.pm, and since fink had already built libgd.a for me, I thought I would be fine. Nope; it turns out that the latest and greatest GD.pm that you get from CPAN requires that you have v2.0.5 or greater of libgd.a and fink has some earlier version.

OK, I sighed, and was able to get libgd.a v2.0.12 sources from Boutell's site linked above, and of course then it wanted libz.a, which OS X comes with (but not the include files) so I had to go get that. And of course, if you want to be able to read JPEGs, which are only generated by every digital camera in the universe, you have to go track down libjpg.a and build that too. This is definitely two-steps-back-one-forward territory.

Bosak, McGrath, and Prescod
XML Insiders Sean McGrath, Jon Bosak, and Paul Prescod on the January 2001 XML Geek Cruise

At some point during this odyssey I bashed away in Google looking for other people who'd had the problem, and saw that none other than Randal Schwartz, senior Perl deity, had been posting on the subject not too long ago. I know Randal from a shared Geek Cruise (that page fails to work in lots of browsers, bad O'Reilly) a while back, so I emailed him and he let me know that GD is famously difficult to build.

A little later, I had a working libgd.a, and I went back to CPAN and tried again for GD.pm and hey, it built! Oops, it failed three of the installation tests. Crap. But I tried it out and it seems to work fine, so I'm ignoring those failed tests.

Windows Wins · My wife wanted to do some batch-job image crunching, and she has a Windows laptop and is fine with Perl, I recommended GD and moaned about what a crock it was getting it to build. Oh yeah? She fired up ActiveState's “Perl Package Manager” (by typing ppm at the DOS command-line), entered install GD, and it was all done in like 20 seconds.

Dammit, Unix is better than Windows because, er... because it just is, that's right.

GD is Good · Mind you, GD is a really nice piece of software, once you get it going. Here's how you scale and resize an image to make a thumbnail:

  open($gfile, "<$inDir/$src") || die "Can't open image file $src";
  my $bitmap = new GD::Image($gfile);
  my ($w, $h) = $bitmap->getBounds();

  # make thumbnail version
  my $tnH = int($tnWidth * $h / $w);
  my $out = new GD::Image($tnWidth, $tnH);

  $out->copyResampled($bitmap, 0, 0, 0, 0, $tnWidth, $tnH, $w, $h)

  open(Out, ">$tnDir/$src") || die "Can't open thumbnail for $src";
  print Out $out->png;

I suspect that Paintshop or Debabelizer might make a slightly better-looking thumbnail, but I don't know how to get at them from Perl code.

Debian Wins, Except When it Doesn't · I was emailing Matt, the guy who runs ongoing's colo, whining about my GD problems, and he's a kind of a Debian chauvinist (I have a Debian box in my basement too), and he wrote back pityingly “Tim, Tim, on Debian you just type apt-get install gd-pm and it's all done!”. Sigh.

Speaking of all done, I got all those graphics updates done on the ongoing software here on my Mac, and tried a run of the new version over on the colo. Oops! It turns out that Debian, just like fink, got that back-rev of GD, and it doesn't have that copyResampled method, so I'm blocked for the moment. In fact I've been informed that there's some metaphysical relationship between fink and Debian's apt-get and friends, so maybe this isn't a surprise.

Anyhow, Open Source is wonderful stuff except when it's not; but we all knew that already.

author · Dad
colophon · rights

May 04, 2003
· Technology (90 fragments)
· · Open Source (82 more)

By .

The opinions expressed here
are my own, and no other party
necessarily agrees with them.

A full disclosure of my
professional interests is
on the author page.

I’m on Mastodon!