|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52403 imagettfbbox/imagettftext "Could not read font" error
Submitted: 2010-07-22 14:24 UTC Modified: 2015-06-28 19:46 UTC
Avg. Score:3.4 ± 1.3
Reproduced:4 of 4 (100.0%)
Same Version:1 (25.0%)
Same OS:2 (50.0%)
From: Assigned:
Status: Suspended Package: GD related
PHP Version: 5.2.13 OS: CentOS4
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2010-07-22 14:24 UTC]
Using the Vera.ttf font, which is part of the Image_Text PEAR package results in an odd error...

The font can be found here:

The error given by imagettfbbox() is "Could not read font".

When tested with is_readable(), the font is indeed readable.

When opening the Vera.ttf font file in windows, it produces the following error:

"The requested file Vera.ttf was not a valid font file."

It would appear that the file may well be corrupt, not that it "could not read".

This error lead to a very confusing situation...

I propose that the error should be more descriptive.

Instead of "Could not read font", consider "Invalid font file".

Test script:

$font = 'Vera.ttf';
$test = imagettfbbox(10, 10, $font, 'test');
echo "\n<br>What PHP version? ".phpversion();
$read = file_exists($font)?'Yes':'No';
echo "\n<br>Does font '$font' exist? ".$read;
$read = is_readable($font)?'Yes':'No';
echo "\n<br>Is font '$font' readable? ".$read;


Expected result:
Warning: imagettfbbox() [function.imagettfbbox]: Could not read font in /home/share/www/dev/test/php/imagettfbbox.php on line 4

Actual result:
Warning: imagettfbbox() [function.imagettfbbox]: Could not read font in /home/share/www/dev/test/php/imagettfbbox.php on line 4

What PHP version? 5.2.13
Does font 'Vera.ttf' exist? Yes
Is font 'Vera.ttf' readable? Yes


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-07-27 01:04 UTC]
-Status: Open +Status: Duplicate -Block user comment: N +Block user comment: Y
 [2010-07-27 01:04 UTC]
Same issue as in bug #52404
 [2010-07-27 10:57 UTC]
-Status: Duplicate +Status: Open
 [2010-07-27 10:57 UTC]
Excuse me, but this is -NOT- the same bug.

Just because it's simply related does not make it the same.

The problem here is the error, not the TTF files, which is the problem described in the other bug report.

Please check and try again.
 [2010-07-27 14:56 UTC]
To clarify:

Expected result:
Warning: imagettfbbox() [function.imagettfbbox]: Invalid font file in /home/share/www/dev/test/php/imagettfbbox.php on line 4

What PHP version? 5.2.13
Does font 'Vera.ttf' exist? Yes
Is font 'Vera.ttf' readable? Yes

Actual result:
Warning: imagettfbbox() [function.imagettfbbox]: Could not read font in /home/share/www/dev/test/php/imagettfbbox.php on line 4

What PHP version? 5.2.13
Does font 'Vera.ttf' exist? Yes
Is font 'Vera.ttf' readable? Yes
 [2010-10-18 18:32 UTC]
To put it very simply, it incorrectly says "Could not read font", when it should say "Invalid font file".

Could somebody fix this or do you need me to supply a patch?
 [2010-10-18 20:29 UTC]
-Status: Open +Status: Bogus -Block user comment: Y +Block user comment: N
 [2010-10-18 20:29 UTC]
The message is correct. As some fonts are supported by some freetype versions. It does not mean that the font file is invalid, but that ft (gd) could not read it.
 [2010-10-18 22:20 UTC]
No, the message is ambiguous. Consider this...

If GD is able to read the file, it is readable.

If GD is unable to read the file, it is unreadable.

We know the file is readable, that is not the problem.

If GD is able to validate the file, it is valid.

If GD is unable to validate the file, it is invalid.

We do not know whether the file is valid or not.


If GD is able to support the file, it is supported.

If GD is unable to support the file, it is unsupported.

We do not know whether the file is supported or not.

To use "read" is too ambiguous in this context.
 [2010-10-18 22:25 UTC]
-Status: Bogus +Status: Open
 [2010-10-19 18:29 UTC]
-Status: Open +Status: Bogus
 [2010-10-19 18:29 UTC]
The error if the file does not exist or cannot be open is "could not find/read font".

The error when GD cannot (actually Freetype failed) read the font file is "could not read font", which is perfectly correct. There is no bug here and I won't change this error (will have to change in external GD as well, duplicate tests, etc. for no gain).
 [2010-10-19 20:40 UTC]
-Status: Bogus +Status: Open
 [2010-10-19 20:40 UTC]
To confirm,

"could not find/read font" means the file is not readable.

"Could not read font" means what?

And you don't believe these errors are ambiguous?

There is clearly an issue with the error being too ambiguous. The gain would be to improve the end user experience.

Or are we to assume that improvements are no longer worth reporting?
 [2010-10-19 20:50 UTC]
-Status: Open +Status: Bogus
 [2010-10-19 20:50 UTC]
Let me rephrase a last time, I won't change this error at this stage. So keep this report as bogus as there is no bug here. The meaning of open and read are clear.

I did not say that reporting issues is not valuable. I love bugs reports. However you also have to consider polite negative replies, with arguments.

The gain (trying to replace the words open and read so users can understand the difference between these two actions) is not enough in regard to the hassle that it will introduce from a test point of view.
 [2010-10-19 21:25 UTC]
The issue is not between open and read.

imagettfbbox() says the file cannot be read.
is_readable() says the file can be read.

This is the issue. "Open" is never mentioned in the error.

The wording is poor, you are trying to dismiss it as bogus because you deem it unimportant.

You seem to agree that the wording is ambiguous and can be improved, yet you are choosing to ignore it. That is just rude, not polite.

Is it too much to ask to improve the wording in the name of clarity?
 [2011-12-22 18:24 UTC] rpalkowski at cyberitas dot com
For what it's worth, I just encountered this exact problem and was also
thrown by the ambiguity of the warning message, and was barking up the 
wrong tree for a while before I stumbled upon testing the validity of 
the font file itself.  There is clearly an actual semantic difference 
between being able to open, and being able to parse or validate a file.
If you don't want to change "Could not read font", then the ambiguity 
could be resolved by changing the other warning message to "Could not 
open font".
 [2011-12-22 23:09 UTC]
-Status: Bogus +Status: Open
 [2015-06-28 19:46 UTC]
-Status: Open +Status: Suspended
 [2015-06-28 19:46 UTC]
> imagettfbbox() says the file cannot be read.

Well, it says the *font* cannot be read. It doesn't say anything
about the *file*.

Anyhow, this issue is not directly a PHP issue, but rather a libgd
issue[1], so it would have to reported and fixed upstream. Until
then I'm changing the status to suspended.

[1] <>
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 23 00:01:31 2024 UTC