ubuntu 的PHP伺服器,驗證碼圖片不顯示字元,咋回事

來源:互聯網
上載者:User
ubuntu 的PHP伺服器,驗證碼圖片不顯示字元,怎麼回事
ubuntu 的PHP伺服器,驗證碼圖片不顯示字元,怎麼回事?
有圖片產生,就是沒有字元顯示.是字元集錯誤了嗎?哪裡設定?

分享到:


------解決方案--------------------
引用:
Quote: 引用:

代碼貼出來看一下

function getAuthImage($text) {
$im_x = 160;
$im_y = 40;
$im = imagecreatetruecolor($im_x,$im_y);
$text_c = ImageColorAllocate($im, mt_rand(0,100),mt_rand(0,100),mt_rand(0,100));
$tmpC0=mt_rand(100,255);
$tmpC1=mt_rand(100,255);
$tmpC2=mt_rand(100,255);
$buttum_c = ImageColorAllocate($im,$tmpC0,$tmpC1,$tmpC2);
imagefill($im, 16, 13, $buttum_c);

$font = 't1.ttf';

for ($i=0;$i{
$tmp =substr($text,$i,1);
$array = array(-1,1);
$p = array_rand($array);
$an = $array[$p]*mt_rand(1,10);//角度
$size = 28;
imagettftext($im, $size, $an, 15+$i*$size, 35, $text_c, $font, $tmp);
}


$distortion_im = imagecreatetruecolor ($im_x, $im_y);

imagefill($distortion_im, 16, 13, $buttum_c);
for ( $i=0; $i<$im_x; $i++) {
for ( $j=0; $j<$im_y; $j++) {
$rgb = imagecolorat($im, $i , $j);
if( (int)($i+20+sin($j/$im_y*2*M_PI)*10) <= imagesx($distortion_im)&& (int)($i+20+sin($j/$im_y*2*M_PI)*10) >=0 ) {
imagesetpixel ($distortion_im, (int)($i+10+sin($j/$im_y*2*M_PI-M_PI*0.1)*4) , $j , $rgb);
}
}
}
//加入幹擾象素;
$count = 160;//幹擾像素的數量
for($i=0; $i<$count; $i++){
$randcolor = ImageColorallocate($distortion_im,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
imagesetpixel($distortion_im, mt_rand()%$im_x , mt_rand()%$im_y , $randcolor);
}

$rand = mt_rand(5,30);
$rand1 = mt_rand(15,25);
$rand2 = mt_rand(5,10);
for ($yy=$rand; $yy<=+$rand+2; $yy++){
for ($px=-80;$px<=80;$px=$px+0.1)
{
$x=$px/$rand1;
if ($x!=0)
{
$y=sin($x);
}
$py=$y*$rand2;

imagesetpixel($distortion_im, $px+80, $py+$yy, $text_c);
}
}

//設定檔案頭;
Header("Content-type: image/JPEG");

//以PNG格式將映像輸出到瀏覽器或檔案;
ImagePNG($distortion_im);

//銷毀一映像,釋放與image關聯的記憶體;
ImageDestroy($distortion_im);
ImageDestroy($im);
}

function make_rand($length="32"){//驗證碼文字產生函數
$str="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$result="";
for($i=0;$i<$length;$i++){
$num[$i]=rand(0,25);
$result.=$str[$num[$i]];
}
return $result;
}


//輸出調用
$checkcode = make_rand(4);
session_start();//將隨機數存入session中
$_SESSION['helloweba_gg']=strtolower($checkcode);
getAuthImage($checkcode);
?>





windows的伺服器可以. 就是ubuntu 不行


檢查你的字型檔路徑.
------解決方案--------------------
你把 62 行的 Header("Content-type: image/JPEG"); 注釋掉就能看到錯誤資訊了
ttf 是 windows 的字型檔,你需要安裝支援庫
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.