畫(huà)布不出現(xiàn) 求大神指教
<?php
require_once 'string.func.php';
//通過(guò)GD庫(kù)做驗(yàn)證碼
function verifyImage($type=1,$length=4,$pixel=0,$line=0,$sess_name="verify"){
//創(chuàng)建畫(huà)布
$w=300;
$h=80;
$img=imagecreatetruecolor($w, $h);// 創(chuàng)建畫(huà)布?
$white=imagecolorallocate($img, 255, 255, 225);//畫(huà)布顏色 白色
var_dump($white);
$black=imagecolorallocate($img, 255, 20, 40);//畫(huà)布顏色 ?黑色
imagefill($img, 0, 0, $white);
//用填充矩形填充畫(huà)布
imagefilledrectangle($img, 1, 1, $w-1, $h-1, $white);//用填充矩形填充畫(huà)布
$chars=buildRandomString($type,$length);//string.func.php中產(chǎn)生隨機(jī)字符串的函數(shù)
$_SESSION[$sess_name]=$chars;//用于比較用戶(hù)輸入是否正確
$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庫(kù)沒(méi)開(kāi)以外,mysql服務(wù)沒(méi)開(kāi)也有可能不顯示,我剛剛就那個(gè)情況,開(kāi)了mysql就顯示了,也不清楚怎么回事,同求原因
2016-09-02
用填充矩形填充畫(huà)布之后輸出圖像
imagepng($img);