Bug #64822 [Com]: imagettftext not closing font file handle
| From: | rjbaytos at rjbaytos dot ddns dot net | Date: | Sun, 17 May 2015 16:43:34 +0000 |
| Subject: | Bug #64822 [Com]: imagettftext not closing font file handle | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-192712@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=64822&edit=1
ID: 64822
Comment by: rjbaytos at rjbaytos dot ddns dot net
Reported by: amxmodx dot unloco at gmail dot com
Summary: imagettftext not closing font file handle
Status: Open
Type: Bug
Package: GD related
Operating System: win8 32bit
PHP Version: 5.4.4
Block user comment: N
Private report: N
New Comment:
I was able to reproduce this bug. It's a hassle when trying to replace or move the ttf files
around. The only solution so far is to restart the server.
<?php
if (isset($_GET['METHOD']) && $_GET['METHOD']=='captcha')
{ session_start();
$code=rand(1000,9999);
$_SESSION["code"] = $code;
session_write_close();
$font = rand(1,4).".ttf";
if ($font == "1.ttf")
$font_size = 20;
else if ($font == "2.ttf")
$font_size = 25;
else if ($font == "3.ttf")
$font_size = 30;
else if ($font == "4.ttf")
$font_size = 35;
$angle = 0;
$width = 120;
$height = 60;
$bounding_box = imagettfbbox($font_size, $angle, $font, $code);
$textwidth = abs($bounding_box[4] - $bounding_box[0]);
$textheight = abs($bounding_box[5] - $bounding_box[1]);
$x = ($width - $textwidth) / 2;
$y = (($height*3/4) + $textheight) / 2;
$image = imagecreatetruecolor($width, $height);
$text_background = imagecolorallocate($image, 0, 0, 0);
$color = imagecolorallocate($image, 230, 230, 230);
imagefill($image, 0, 0, $text_background);
imageline($image, 0, $y-rand(0,10), $width, $y-rand(0,10), $color);
imageline($image, 0, $y, $width, $y, $color);
imageline($image, 0, $y+rand(0,10), $width, $y-rand(0,20), $color);
imageline($image, $x+rand(0,$width/2), 0, $x+rand($width/2,$width), $height, $color);
imageline($image, $x+rand(0,$width/2), $height, $x+rand($width/2,$width), 0, $color);
for($i=0;$i<400;$i++)
{ imagesetpixel($image,rand()%$width,rand()%$height,$color);
}
imagettftext($image, $font_size, $angle, $x, $y, $color, $font, $code);
header("Cache-Control: no-cache, must-revalidate");
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
exit();
}
?>
<img src = "<?php echo $_SERVER['PHP_SELF']; ?>?METHOD=captcha">
Previous Comments:
------------------------------------------------------------------------
[2013-05-12 12:46:47] amxmodx dot unloco at gmail dot com
PHP v5.4.4
------------------------------------------------------------------------
[2013-05-12 12:39:05] amxmodx dot unloco at gmail dot com
Description:
------------
after using imagettftext the font file handle is not closed which makes it
impossible to rename/delete the font file without restarting Apache
$font = '../data/font/arruski.ttf';
$a = imagettftext($im, 20, 0, 10, 20, $white, $font, $text);
Using "Process Explorer" I was able to see that several font files are still open.
screenshot:http://i44.tinypic.com/2iubwu8.png
Test script:
---------------
header('Content-Type: image/png');
$im = imagecreatetruecolor(400, 30);
$white = imagecolorallocate($im, 255, 255, 255);
$text = 'Test';
$font = '../data/font/arruski.ttf';
$a = imagettftext($im, 20, 0, 10, 20, $white, $font, $text);
$fp = fopen($font,'r');
fclose($fp);
imagepng($im);
imagedestroy($im);
Expected result:
----------------
the font file would be released after script execution
Actual result:
--------------
the font file is not released.
"The action can't be completed because the file is open in httpd.exe"
Users cannot replace/rename/delete font file !
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=64822&edit=1