哪位大佬能解答我一下。。chars返回時數(shù)據(jù)是沒問題的但是無法再畫布上顯示。。
這個?是按老師課程編的image.func
<?php require_once?'../lib/string.func.php'; $width=160; $height=50; $image=imagecreatetruecolor($width,?$height); $white=imagecolorallocate($image,?255,?255,?255); $black=imagecolorallocate($image,?0,?0,?0); imagefilledrectangle($image,?1,?1,?$width-2,?$height-2,?$white); $chars=buildRandomString(5); echo?$chars;$sess_name="verify"; $_SESSION[$sess_name]=$chars; $fontfiles=array("ahronbd.ttf",?"andlso.ttf","FZLTCXHJW.TTF","hakuyoxingshu7000.TTF"); for($i=0;$i<5;$i++){???? $size=mt_rand(14,?18);? ???$angle=mt_rand(-15,?15);?? ?????$x=5+$i*$size;?? ???????$y=mt_rand(20,?40); ???????????$fontfile="../fonts/".$fontfiles[mt_rand(0,?4)];? ??????????????$text=substr($chars,?$i,1); ??????????????????imagettftext($image,?$size,?$angle,?$x,?$y,?$black,?$fontfile,?$text);} ??????????????????ob_clean(); ??????????????????header("content-type:image/gif"); ??????????????????imagegif($image); ??????????????????imagedestroy($image);
? 這個是string.func的,為了避免出亂子我直接把類型寫死了,然后再取值,這部分出來的字符串也是沒問題的
<?php function?buildRandomString($length){???? $chars=join("",array_merge(range("a","z"),range("A","Z"),range(0,9)));???? $chars=str_shuffle($chars);???? $chars=substr($chars,?0,$length);???? return?$chars;}
這里我就在image.func調(diào)用了一下string.func中的字符串生成函數(shù),其他部分都用/**/注釋掉了,說明我字符串是被調(diào)用出來了,但是無法再畫布上顯示,我都快要崩潰了,不想搞這個了,但是又怕后面的內(nèi)容和這一塊有關,大約一個星期我就要去答辯去了,哪位大神解救我一下啊。
2019-07-24
imagettftext()需要freeType支持,可以改用imagestring()
2019-06-24
試了一下你的代碼,我用的自己的字體,可以輸出的,是不是你的字體右問題,把字體寫死,多試幾個字體