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