亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

圖像**因存在錯誤無法顯示

<?php
session_start();

// 驗證碼
$img = imagecreatetruecolor(200, 80); // 生成一個彩色圖片
$bgcolor = imagecolorallocate($img, 255, 255, 255); // 白色
imagefill($img, 0, 0, $bgcolor); // 填充背景
??????????????????????????????? ?
header('content-type:text/html;charset=utf-8');
// 定義字符集路徑
$fontface = "simhei.ttf";
// 定義字符庫
$str =? "中文字庫";
// 如果字符必須保證為 UTF-8 編碼格式, 如果不是,需要將其轉換UTF-8 編碼
// iconv ( string $in_charset , string $out_charset , string $str ) 將 $in_charset 編碼的 $str 字符串按要求的 $out_charset 字符編碼來轉換 并返回
// $str = iconv("GBK", "UTF-8", $text);
// 將字符庫中的字符截取成數組
// str_split(string,length) 把字符串分割到數組中。string 要分割的字符串。length 每個數組元素的長度。默認是 1。
// 因為 utf-8 編碼的字符 是三個字節一個漢字,所以 length = 3.
$strdb = str_split($str,3);
for ($i=0; $i < 4; $i++) {
??? // 0-120 為深色區,能更好的在淺色背景中識別驗證碼
??? $fontcolor = imagecolorallocate($img, rand(0,120), rand(0,120), rand(0,120));
??? $index = rand(0,count($strdb)-1);
??? $cn = $strdb[$index];
??? $captch .=$cn;
??? // imagettftext ( 畫布資源 , 字體大小 , 傾斜角度 , X軸位置 , Y軸位置 , 字體顏色 , 字符集路徑 , 文字內容 )???? 圖像寫入文本
??? imagettftext($img, rand(14,18), mt_rand(-60,60), (40*$i+20), mt_rand(30,35), $fontcolor, $fontface, $cn);
}
// 保存驗證碼,并全部轉換在小寫
$_SESSION['authcode'] = strtolower($captch);
// 加入噪點干擾
for ($i = 0; $i < 200; $i ++) {
??? $pointcolor = imagecolorallocate($img, rand(50, 200), rand(50, 255), rand(50, 200));
??? imagesetpixel($img, rand(0, 200), rand(0, 80), $pointcolor); // 隨機點生成
}
// 加入線干擾
for ($i = 0; $i < 3; $i ++) {
??? $linecolor = imagecolorallocate($img, rand(0, 255), rand(0, 255), rand(0, 255));
??? imageline($img, rand(0, 200), rand(0, 80), rand(0, 200), rand(0, 80), $linecolor);
}
// 輸出驗證碼
header("content-type: image/png");
imagepng($img);
imagedestroy($img);

我自己的照著寫的代碼出現這種錯誤,我還以為我自己寫有問題,但是一步步檢查發現語法都沒問題,就是 imagesetpixel()這里出錯,但是又不知道問題所在,上面是網友的代碼,我復制粘貼也是一樣出錯,網上說在header("content-type: image/png");前面加ob_clean();,一樣報錯,求大師指導。環境是xampp3.2.2,

正在回答

1 回答

沒毛病,加上去就可以了,。。。。

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

圖像**因存在錯誤無法顯示

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號