Jump to content


Photo

GD2 and TTF


  • Please log in to reply
7 replies to this topic

#1 webproclaim

webproclaim
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 16 August 2006 - 01:32 PM

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);
?>

#2 bbaker

bbaker
  • Members
  • PipPipPip
  • Advanced Member
  • 127 posts
  • LocationNY

Posted 16 August 2006 - 02:39 PM

from the imagettftext documentation on php.net http://us2.php.net/m...magettftext.php

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


#3 webproclaim

webproclaim
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 16 August 2006 - 02:41 PM

bbaker,

I tried it without the '.ttf' and it still doesnt work. It is like the ImageTTFText function is broken.

#4 webproclaim

webproclaim
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 16 August 2006 - 02:46 PM

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

#5 webproclaim

webproclaim
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 21 August 2006 - 06:28 PM

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

#6 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 22 August 2006 - 08:58 AM

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
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#7 webproclaim

webproclaim
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 22 August 2006 - 01:11 PM

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.



#8 webproclaim

webproclaim
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 22 August 2006 - 01:13 PM

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?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users