//建立映像
$im=imagecreatetruecolor(100,100);
//將背景設為紅色
$red=imagecolorallocate($im,255,0,0);
imagefill($im,0,0,$red);
//輸出映像
header('content-type: image/png');
imagepng($im);
imagedestroy($im);
/*
執行該代碼,將產生背景為紅色的圖形。
*/
//代碼二
//建立真彩色映像
$img=imagecreatetruecolor(400,400);
//通過迴圈執行操作
for($i=10;$i<=350;$i=$i+20)
{
//定義顏色
$color=imagecolorallocate($img,200,50,$i);
//畫出橢圓
imageellips教程e($img,200,200,350,$i,$color);
}
//輸出映像
header("content-type: image/png");
imagepng($img);
//銷毀映像
imagedestroy($img);
/*
該代碼的執行結果如圖:22.7所示:
*/
//代碼三
//建立真彩色映像
$img=imagecreatetruecolor(200,200);
$white=imagecolorallocate($img,255,255,255);
$red=imagecolorallocate($img,255,0,0);
$blue=imagecolorallocate($img,0,0,255);
//在映像上畫圖
imagearc($img,100,100,50,150,360,0,$red);
imagearc($img,100,100,150,50,0,360,$blue);
//輸出映像
header("content-type: image/png");
imagepng($img);
//銷毀映像
imagedestroy($img);
/*
該代碼的的執行結果如圖22.6所示:
*/
//執行個體四
//發送標頭檔
header("content-type: image/png");
//建立映像,如果失敗輸出內容
$im=imagecreatetruecolor(500,500); //建立映像
//定義背景顏色
$black=imagecolorallocate($im,0,0,0);
//定義線顏色
$color=imagecolorallocate($im,0,255,255);
//在映像上畫出虛線
imageline($im,1,1,450,450,$color);
//輸出影像檔
imagepng($im);
//銷毀映像
imagedestroy($im);