php imagefill,PHP 图像填充 imagefill、imagefilledarc 与 imagefilledrectangle() 函数
imagefill() 函數(shù)用于區(qū)域填充。
語法:
bool imagefill( resource image, int x, int y, int color )
x,y 分別為填充的起始 x 坐標(biāo)和 y 坐標(biāo),與 x, y 點(diǎn)顏色相同且相鄰的點(diǎn)都會(huì)被填充。
例子:
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() 函數(shù)畫一橢圓弧并填充。
語法:
bool imagefilledarc( resource image, int cx, int cy, int w, int h, int s, int e, int color, int style )
該函數(shù)參數(shù)用法可參考繪制橢圓弧函數(shù) imagearc() ,只是本函數(shù)增加 style 參數(shù)表示填充方式。
style 填充方式說明:
填充方式
說明
IMG_ARC_PIE
普通填充,產(chǎn)生圓形邊界
IMG_ARC_CHORD
只是用直線連接了起始和結(jié)束點(diǎn),與 IMG_ARC_PIE 方式互斥
IMG_ARC_NOFILL
指明弧或弦只有輪廓,不填充
IMG_ARC_EDGED
指明用直線將起始和結(jié)束點(diǎn)與中心點(diǎn)相連
例子:
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);
?>
該函數(shù)典型應(yīng)用之一是畫餅狀統(tǒng)計(jì)圖。
imagefilledrectangle() 函數(shù)畫一矩形并填充。
語法:
bool imagefilledrectangle( resource image, int x1, int y1, int x2, int y2, int color )
x1,y1為左上角左邊,x2,y2為右下角坐標(biāo)。
例子:
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);
?>
該函數(shù)典型應(yīng)用之一是柱狀統(tǒng)計(jì)圖。
imagefilledpolygon() 函數(shù)畫一多邊形并填充。
語法:
bool imagefilledpolygon( resource image, array points, int num_points, int color )
參數(shù)說明:
參數(shù)
說明
image
圖像資源,欲繪制多邊形的圖像
points
按順序包含有多邊形各頂點(diǎn)的 x 和 y 坐標(biāo)的數(shù)組
num_points
頂點(diǎn)的總數(shù),必須大于 3
color
圖像的顏色
繪制一個(gè)用紅色填充的六邊形例子:
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);
?>
總結(jié)
以上是生活随笔為你收集整理的php imagefill,PHP 图像填充 imagefill、imagefilledarc 与 imagefilledrectangle() 函数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php文字超链接怎么写,php 文本UR
- 下一篇: 动态规划算法php,php算法学习之动态