From:             choinet at rocketmail dot com
Operating system: Windows XP
PHP version:      4.3.3RC1
PHP Bug Type:     GD related
Bug description:  TTF and FreeType functions lock font file

Description:
------------
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');
imagepng($im);
imagedestroy($im);

unlink($font);

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 127.0.0.1] PHP Warning:  unlink(arial.ttf): Permission denied in
C:\Apache2\htdocs\gd\dynamic.php on line 16

-- 
Edit bug report at http://bugs.php.net/?id=24450&edit=1
-- 
Try a CVS snapshot:         http://bugs.php.net/fix.php?id=24450&r=trysnapshot
Fixed in CVS:               http://bugs.php.net/fix.php?id=24450&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=24450&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=24450&r=needtrace
Try newer version:          http://bugs.php.net/fix.php?id=24450&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=24450&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=24450&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=24450&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=24450&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=24450&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=24450&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=24450&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=24450&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=24450&r=gnused

Reply via email to