05 Jul

php5 failing on imagecreatefromjpeg

I had a very strange problem yesterday. I upgraded my office server recently, as I intended to use GD as my graphical library, instead of ImageMagick, which I had been using up until that point. The major difference is that ImageMagick is an external program which must be re-called every time it is used, and GD could be compiled as a linked library, making it quicker to use (imho).

So anyway – I did the upgrade, choosing PHP5 over PHP4 (not that I use its new OOP methods, fantastic as I’m sure they are).

Not being sure how all this would go, I chose a very simple configure script:

./configure --with-apxs2=/www/bin/apxs --with-gd \
  --with-mysql=/usr/local --with-pear --with-zlib

This compiled perfectly, with absolutely no warnings.

As I have four different machines that I test on – my laptop, my home server, the office test server, and the production server, I didn’t notice up until yesterday that the compilation wasn’t quite as perfect as I thought.

I’ve recently converted webme cms to use Pear’s Image_Transform instead of ImageMagick to perform its image manipulation, and was told yesterday that it wasn’t working on the office server.

A quick look was puzzling – no errors, no crashes – the scripts would just run, until an image was manipulated, then it would stop.

It took a bit of digging to find the problem. In order to find it, I first had to correct a few warnings in the Pear modules I was using (the Pear administrators have a policy of not giving a shit about strict code compliance, which means that their code is full of deprecated syntax and commands). I eventually tracked it down to an innocuous line, which called imagecreatefromjpeg.

Placing a line “echo 'test';exit;” before the line echoed ‘test’, but placing it after the line didn’t, so that was definitely the line.

I was a little bit stumped. I tried recompiling with the following configure script:

./configure --with-apxs2=/www/bin/apxs --with-gd \
  --with-mysql=/usr/local --with-pear --with-zlib --with-jpeg

That didn’t work.

Then I read the imagecreatefromjpeg manual page for any thoughts other people might have had – the answer was to explicitly tell PHP what directory the libjpeg.so was located in:

./configure --with-apxs2=/www/bin/apxs --with-gd \
  --with-mysql=/usr/local --with-pear --with-zlib \
  --with-jpeg-dir=/usr/lib

Flying colours!

I’m a bit annoyed that it took me a few hours to figure that out. It would have been nice to at least get an error message that the library hadn’t been found…

%d bloggers like this: