為什么我的總是提醒打不開字體文件??好著急啊
session_start();
$image=imagecreatetruecolor(200, 60);
$color=imagecolorallocate($image, 255, 255, 255);
imagefill($image, 0, 0, $color);
$fonttype='STKAITI.TTF';
$array_font="的是了我不人在他有這個(gè)上們來(lái)到時(shí)大地為子中你說(shuō)生國(guó)年
? ? 著就那和要她出也得里后自以會(huì)家可下而過(guò)天去能對(duì)小多然于心學(xué)么之都好看
? ? 起發(fā)當(dāng)沒(méi)成只如事把還用第樣道想作種美總從無(wú)情己面最女但現(xiàn)前些所同日手又
? ? 行意動(dòng)方期它頭經(jīng)長(zhǎng)兒回位分愛(ài)老因很給名法間斯知世什兩次使身者被高已親其進(jìn)此話常與活正感"
;
? ? $v=str_split($array_font,3);
? ? $captch_code='';
? ? for ($i=0;$i<4;$i++){
? ? ? ? $fontsize=6;
? ? ? ?$fontcolor= imagecolorallocate($image, rand(40,160), rand(40,160), rand(40,160));
? ? ? $index = rand(0,count($v));
? ? ? $cn=$v[$index];
? ? ? $captch_code.=$cn;
? ? ? imagettftext($image, mt_rand(20,24),mt_rand(-60,60),(40*$i+20),mt_rand(30,35), $fontcolor, $fonttype, $cn);
? ? }
? ? $_SERVER['codee']=$captch_code;
? ? for($i=0;$i<200;$i++){
? ? ? ? //設(shè)定顏色
? ? ? ? $color = imagecolorallocate($image, rand(50,180), rand(50,180), rand(50,280));
? ? ? ? //坐標(biāo)
? ? ? ? $x=rand(0,200);
? ? ? ? $y= rand(0,60);
? ? ? ? //系統(tǒng)函數(shù)imagesetpixel設(shè)定像素點(diǎn)
? ? ? ? imagesetpixel($image, $x, $y, $color);
? ? }
? ? for ($i=0;$i<3;$i++){
? ? ? ? $linecolor=imagecolorallocate($image, rand(80,220), rand(80,220), rand(80,220));
? ? ? ? //坐標(biāo)
? ? ? ? $x1 = rand(1,99);
? ? ? ? $y1 = rand(1,59);
? ? ? ? $x2 = rand(5,200);
? ? ? ? $y2 = rand(1,59);
? ? ? ? //系統(tǒng)函數(shù)imageline設(shè)置劃線
? ? ? ? //也可以直接在函數(shù)imageline內(nèi)設(shè)定坐標(biāo):
? ? ? ? //imageline($image,rand(8,99),rand(1,28),rand(5,99),rand(1,28)$linecolor);
? ? ? ? imageline($image, $x1, $y1, $x2, $y2, $linecolor);
? ? }
? ? header('content-type:image/png');
? ?imagepng($image);
imagedestroy($image);
2019-03-14
已經(jīng)找到解決辦法了:把字體文件的路徑賦值就好了,而不是字體文件的名稱
正確:$fonttype="D:\wamp64\www\project01\STKAITI.TTF"
失敗:$fonttype='STKAITI.TTF';
錯(cuò)誤代碼在上文第六行