Im trying to put a captcha image in my site to stop people from spamming, and when i view the image its self i get this:
Fatal error: Call to undefined function imagettfbbox() in (...)/htdocs/CaptchaSecurity Images.php on line 39
so heres my code:
[php]
<?php
session_start() ;
class CaptchaSecurity Images {
var $font = 'monofont.ttf';
function generateCode($c haracters) {
/* list all possible characters, similar looking characters and vowels have been removed */
$possible = '23456789bcdfgh jkmnpqrstvwxyz' ;
$code = '';
$i = 0;
while ($i < $characters) {
$code .= substr($possibl e, mt_rand(0, strlen($possibl e)-1), 1);
$i++;
}
return $code;
}
function CaptchaSecurity Images($width=' 120',$height='4 0',$characters= '6') {
$code = $this->generateCode($ characters);
/* font size will be 75% of the image height */
$font_size = $height * 0.75;
$image = @imagecreate($w idth, $height) or die('Cannot initialize new GD image stream');
/* set the colours */
$background_col or = imagecoloralloc ate($image, 255, 255, 255);
$text_color = imagecoloralloc ate($image, 20, 40, 100);
$noise_color = imagecoloralloc ate($image, 100, 120, 180);
/* generate random dots in background */
for( $i=0; $i<($width*$hei ght)/3; $i++ ) {
imagefilledelli pse($image, mt_rand(0,$widt h), mt_rand(0,$heig ht), 1, 1, $noise_color);
}
/* generate random lines in background */
for( $i=0; $i<($width*$hei ght)/150; $i++ ) {
imageline($imag e, mt_rand(0,$widt h), mt_rand(0,$heig ht), mt_rand(0,$widt h), mt_rand(0,$heig ht), $noise_color);
}
/* create textbox and add text */
$textbox = imagettfbbox($f ont_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
$x = ($width - $textbox[4])/2;
$y = ($height - $textbox[5])/2;
imagettftext($i mage, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('Error in imagettftext function');
/* output captcha image to browser */
header('Content-Type: image/jpeg');
imagejpeg($imag e);
imagedestroy($i mage);
$_SESSION['security_code'] = $code;
}
}
$width = isset($_GET['width']) ? $_GET['width'] : '120';
$height = isset($_GET['height']) ? $_GET['height'] : '40';
$characters = isset($_GET['characters']) && $_GET['characters'] > 1 ? $_GET['characters'] : '6';
$captcha = new CaptchaSecurity Images($width,$ height,$charact ers);
?>
[/php]
i hope you guys can help, im lost!
Fatal error: Call to undefined function imagettfbbox() in (...)/htdocs/CaptchaSecurity Images.php on line 39
so heres my code:
[php]
<?php
session_start() ;
class CaptchaSecurity Images {
var $font = 'monofont.ttf';
function generateCode($c haracters) {
/* list all possible characters, similar looking characters and vowels have been removed */
$possible = '23456789bcdfgh jkmnpqrstvwxyz' ;
$code = '';
$i = 0;
while ($i < $characters) {
$code .= substr($possibl e, mt_rand(0, strlen($possibl e)-1), 1);
$i++;
}
return $code;
}
function CaptchaSecurity Images($width=' 120',$height='4 0',$characters= '6') {
$code = $this->generateCode($ characters);
/* font size will be 75% of the image height */
$font_size = $height * 0.75;
$image = @imagecreate($w idth, $height) or die('Cannot initialize new GD image stream');
/* set the colours */
$background_col or = imagecoloralloc ate($image, 255, 255, 255);
$text_color = imagecoloralloc ate($image, 20, 40, 100);
$noise_color = imagecoloralloc ate($image, 100, 120, 180);
/* generate random dots in background */
for( $i=0; $i<($width*$hei ght)/3; $i++ ) {
imagefilledelli pse($image, mt_rand(0,$widt h), mt_rand(0,$heig ht), 1, 1, $noise_color);
}
/* generate random lines in background */
for( $i=0; $i<($width*$hei ght)/150; $i++ ) {
imageline($imag e, mt_rand(0,$widt h), mt_rand(0,$heig ht), mt_rand(0,$widt h), mt_rand(0,$heig ht), $noise_color);
}
/* create textbox and add text */
$textbox = imagettfbbox($f ont_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
$x = ($width - $textbox[4])/2;
$y = ($height - $textbox[5])/2;
imagettftext($i mage, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('Error in imagettftext function');
/* output captcha image to browser */
header('Content-Type: image/jpeg');
imagejpeg($imag e);
imagedestroy($i mage);
$_SESSION['security_code'] = $code;
}
}
$width = isset($_GET['width']) ? $_GET['width'] : '120';
$height = isset($_GET['height']) ? $_GET['height'] : '40';
$characters = isset($_GET['characters']) && $_GET['characters'] > 1 ? $_GET['characters'] : '6';
$captcha = new CaptchaSecurity Images($width,$ height,$charact ers);
?>
[/php]
i hope you guys can help, im lost!
Comment