public function getCaptcha(){
//设置填充颜色
$white=imagecolorallocate($this->_image,255,255,255);
//绘制填充矩形
imagefilledrectangle($this->_image, 0, 0, $this->_width,$this->_height,$white);
//获取字符
$str=$this->_getStr();
if($str === false){
return false;
}
//绘制验证码
$fontfile=$this->_fontfile;
for($i=0;$i<$this->_length;$i++){
$size=$this->_size;
$fonheight=imagefontheight($size);
$angle=mt_rand(-15,15);
$x=20+ceil($this->_width/$this->_length)*$i;
$y=mt_rand($this->_height/2,$this->_height-$fonheight);
$color=$this->_getRoundColor();
//$text=mb_substr($str,$i,1,'utf-8');//从字符集从随机获取一个字符
$text=$str{$i};
imagettftext($this->_image, $size, $angle, $x, $y, $color, $fontfile, $text);
}
//绘制干扰元素 分为雪花模式和像素点线段模式
if($this->_snow){
$this->_getSnow();
}else{
if($this->_pixel){
$this->_getPixel();
}
if($this->_line){
$this->_getLine();
}
}
//输出图像
/*向浏览器输出图像*/
header('content-type:image/png');
imagepng($this->_image);
imagedestory($this->_image);
return strtolower($str);
}