2015-09-20 40 views
-3

我有一個代碼,以動態創建CPATCHA像蒼蠅驗證碼圖像,其顯示圖像的破碎...這裏是代碼創建PHP的

$code = $this->generateCode($characters); 
    /* font size will be 95% of the image height */ 
    $font_size = $height * 1; 
    $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,0, 0, 0); 
    //  $text_color_2 = imagecolorallocate($image, 100, 40, 20); 
    $noise_color = imagecolorallocate($image, 50, 40, 35); 
    $line_color = imagecolorallocate($image, 150, 140, 135); 
    //  $noise_color_2 = imagecolorallocate($image, 150, 120, 100); 
    /* generate random dots in background */ 
    for($i=0; $i<($width*$height)/15; $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), $line_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); 

任何人都可以說,什麼是錯我的代碼?

+1

停了嗎?來吧,你可以做得比那 – 2015-09-20 06:37:05

+0

好......我真的不知道這裏發生了什麼事......它在飛行中創建圖像...可以權限是問題嗎? –

+1

嗯,我真的不知道**停止了**甚至在這種情況下意味着 – 2015-09-20 07:03:51

回答

0

問題在於BOM字符。我刪除它,現在它工作正常。