GD2 and TTF
Posted 16 August 2006 - 01:32 PM
Anyway, I just setup a new server and now this script it does not work properly. It creates the image and the line in the image, but the text does not appear on the image. I verified that the times.ttf file is the the proper place. Also, this new server is running the same version of PHP as my other server where this script works (even using an identical copy of the php.ini file).
I just cant seem to figure out why this would work on one server and not the other. It has to be something system related but I just can't figure it out. Any help with this would be appreciated.
$TheImage = Imagecreate("75", "25");
$ColorImage = imagecolorallocate($TheImage, 180, 50, 23);
$ColorText = imagecolorallocate($TheImage, 0, 0, 0);
$ColorLine = imagecolorallocate($TheImage, 75, 75, 75);
$secret = substr(md5(uniqid(rand())), 0, 5);
$secret = strtoupper($secret);
$Dingy = $secret;
imageline($TheImage, 75, 8, 0, 15, $ColorLine);
ImageTTFText($TheImage, 12, -5, 16, 20, $ColorText, "times.ttf", $secret);
Posted 16 August 2006 - 02:39 PM
Depending on which version of the GD library PHP is using, when fontfile does not begin with a leading / then .ttf will be appended to the filename and the library will attempt to search for that filename along a library-defined font path.
maybe try dropping the .ttf in your ImageTTFText function?
ImageTTFText($TheImage, 12, -5, 16, 20, $ColorText, "times", $secret);
Posted 16 August 2006 - 02:41 PM
I tried it without the '.ttf' and it still doesnt work. It is like the ImageTTFText function is broken.
Posted 16 August 2006 - 02:46 PM
Looking at the PHP errors...the problem is that it cannot see the font. The font IS in the correct place though. I am running this on Windows 2003 Server. Any idea why PHP can't see the font? It's in the same directory as the file.
Warning: Could not find/open font in C:\!Webs\mysite\codekeyimage.php on line 31
Posted 21 August 2006 - 06:28 PM
This is one of those off PHP things that happen every so often that make me want to pull my hair out (what's left of it).
Posted 22 August 2006 - 08:58 AM
Sometimes this gets overlooked, so your code is looking for times.ttf and the file is called Times.ttf or Times.TTF
Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools
Posted 22 August 2006 - 01:11 PM
In this particular case, the problem cannot be with anything in the code. Everything worked fine before we reformatted and resetup our server.
I have the exact same code running on a different server along with the same php.ini file and exact copy of the DLL for GD2.
Posted 22 August 2006 - 01:13 PM
Is there any otrher way for me to get text to be displayed on my image WITHOUT having to use ImageTTFText. Can I write text in an image without using a TTF?
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users