例一:輸出藍色背景和交叉白線的圖形
<?php $width=35; $height=35; //創(chuàng)建對象 $image=imagecreate($width,$height); //提取顏色 $color_white=imagecolorallocate($image,255,255,255);//白色 $color_blue=imagecolorallocate($image,0,0,108);//藍色 imagefill($image,0,0,$color_blue); //作圖 //線寬 imagesetthickness($image,3); imageline($image,0,0,$width,$height ,$color_white); imageline($image,$width,0,0,$height ,$color_white);
//發(fā)送對象至頭 header('content-type:image/png'); imagepng($image); /* //發(fā)送對象至文件 $filename="ex1.png"; imagepng($image,$filename); */ //銷毀對象 imagedestroy($image); ?>
輸出圖象:
在線演示: http://www.phzzy.org/temp/5do8/ex1.php
例二: 陰陽圖
<?php $width=400; $height=400; $image=imagecreatetruecolor($width,$height); //提取顏色 $color_black=imagecolorallocate($image,0,2,0);// $color_white=imagecolorallocate($image,255,255,255);//白色 $color_blue=imagecolorallocate($image,0,0,108);//藍色 $color_red=imagecolorallocate($image,151,0,4);//紅色 $color_my=imagecolorallocate($image,192,192,255);//背景 $color_temp=imagecolorallocate($image,199,199,199);//背景 //作圖 imagefill($image,0,0,$color_white);
//第一個是大圓 imagefilledarc ($image,$width/2,$height/2,$height,$height,0,360,$color_blue,IMG_ARC_PIE); //兩個小圓 imagefilledellipse ($image,$width/2,$height/4 ,$height/2,$height/2,$color_red); imagefilledellipse ($image,$width/2,$height/4 * 3,$height/2,$height/2,$color_blue); /*imagefilledellipse -- 畫一橢圓并填充*/ imagefilledarc ($image,$width/2,$height/2,$height,$height,-90,90,$color_red,IMG_ARC_PIE); imagefilledellipse ($image,$width/2,$height/4 * 3,$height/2,$height/2,$color_blue); //發(fā)送對象至頭 header('content-type:image/png'); imagepng($image); /* //發(fā)送對象至文件 $filename="ex1.png"; imagepng($image,$filename); */ //銷毀對象 imagedestroy($image); ?>
演示: http://www.phzzy.org/temp/5do8/ex2.php
例三:3D圖像--cool
<?php $width=400; $height=400; $image = imagecreatetruecolor($width, $height); $white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF); $gray = imagecolorallocate($image, 0xC0, 0xC0, 0xC0); $darkgray = imagecolorallocate($image, 0x90, 0x90, 0x90); $navy = imagecolorallocate($image, 0x00, 0x00, 0x80); $darknavy = imagecolorallocate($image, 0x00, 0x00, 0x50); $red = imagecolorallocate($image, 0xFF, 0x00, 0x00); $darkred = imagecolorallocate($image, 0x90, 0x00, 0x00); imagefill($image,0,0,$white);
// make the 3D effect for ($i = $height /2 +20; $i > $height /2; $i--) { imagefilledarc($image, $width/2, $i, $width/2, $height /2, 0, 45, $darknavy, IMG_ARC_PIE); imagefilledarc($image, $width/2, $i, $width/2, $height /2, 45, 75 , $darkgray, IMG_ARC_PIE); imagefilledarc($image, $width/2, $i, $width/2, $height /2, 75, 360 , $darkred, IMG_ARC_PIE); }
imagefilledarc($image, $width/2, $height /2, $width/2, $height /2, 0, 45, $navy, IMG_ARC_PIE); imagefilledarc($image, $width/2, $height /2, $width/2, $height /2, 45, 75 , $gray, IMG_ARC_PIE); imagefilledarc($image, $width/2, $height /2, $width/2, $height /2, 75, 360 , $red, IMG_ARC_PIE);
// flush image header('Content-type: image/png'); imagepng($image); imagedestroy($image); /* //發(fā)送對象至文件 $filename="ex1.png"; imagepng($image,$filename); */
?>
演示: http://www.phzzy.org/temp/5do8/ex3.php
出處:藍色理想
責任編輯:moby
上一頁 玩轉(zhuǎn)圖像函數(shù)庫—常見圖形操作 [1] 下一頁 玩轉(zhuǎn)圖像函數(shù)庫—常見圖形操作 [3]
◎進入論壇網(wǎng)絡(luò)編程版塊參加討論
|