脚本宝典收集整理的这篇文章主要介绍了php使用imagettftext()函数有干扰线但是没有文字的问题解决,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
public function code() { //主要参数 if($font_size == 0) $font_size = 20; if($img_width == 0) $img_width = 110; if($img_height == 0) $img_height = 50; if($word_tyPE == 0) $word_type = 3; // 1:数字 2:英文 3:混合 $font_file = ‘E:\PHPStudy\PHPTutorial\WWW\thinkPHP_3.2.3_full\Application\Home\Controller\SIDESHOW.TTF‘;//字体的路径 //创建图片,并设置背景色 $im = @imagecreate($img_width,$img_height); imagecolorallocate($im,192,192); //获取随机字符 if($word_type == 1) { $verifyCode = implode(‘‘,range(2,9)); }elseif ($word_type == 2) { $verifyCode = implode(‘‘,range(‘A‘,‘Z‘)); }else{ $verifyCode = implode(‘‘,array_merge(range(2,9),‘Z‘))); $verifyCode = str_replace(array(‘I‘,‘O‘),array(‘P‘,‘N‘),$verifyCode); } //打乱字符串 $verifyCode = str_shuffle($verifyCode); $rndstring = substr($verifyCode,4); //echo $rndstring;exIT; $rndcodelen = strlen($rndstring); //干扰线 for($i = 0; $i < 5; $i++) { $color = imagecolorallocate($im,0); imageline($im,rand(0,$img_width),$img_height),$color); } //画边框 //$bordercolor = imagecolorallocate($im,0); //imagerectangle($im,$img_width-1,$img_height-1,$bordercolor); //输出文字 for($i = 0;$i < $rndcodelen;$i++){ $rndstring[$i] = strtoupper($rndstring[$i]); $c_fontColor = imagecolorallocate($im,0); $y_pos = $i == 0 ? 10 : $i * ($font_size + 8); $c = mt_rand(0,15); imagettftext($im,$font_size,$c,$y_pos,35,$c_fontColor,$font_file,$rndstring[$i]); } header("PRagma:no-cache\r\n"); header("Cache-Control:no-cache\r\n"); header("Expires:0\r\n"); if(function_exists("imagejpeg")){ header("content-type:image/jpeg\r\n"); imagejpeg($im); }else{ header("content-type:image/png\r\n"); imagepng($im); } imagedestroy($im); exit(); }@H_86_304@
以上是脚本宝典为你收集整理的php使用imagettftext()函数有干扰线但是没有文字的问题解决全部内容,希望文章能够帮你解决php使用imagettftext()函数有干扰线但是没有文字的问题解决所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。