Jump to content

Archived

This topic is now archived and is closed to further replies.

webproclaim

GD2 and TTF

Recommended Posts

I wrote this script that creates an image and then places a random string of characters on the image and runs a line thru them. (This is something I use along with forms to block bots from auto posting them if you are interested).

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.

<?php

$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);
session_start();
session_register("Dingy");
$Dingy = $secret;

imageline($TheImage, 75, 8, 0, 15, $ColorLine);
ImageTTFText($TheImage, 12, -5, 16, 20, $ColorText, "times.ttf", $secret);

header("Content-Type: image/PNG");

ImagePng ($TheImage);
imagedestroy($TheImage);
?>

Share this post


Link to post
Share on other sites
from the imagettftext documentation on php.net [url=http://us2.php.net/manual/en/function.imagettftext.php]http://us2.php.net/manual/en/function.imagettftext.php[/url]
[quote]
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.[/quote]

maybe try dropping the .ttf in your ImageTTFText function?
[code]ImageTTFText($TheImage, 12, -5, 16, 20, $ColorText, "times", $secret); [/code]

Share this post


Link to post
Share on other sites
More info...

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

Share this post


Link to post
Share on other sites
Any ideas anyone? I have yet to solve this.

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).

Share this post


Link to post
Share on other sites
Don't forget to check the case.  The link to the font file will be CaSe SeNsitiVe.

Sometimes this gets overlooked, so your code is looking for times.ttf and the file is called Times.ttf or Times.TTF

Regards
Rich

Share this post


Link to post
Share on other sites
Rich,

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.

Share this post


Link to post
Share on other sites
How about this...

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?

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.