PHP gd庫在html中生成的影象不顯示的
阿新 • • 發佈:2018-12-16
生成圖片的PHP檔案單獨放在資料夾裡面,然後在另一個需要顯示這個圖片的頁面裡寫個< src="PHP圖片路徑" />
就可以啦!
例如:
phpimagecreate.php:
<?php $ysize = 300; $xsize = 200; $theimage = imagecreatetruecolor($xsize, $ysize); //建立畫布 $color1 = imagecolorallocate($theimage, 249,38,114); //在畫布上選定顏色 $color2 = imagecolorallocate($theimage, 8, 2, 133); imagefill($theimage, 0, 0, $color2); //對畫布填充顏色 imageline($theimage, 0, 0, $xsize, $ysize, $color1); //在畫布內畫線 header('content-type:image/png'); //定義輸出的檔案時image的png格式 imagepng($theimage); //生成$theimage畫布中的所有內容 imagedestroy($theimage); //清楚$theimage物件 ?>
needphpimage.php:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>建立一個簡單的影象</title>
</head>
<body>
<img src="phpimagecreate.php">
</body>
</html>