imagettfbbox() Could not find/open font
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


January 10th, 2009 at 6:38 pm
hi
wmdmoeroxmu7pfwr
good luck
March 5th, 2009 at 4:08 pm
Found that instead of using an absolute path I was able to use ./ instead. For instance I changed:
var $font = ‘monofont.ttf’;
to
var $font = ‘./monofont.ttf’;
and it worked.
Got this idea from http://ubuntuforums.org/archive/index.php/t-905187.html
May 8th, 2009 at 4:00 pm
nice solution, fixed my problem
Thanks a lot
August 21st, 2009 at 1:41 am
thank you .. you save my day
June 6th, 2011 at 9:13 pm
Thank you. This fixed my problem! Mine’s PHP5.2.10 on Ubuntu 11.4
March 13th, 2012 at 7:20 am
@David Valentiate :
Good job, your tips is working for me