php imagefill,PHP 图像填充 imagefill、imagefilledarc 与 imagefilledrectangle() 函数

本文介绍PHP中使用imagefill(), imagefilledarc(), imagefilledrectangle(), 和imagefilledpolygon()函数进行图像填充的方法,包括区域填充、椭圆弧填充、矩形填充及多边形填充等,并通过实例展示了这些函数的应用。

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);

?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值