方法1:用記事本寫,再另存爲utf-8 no bom的格式。
方法2:在代碼中添加ob_clean()函數,清空(擦掉)輸出緩衝區。
代碼如下:
<?php
//用其他編輯器打開存儲爲utf-8 no bom
ob_clean();/* 清空(擦掉)輸出緩衝區,不加此行可能無法顯示圖像*/
$height=600;
$width=600;
//創建一個圖像標識符
$im=imagecreatetruecolor($width,$height);
//爲圖像選擇顏色
$white=imagecolorallocate($im,255,255,255);
$blue=imagecolorallocate($im,0,0,64);
$c=imagecolorallocate($im,255,125,10);
$red=imagecolorallocate($im,255,0,0);
//繪製背景顏色
imagefill($im,0,0,$blue);
//從左上角開始畫一條線導圖像右下角
imageline($im,0,0,$width,$height,$white);
//從左下角開始畫一條線導圖像右上角
imageline($im,600,0,0,600,$red);
//添加文字
imagestring($im,5,250,150,'Hello World!',$c);
Header('Content-type:image/png');
imagepng($im);
imagedestroy($im);
?>
輸出: