php imagefill,PHP 图像填充 imagefill、imagefilledarc 与 imagefilledrectangle() 函数
imagefill() 函數用于區域填充。
語法:
bool imagefill( resource image, int x, int y, int color )
x,y 分別為填充的起始 x 坐標和 y 坐標,與 x, y 點顏色相同且相鄰的點都會被填充。
例子:
header("Content-type: image/png");
$im = @imagecreatetruecolor(200, 200);
$red = imagecolorallocate($im, 255, 0, 0);
//用 $red 顏色填充圖像
imagefill( $im, 0, 0, $red );
imagepng($im);
imagedestroy($im);
?>
imagefilledarc() 函數畫一橢圓弧并填充。
語法:
bool imagefilledarc( resource image, int cx, int cy, int w, int h, int s, int e, int color, int style )
該函數參數用法可參考繪制橢圓弧函數 imagearc() ,只是本函數增加 style 參數表示填充方式。
style 填充方式說明:
填充方式
說明
IMG_ARC_PIE
普通填充,產生圓形邊界
IMG_ARC_CHORD
只是用直線連接了起始和結束點,與 IMG_ARC_PIE 方式互斥
IMG_ARC_NOFILL
指明弧或弦只有輪廓,不填充
IMG_ARC_EDGED
指明用直線將起始和結束點與中心點相連
例子:
header('Content-type: image/png');
$im = imagecreatetruecolor(100, 100);
$red = imagecolorallocate($im, 255, 0, 0);
imagefilledarc($im, 50, 50, 100, 50, 0, 360 , $red, IMG_ARC_PIE);
imagepng($im);
imagedestroy($im);
?>
該函數典型應用之一是畫餅狀統計圖。
imagefilledrectangle() 函數畫一矩形并填充。
語法:
bool imagefilledrectangle( resource image, int x1, int y1, int x2, int y2, int color )
x1,y1為左上角左邊,x2,y2為右下角坐標。
例子:
header('Content-type: image/png');
$im = imagecreatetruecolor(200, 200);
$yellow = imagecolorallocate($im, 255, 255, 0);
imagefilledrectangle($im, 20, 150, 40, 200, $yellow);
imagefilledrectangle($im, 50, 80, 70, 200, $yellow);
imagepng($im);
imagedestroy($im);
?>
該函數典型應用之一是柱狀統計圖。
imagefilledpolygon() 函數畫一多邊形并填充。
語法:
bool imagefilledpolygon( resource image, array points, int num_points, int color )
參數說明:
參數
說明
image
圖像資源,欲繪制多邊形的圖像
points
按順序包含有多邊形各頂點的 x 和 y 坐標的數組
num_points
頂點的總數,必須大于 3
color
圖像的顏色
繪制一個用紅色填充的六邊形例子:
header('Content-type: image/png');
$points = array(
50, 50,// Point 1 (x, y)
100, 50, // Point 2 (x, y)
150, 100, // Point 3 (x, y)
150, 150,// Point 4 (x, y)
100, 150, // Point 5 (x, y)
50, 100// Point 6 (x, y)
);
$im = imagecreatetruecolor(200, 200);
$red = imagecolorallocate($im, 255, 0, 0);
imagefilledpolygon($im, $points, 6, $red);
imagepng($im);
imagedestroy($im);
?>
總結
以上是生活随笔為你收集整理的php imagefill,PHP 图像填充 imagefill、imagefilledarc 与 imagefilledrectangle() 函数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php文字超链接怎么写,php 文本UR
- 下一篇: php 画布插入图像,javascrip