為什么我的總是提醒打不開字體文件??好著急啊
session_start();
$image=imagecreatetruecolor(200, 60);
$color=imagecolorallocate($image, 255, 255, 255);
imagefill($image, 0, 0, $color);
$fonttype='STKAITI.TTF';
$array_font="的是了我不人在他有這個上們來到時大地為子中你說生國年
? ? 著就那和要她出也得里后自以會家可下而過天去能對小多然于心學么之都好看
? ? 起發當沒成只如事把還用第樣道想作種美總從無情己面最女但現前些所同日手又
? ? 行意動方期它頭經長兒回位分愛老因很給名法間斯知世什兩次使身者被高已親其進此話常與活正感"
;
? ? $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++){
? ? ? ? //設定顏色
? ? ? ? $color = imagecolorallocate($image, rand(50,180), rand(50,180), rand(50,280));
? ? ? ? //坐標
? ? ? ? $x=rand(0,200);
? ? ? ? $y= rand(0,60);
? ? ? ? //系統函數imagesetpixel設定像素點
? ? ? ? imagesetpixel($image, $x, $y, $color);
? ? }
? ? for ($i=0;$i<3;$i++){
? ? ? ? $linecolor=imagecolorallocate($image, rand(80,220), rand(80,220), rand(80,220));
? ? ? ? //坐標
? ? ? ? $x1 = rand(1,99);
? ? ? ? $y1 = rand(1,59);
? ? ? ? $x2 = rand(5,200);
? ? ? ? $y2 = rand(1,59);
? ? ? ? //系統函數imageline設置劃線
? ? ? ? //也可以直接在函數imageline內設定坐標:
? ? ? ? //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
已經找到解決辦法了:把字體文件的路徑賦值就好了,而不是字體文件的名稱
正確:$fonttype="D:\wamp64\www\project01\STKAITI.TTF"
失敗:$fonttype='STKAITI.TTF';
錯誤代碼在上文第六行