PHP建立影象時成為亂碼的解決方法(GD)
阿新 • • 發佈:2019-02-08
有問題的程式碼:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>php學習</title>
</head >
<body>
<?php
$im=imagecreate(200,200); //建立一個畫布(單位畫素pixel)
$white=imagecolorallocate($im,225,66,159); //設定畫布的背景顏色為粉色 (256RGB)
imagegif($im); //輸出gif影象
imagedestroy($im);
?>
</body>
</html>
執行結果:
修改後的程式碼:
<?php
$im=imagecreate(200,200); //建立一個畫布(單位畫素pixel)
$white=imagecolorallocate($im ,225,66,159); //設定畫布的背景顏色為粉色 (256RGB)
header('content-type:image/gif'); //設定gif Image
imagegif($im); //輸出gif影象
imagedestroy($im);
?>
執行結果: