Jump to content

GD2 and TTF


webproclaim

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);
?>
Link to comment
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]
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.