100 Web Space
https://forum.100webspace.com/

Imagettftext can't find my font. Why not?
https://forum.100webspace.com/viewtopic.php?f=5&t=9780
Page 1 of 1

Author:  Takumi [ Wed May 14, 2008 1:48 am ]
Post subject:  Imagettftext can't find my font. Why not?

My script functions fine if I use Arial as the font, but when I try to use a font that's not in the current directory (setting the GD path with putenv) it tells me it can't find the font.

If it helps, this is my script:

Code:
<?php

header("Content-type: image/png");

$im = imagecreatetruecolor(400, 30);

$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);

$homedir = "http://www.mtaonline.net/~dburton/";
putenv("GDFONTPATH=$homedir");

//These entities should output the hanzi numerals for one, two, and three
$text = '&#x4e00;&#x4e8c;&#x4e09;';
$font = 'HDZB_35.TTF';

imagettftext($im, 12, 0, 10, 20, $black, $font, $text);

imagepng($im);
imagedestroy($im);

?>


I only called the font from an outside URL due to the fact that it's more than 500KB (most fonts are). Yes, I have opened the full URL to the font in my browser, and it works.

This works (albeit the fact it outputs the entities instead of the corresponding characters):

Code:
<?php

header("Content-type: image/png");

$im = imagecreatetruecolor(400, 30);

$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);

$text = "&#x4e00;&#x4e8c;&#x4e09;";
$font = "Arial";

imagettftext($im, 12, 0, 10, 20, $black, $font, $text);

imagepng($im);
imagedestroy($im);

?>


How should I direct GD to my font?

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/