3

I'm using imagettftext to draw text on an image using PHP GD

header('Content-Type: image/png');
$im = imagecreatetruecolor(400, 30);

$white = imagecolorallocate($im, 255, 255, 255);
$text = 'Test';
$font = 'data/font/arial.ttf';
imagettftext($im, 20, 0, 10, 20, $white, $font, $text);
imagepng($im);
imagedestroy($im);

It's working fine but the problem is that the font file handle is not closed after imagedestroy($im); (inspected with procexp)
And as i expected, I got a Permission denied warning when I tried to unlink the font file.

How to release the used font file? Thank you
I'm testing on windows xampp

unloco
  • 6,928
  • 2
  • 47
  • 58
  • it will happen automatically when the script finishes –  May 12 '13 at 00:21
  • No, `unlink`, meaning deletion of the file, will not automatically happen for the _font file_ used in writing on an image. And I don’t see why one would want to do that either – not for a font as common as Arial? (I would understand if it was a font file uploaded by the user just for one-time image creation …) – CBroe May 12 '13 at 00:28
  • @CBroe No, the font file is not deleted after this script finishes. The system allows users to upload and delete fonts and when a user tries to delete a font the said warning occurs – unloco May 12 '13 at 00:39
  • I think Dagon meant that the file is unlocked after script ends. You could remove the font file within a future request, in which you don't use the file – nice ass May 12 '13 at 00:40
  • i did not mean deletion of the file, but in reference to the title ' the internal php file handle –  May 12 '13 at 00:42
  • @Dagon yes I understand , but it is not happening as I inspect every time with Process Explorer, try to rename/delete the font file but it says '.. the file is open in httpd.exe' – unloco May 12 '13 at 00:44
  • so this is on windows? –  May 12 '13 at 00:47
  • @Dagon yes a windows localhost – unloco May 12 '13 at 00:49

0 Answers0