imagettfbbox() Could not find/open font

June 4th, 2008

This evening I noticed a problem with the script which generates the image headings for this site. It had stopped working. I hadn’t noticed until now because the process caches all previously generated images and as such it hadn’t actually run for a while.

The error

imagettfbbox() [function.imagettfbbox]: Could not find/open font

The specified font file existed and was readable. I was in fact testing for this eventuality using is_readable() prior to the the imagettfbbox call. After some poking around and a bit of googling I narrowed the problem down to a bug.. or feature in PHP > 4.3.0

The solution

It’s a simple fix, but what worked for me was to pass imagettfbbox an absolute path to the font. This is with PHP 5.2.0. I’ve read of this working for lots of people using various versions of PHP from 4.3.0 onwards, but it also seems that this isn’t always the solution, so your mileage may vary. As usual, it probably depends on a magic combination of seven million random compile flags.

So to sum up. Using imagettfbbox with relative font paths in PHP >= 4.3.0 may result in an error. A solution seems to be to use absolute paths. If this isn’t the issue, it could be spaces in the filename? Your really shouldn’t put spaces in filenames, what are you a windows user?

Official bug report here: http://bugs.php.net/bug.php?id=22092

Sometimes* PHP just sucks

* all the time

Posted in Web | Tagged with: , ,

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.