功能错误imagettfbbox() [英] Error in function imagettfbbox()

查看:129
本文介绍了功能错误imagettfbbox()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的网站上放置验证码图像以阻止人们发送垃圾邮件,当我查看图像时我自己得到了这个:

致命错误:调用未定义的函数imagettfbbox ()第39行的(...)/ htdocs / CaptchaSecurityImages.php


所以继承我的代码:


[php]

<?php

session_start();


class CaptchaSecurityImages {


var $ font =''monofont.ttf'';


函数generateCode($ characters){

/ * list所有可能的角色,类似的角色和元音都被删除了* /

$ possible ='''23456789bcdfghjkmnpqrstvwxyz'';

$ code ='''';

$ i = 0;

while($ i< $ characters){

$ code。= substr($ possible,mt_rand(0,strlen) ($ possible)-1),1);

$ i ++;

}

返回$ code;

}


功能CaptchaSecurityIm年龄($ width ='''120'',$ height =''40'',$ c haracters ='''6''){

$ code = $ this-> generateCode($字符);

/ *字体大小为图像高度的75%* /

$ font_size = $ height * 0.75;

$ image = @imagecreate($ width,$ height)或die(''无法初始化新的GD图像流'');

/ *设置颜色* /

$ background_color = imagecolorallocate($ image,255,255,255);

$ text_color = imagecolorallocate($ image,20,40,100);

$ noise_color = imagecolorallocate( $ image,100,120,180);

/ *在背景中生成随机点* /

for($ i = 0; $ I≤($宽度* $高度)/ 3; $ i ++){

imagefilledellipse($ image,mt_rand(0,$ width),mt_rand(0,$ height),1,1,$ noise_color);

}

/ *在后台生成随机行* /

for($ i = 0; $ i<($ width * $ height)/ 150; $ i ++){

imageline($ image,mt_rand(0,$ width),mt_rand(0,$ height),mt_rand(0,$ width),mt_rand(0,$ height),$ noise_color);

}

/ *创建文本框并添加文本* /

$ textbox = imagettfbbox($ font_size,0,$ this-> font,$代码)或死(''错误的imagettfbbox函数'');

$ x =($ width - $ textbox [4])/ 2;

$ y = ($ height - $ textbox [5])/ 2;

imagettftext($ image,$ font_size,0,$ x,$ y,$ text_color,$ this-> font,$ code)或死(''imagettftext函数中的错误');

/ *输出验证码图像到浏览器* /

header(''Content-Type:image / jpeg' ');

imagejpeg($ image);

imagedestroy($ image);

$ _SESSION [''secu rity_code''] = $ code;

}


}


$ width = isset($ _ GET [ ''宽度''])? $ _GET [''width'']:''120'';

$ height = isset($ _ GET [''height''])? $ _GET [''height'']:''40'';

$ characters = isset($ _ GET [''characters''])&& $ _GET [''characters'']> 1? $ _GET [''characters'']:''6'';


$ captcha = new CaptchaSecurityImages($ width,$ height,$ characters);


?>

[/ php]


i希望你们能帮忙,我迷路了!

解决方案

font =''monofont.ttf'';


函数generateCode(


characters){

/ *列出所有可能的字符,类似的字符和元音已被删除* /


possible =''23456789bcdfghjkmnpqrstvwxyz'';

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/CaptchaSecurityImages.php on line 39

so heres my code:

[php]
<?php
session_start();


class CaptchaSecurityImages {

var $font = ''monofont.ttf'';

function generateCode($characters) {
/* list all possible characters, similar looking characters and vowels have been removed */
$possible = ''23456789bcdfghjkmnpqrstvwxyz'';
$code = '''';
$i = 0;
while ($i < $characters) {
$code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
$i++;
}
return $code;
}

function CaptchaSecurityImages($width=''120'',$height=''40'',$c haracters=''6'') {
$code = $this->generateCode($characters);
/* font size will be 75% of the image height */
$font_size = $height * 0.75;
$image = @imagecreate($width, $height) or die(''Cannot initialize new GD image stream'');
/* set the colours */
$background_color = imagecolorallocate($image, 255, 255, 255);
$text_color = imagecolorallocate($image, 20, 40, 100);
$noise_color = imagecolorallocate($image, 100, 120, 180);
/* generate random dots in background */
for( $i=0; $i<($width*$height)/3; $i++ ) {
imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color);
}
/* generate random lines in background */
for( $i=0; $i<($width*$height)/150; $i++ ) {
imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
}
/* create textbox and add text */
$textbox = imagettfbbox($font_size, 0, $this->font, $code) or die(''Error in imagettfbbox function'');
$x = ($width - $textbox[4])/2;
$y = ($height - $textbox[5])/2;
imagettftext($image, $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($image);
imagedestroy($image);
$_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 CaptchaSecurityImages($width,$height,$characters);

?>
[/php]

i hope you guys can help, im lost!

解决方案

font = ''monofont.ttf'';

function generateCode(


characters) {
/* list all possible characters, similar looking characters and vowels have been removed */


possible = ''23456789bcdfghjkmnpqrstvwxyz'';


这篇关于功能错误imagettfbbox()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆