?public?function?getCaptcha(){
????????//設(shè)置填充顏色
??????$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;
??????}
????????//繪制驗(yàn)證碼
??????$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');//從字符集從隨機(jī)獲取一個(gè)字符
??????????$text=$str{$i};
??????????imagettftext($this->_image,?$size,?$angle,?$x,?$y,?$color,?$fontfile,?$text);
??????}
??????//繪制干擾元素?分為雪花模式和像素點(diǎn)線段模式
??????if($this->_snow){
??????????$this->_getSnow();
??????}else{
??????????if($this->_pixel){
??????????????$this->_getPixel();
??????????}
??????????if($this->_line){
??????????????$this->_getLine();
??????????}
??????}
??????//輸出圖像
??????/*向?yàn)g覽器輸出圖像*/
??????header('content-type:image/png');
??????imagepng($this->_image);
??????imagedestory($this->_image);
??????return?strtolower($str);
??}
2018-12-27
因?yàn)?code>header(
'content-type:image/png'
);已經(jīng)告訴瀏覽器輸出png圖像