|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24450 TTF and FreeType functions lock font file
Submitted: 2003-07-01 17:45 UTC Modified: 2003-07-14 18:24 UTC
Avg. Score:4.5 ± 0.8
Reproduced:17 of 17 (100.0%)
Same Version:4 (23.5%)
Same OS:13 (76.5%)
From: choinet at rocketmail dot com Assigned:
Status: Wont fix Package: GD related
PHP Version: 4.3.3RC1 OS: Windows XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: choinet at rocketmail dot com
New email:
PHP Version: OS:


 [2003-07-01 17:45 UTC] choinet at rocketmail dot com
My computer setup is Apache 2.0.46,PHP 4.3.2, and Windows XP SP1. Only modifications to php.ini are: 'extension=php_gd2.dll' and 'log_errors' are enabled. Originally, I was trying to use the imagettftext() function to write text to a png file. I used the function in a similar context as described by the manual, and the text write was successful. However, I stumbled upon the discovery that the font file that the function uses was locked by either the webserver or PHP process, as I was not able to unlink or remove the font file.

I tried to isolate the problem by testing the code on Windows XP with Apache 1.3.27, Apache 2.0.46, and IIS 5.1 and either PHP 4.2.3, 4.3.2, 4.3.3RC1, or 5.0, so I am thinking that it has something to do with the operating system. Furthermore, this problem does not occur with a webserver running Apache/PHP 4.3.2 on Linux. Also, this problem applies to various true-type font files.

The problem only goes away after I stop or restart the webserver.

In summary, there are four functions that use a font file that lock it: imagettftext(), imagettfbbox(), imagefttext(), and imageftbbox().

Reproduce code:
$im = imagecreatefrompng('test.png');
$blue = imagecolorallocate($im, 0, 102, 255);
$font = 'tahoma.ttf';
// These four functions lock the font file and do not release it
imagettftext($im, 10, 0, 10, 25, $blue, $font, 'text');
imagettfbbox (20, 0, $font, 'text');
imagefttext ($im, 12, 0, 10, 20, 5, $font, 'text', $foo);
imageftbbox (12, 0, $font, 'text', $foo);

header('Content-Type: image/png');


Expected result:
I expect to see the png image generated and the font file unlinked.

Actual result:
The image displays fine but the font file cannot be deleted.

(Windows Error Dialog Box after manually attempting to delete arial.ttf)

Cannot delete arial: It is being used by another person or program. Close any programs that might be using the file and try again.

(Apache Error Log)

[client] PHP Warning:  unlink(arial.ttf): Permission denied in C:\Apache2\htdocs\gd\dynamic.php on line 16


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-07-01 18:37 UTC]
Just curious..but why do you want to delete the file? :)

 [2003-07-03 18:44 UTC] choinet at rocketmail dot com
I don't necessarily want to delete the file, but I want to be able to hypothetically delete the parent directory above it :) I'm developing an image management system that also allows for random image generation with text, and perhaps I would need to remove a parent directory or the file itself.
 [2003-07-14 18:24 UTC]

We cannot fix it. Freetype keeps the file handle open and windows interprets that as a lock. Test your script on a unix system and it should work like a charm.

thanks for your report,

 [2011-03-05 16:16 UTC] stano110 at azet dot sk
thanks for explanation. I have the same problem, cannot remove plugin directory with the font locked. It's a pity, that this problem still persists also on Win7+PHP5.3.3.
 [2013-02-08 07:27 UTC] dimagsv at f-m dot fm
I have the same problem.
It still persists also on Winxp + PHP5.4.4
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Tue Dec 01 06:01:23 2020 UTC