|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #17666 TTF-Fonts does not work
Submitted: 2002-06-09 08:55 UTC Modified: 2002-07-09 12:47 UTC
From: ulf at ecora dot de Assigned:
Status: Closed Package: GD related
PHP Version: 4.2.0 OS: WinXP/Suse Linux
Private report: No CVE-ID: None
 [2002-06-09 08:55 UTC] ulf at ecora dot de
TTF-Fonts don't work on WinXP with PHP 4.2.1 and GD 2.0.1 and on Suse Linux with PHP 4.2.0 and GD 2.0.1

On every use with imagettftext or imagettfbbox:
Could not find/open font in e:\try\bild.php4 on line x

$im = imagecreate(420,315);
$grey = imagecolorallocate($im, 60, 60, 60);
imagettftext($im, 80, 0, 20, 50, $grey, 'font.ttf', 'test');

font.ttf is in the same directory like the PHP-Script and an absolute path will also not work.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-09 09:12 UTC]
To fix it for you, try to run the affecting php script through the cgi from the command line and use strace to see which file it is really trying to access, e.g.

strace -e trace=open php-cgi -f script.php

Try to avoid the imagejpeg() call so you don't clutter your terminal with binary data.
 [2002-06-09 09:13 UTC]
Try it without the .ttf extension.
 [2002-06-09 10:46 UTC]
I just had same kind of problem on Linux. And the reason
was that the user my apache runs as did not have read 
access to the fonts. So you might wanna check that too.

 [2002-06-22 11:55 UTC] ulf at ecora dot de

I made a test with file_monitor on WinXP.

$im = imagecreate(420,315);
$grey = imagecolorallocate($im, 60, 60, 60);
imagettftext($im, 80, 0, 20, 50, $grey, 'font.ttf', 'test');

Path of the Testscript: E:\try\test.php4
The php.exe tried to open the fontfile (E:\try\font.ttf) on the following location: 

17:44:45   php.exe   FASTIO_QUERY_OPEN

I have not so much experience, but everywhere in the GD- or in the FreeType-code must be this fixed path:\usr\share\fonts\truetype\
 [2002-06-22 12:43 UTC]
This bug has been fixed in CVS. You can grab a snapshot of the
CVS version at In case this was a documentation 
problem, the fix will show up soon at
In case this was a website problem, the change will show
up on the site and on the mirror sites.
Thank you for the report, and for helping us make PHP better.

You have to set the GDFONTPATH environment variable before yuo call the ttftext function, e.g.


but chances may be that it doesn't work with the gd version 4.2.0 is linked against.

However this is fixed in , so closing.
 [2002-07-09 12:47 UTC] ulf at ecora dot de
I believe this bug is not fixed.
Script E:\try\test\test.php
Font E:\try\gd\font.ttf

imagettftext($im, 20, 0, 10, 5, $grey, 'font.ttf', 'beep');

Apache.exe tried to open E:\try\gd\e:\try\test\font.ttf.ttf

imagettftext($im, 20, 0, 10, 5, $grey, 'font.ttf', 'beep');

Apache.exe tried to open C:\winnt\fonts\e:\try\test\font.ttf.ttf

But my WinXP is in c:\XP. This hardcoded Path (C:\winnt\) is a bad idea.
 [2003-05-23 03:09 UTC] peter at kapege dot de
My provider has php 4.2.3 and I sorrily can't upgrade his php... ;-)
My code is this:

$bild = $_GET["bild"];
header("Content-type: image/png");
$img = imagecreatefrompng("../bin/B_Jahr.png");
$hc = imagecolorallocate($img,0,0,0);
$tsize = 11;
$xpos = 7;
$ypos = 15;

and it worked fine until my provider upgraded the version to 4.2.3. It's a huge German provider (1&1) and they are not able to upgrade quickly.

Is there any workaround for the ttf-problem instead?
Absolute path didn't work.


PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Mon Oct 02 13:01:26 2023 UTC