Help - Search - Members - Calendar
Full Version: Captcha Font
Zymic Webmaster Forums > Web Design & Development > Server Side Scripting > PHP
cogs
I'm trying to create a captcha that uses a .ttf file. I'm using the imagettftext() function, and it works great on my localhost, but when I try to use it on zymic, I get the following error:

Warning: imagettftext() [function.imagettftext]: Could not find/open font in /www/99k.org/c/o/g/cogs/htdocs/kevtest/captcha.php on line 42

I've tried it with different fonts with the same result. It does work, however, with the imagestring() function, but I can't change the font size, which only goes to 5, which is way too small.
I have the tahoma.ttf file uploaded to the same directory as the .php file.
Hopefully someone can tell me what I'm doing wrong.
Here's the code:
CODE
<?php
  
     //Now lets use md5 to generate a totally random string
     $md5 = md5(microtime() * mktime());
     /*
     We dont need a 32 character long string so we trim it down to 5
     */
     $string = substr($md5,0,5);
     /*
     Now for the GD stuff, for ease of use lets create
     the image from a background image.
     */
     $captcha = @imagecreatetruecolor(125, 50)
      or die('Cannot Initialize new GD image stream');
    
    
    
     /*Lets set the colours, the colour $line is used to generate lines.
     Using a blue misty colours. The colour codes are in RGB
     */
     $black = imagecolorallocate($captcha, 0, 0, 0);
     $line = imagecolorallocate($captcha, 125, 125, 125);
     $grey = imagecolorallocate($captcha, 200, 200, 200);
     imagefill($captcha, 0, 0, $grey);

    
     /*
     Now to make it a little bit harder for any bots to break,  
     assuming they can break it so far. Lets add some lines
     in (static lines) to attempt to make the bots life a little harder
     */
     $x1 = rand(0,125);
     $x2 = rand(0,125);
     $y1 = rand(0,50);
     $y2 = rand(0,50);
     imageline($captcha,0,$x1,$x2,$y1,$line);
     imageline($captcha,0,$x2,$x1,$y2,$line);
     /*
     Now for the all important writing of the randomly generated string to the image.
     */
     //imagestring($captcha, 5, 42, 18, $string, $black);
     imagettftext($captcha, 12, 0, 42, 18, $black, "tahoma.ttf", $string);

/*
Encrypt and store the key inside of a session
*/

$_SESSION['key'] = md5($string);


     header("Content-type: image/png");
     imagepng($captcha);
?>
swordz
Use a full path to the ttf file. In this case /www/99k.org/c/o/g/cogs/htdocs/kevtest/tahoma.ttf

Swordz
cogs
QUOTE(swordz @ Oct 19 2009, 10:14 AM) *
Use a full path to the ttf file. In this case /www/99k.org/c/o/g/cogs/htdocs/kevtest/tahoma.ttf

Swordz


Yup! That fixed it.
Thanks, Swordz.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.