1:畫矩形:
imagerectangle ( resource
$image
, int $x1
, int $y1
, int $x2
, int $y2
, int $col
)
imagerectangle() 用 col
顏色在 image
圖像中畫一個矩形,其左上角坐標為 x1, y1,右下角坐標為 x2, y2。圖像的左上角坐標為 0, 0。
2:畫橢圓:
imageellipse ( resource $image
, int $cx
, int $cy
, int $width
, int $height
, int $color
)
cx
中間的 X 坐標。cy
中間的 Y 坐標。width
橢圓的寬度。height
橢圓的高度。color
橢圓的顏色。
3:畫橢圓弧:
imagearc ( resource
$image
, int $cx
, int $cy
, int $w
, int $h
, int $s
, int $e
, int $color
)(即在橢圓中截取一定的弧度)
imagearc() 以 cx
,cy
(圖像左上角為 0, 0)為中心在 image
所代表的圖像中畫一個橢圓弧。w
和 h
分別指定了橢圓的寬度和高度,起始和結束點以 s
和 e
參數以角度指定。0°位於三點鍾位置,以順時針方向繪畫。
4:畫餅狀圖:先循環畫多個圓心在一條直線上的橢圓並填充
1 for($i=100;$i>50;$i--){ 2 imagefilledarc($image, 150, $i, 150, 100, 0, 270, $gray,IMG_ARC_EDGED ); 3 }
imagefilledarc ( resource $image
, int $cx
, int $cy
, int $width
, int $height
, int $start
, int $end
, int $color
, int $style
)
cx:
中間的 x 坐標。cy:
中間的 y 坐標。width:
橢圓弧的寬度。height:
橢圓弧的高度。start:
起點角度。end:
終點角度。 0°color:
顏色標識符。
style:
IMG_ARC_PIE :則產生圓形邊界並填充
IMG_ARC_CHORD :只是用直線連接了起始和結束點並填充
IMG_ARC_NOFILL:
則產生圓形邊界不填充
IMG_ARC_EDGED:指明用直線將起始和結束點與中心點相連
簡單事例:
前台代碼:
1 <div style="width:300px;height:400px;border:1px solid gray;margin:auto;"> 2 <h2 style="text-align:center">全校學生分布統計</h2> 3 <center> 4 <form action="11Pro.php" method="post"> 5 安徽:<input type="text" name="anhui"><br/> 6 浙江:<input type="text" name="zhejiang"><br/> 7 吉林:<input type="text" name="jilin"><br/> 8 北京:<input type="text" name="beijing"><br/><br/> 9 <input style="width:160px;" type="submit" value="生成餅狀圖"><br/> 10 <input style="width:160px;" type="reset" value="重置"> 11 </form> 12 </center> 13 </div>
前台界面:
后台PHP代碼:
1 <?php 2 3 //創建畫布 4 $image=imagecreatetruecolor(200,200); 5 6 7 //定義顏色 8 $red=imagecolorallocate($image, 255, 0, 0); 9 $darkred=imagecolorallocate($image, 102, 0, 0); 10 11 $blue=imagecolorallocate($image, 0, 0, 255); 12 $darkblue=imagecolorallocate($image, 0, 51, 102);; 13 14 15 $green=imagecolorallocate($image, 0, 255, 0); 16 $darkgreen=imagecolorallocate($image, 51, 102, 51); 17 18 $gray=imagecolorallocate($image, 125, 125, 125); 19 $darkgray=imagecolorallocate($image, 102, 102, 102); 20 21 $anhui=$_POST['anhui']; 22 $jilin=$_POST['jilin']; 23 $beijing=$_POST['beijing']; 24 $zhejiang=$_POST['zhejiang']; 25 26 $count=$anhui+$beijing+$jilin+$zhejiang; 27 28 //循環畫餅狀圖 29 for($i=100;$i>85;$i--){ 30 imagefilledarc($image, 100, $i, 150, 100, 0, ($anhui/$count)*360, $darkgray, IMG_ARC_PIE); 31 imagefilledarc($image, 100, $i, 150, 100, ($anhui/$count)*360, (($anhui+$jilin)/$count)*360, $darkblue, IMG_ARC_PIE); 32 imagefilledarc($image, 100, $i, 150, 100, (($anhui+$jilin)/$count)*360, (($anhui+$jilin+$beijing)/$count)*360, $darkgreen, IMG_ARC_PIE); 33 imagefilledarc($image, 100, $i, 150, 100, (($anhui+$jilin+$beijing)/$count)*360, 360, $darkred, IMG_ARC_PIE); 34 } 35 imagefilledarc($image, 100, 85, 150, 100, 0, ($anhui/$count)*360, $gray, IMG_ARC_PIE); 36 imagefilledarc($image, 100, 85, 150, 100, ($anhui/$count)*360, (($anhui+$jilin)/$count)*360, $blue, IMG_ARC_PIE); 37 imagefilledarc($image, 100, 85, 150, 100, (($anhui+$jilin)/$count)*360, (($anhui+$jilin+$beijing)/$count)*360, $green, IMG_ARC_PIE); 38 imagefilledarc($image, 100, 85, 150, 100, (($anhui+$jilin+$beijing)/$count)*360, 360, $red, IMG_ARC_PIE); 39 40 header("Content-type: image/png"); 41 42 imagepng($image); 43 44 imagedestroy($image); 45 46 ?>
后台處理結果: