畫布不出現 求大神指教
<?php
require_once 'string.func.php';
//通過GD庫做驗證碼
function verifyImage($type=1,$length=4,$pixel=0,$line=0,$sess_name="verify"){
//創建畫布
$w=300;
$h=80;
$img=imagecreatetruecolor($w, $h);// 創建畫布?
$white=imagecolorallocate($img, 255, 255, 225);//畫布顏色 白色
var_dump($white);
$black=imagecolorallocate($img, 255, 20, 40);//畫布顏色 ?黑色
imagefill($img, 0, 0, $white);
//用填充矩形填充畫布
imagefilledrectangle($img, 1, 1, $w-1, $h-1, $white);//用填充矩形填充畫布
$chars=buildRandomString($type,$length);//string.func.php中產生隨機字符串的函數
$_SESSION[$sess_name]=$chars;//用于比較用戶輸入是否正確
$fontfiles=array("SIMYOU.TIF");//字體
for($i=0; $i<$length;$i++){
$size=mt_rand(14, 18);
$angle=mt_rand(-15, 15);
$x=5+$i*$size;
$y=mt_rand(20, 26);
$fontfiles="../fonts".$fontfiles[mt_rand(0, count($fontfiles)-1)];
$color=imagecolorallocate($img, mt_rand(50, 90), mt_rand(80, 200), mt_rand(90, 180));
$text=substr($chars,$i,1);
imagettftext($img, $size, $angle, $x, $y, $color, $fontfiles, $text);
}
if($pixel){
for($i=0;$i<50;$i++){
imagesetpixel($img, mt_rand(0, $w-1), mt_rand(0, $h-1), $black);
}
}
if($line){
for($i=0;$i<$line;$i++){
$color=imagecolorallocate($img, mt_rand(50, 90), mt_rand(80, 200), mt_rand(90, 180));
imageline($img, ?mt_rand( 0, $w - 1 ), mt_rand( 0, $h - 1 ), mt_rand( 0, $w - 1 ), mt_rand( 0, $h - 1 ), $color);
}
}
header("content-type:image/gif");
imagegif($img);
imagedestroy($img);
}
2018-06-02
除了GD庫沒開以外,mysql服務沒開也有可能不顯示,我剛剛就那個情況,開了mysql就顯示了,也不清楚怎么回事,同求原因
2016-09-02
用填充矩形填充畫布之后輸出圖像
imagepng($img);