|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-05-12 12:39 UTC] 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 ! PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 13:00:01 2025 UTC |
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">