您的位置:首页 > 编程语言 > PHP开发

10. PHP 图像填充 imagefill、imagefilledarc 与 imagefilledrectangle() 函数

2016-07-19 09:55 666 查看
imagefill() 函数用于图像区域填充。imagefilledarc() 函数画一椭圆弧并填充。imagefilledrectangle() 函数画一矩形并填充。imagefilledpolygon() 函数画一多边形并填充。


imagefill()

imagefill() 函数用于区域填充。

语法:
bool imagefill( resource image, int x, int y, int color )


x,y 分别为填充的起始 x 坐标和 y 坐标,与 x, y 点颜色相同且相邻的点都会被填充。

例子:
<?php
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);
?>


提示:对于用 imagecreate() 建立的图像,第一次调用 imagecolorallocate() 会自动给图像填充背景色。


imagefilledarc()

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指明用直线将起始和结束点与中心点相连
例子:
<?php
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()

imagefilledrectangle() 函数画一矩形并填充。

语法:
bool imagefilledrectangle( resource image, int x1, int y1, int x2, int y2, int color )


x1,y1为左上角左边,x2,y2为右下角坐标。

例子:
<?php
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()

imagefilledpolygon() 函数画一多边形并填充。

语法:
bool imagefilledpolygon( resource image, array points, int num_points, int color )

参数说明:
参数说明
image图像资源,欲绘制多边形的图像
points按顺序包含有多边形各顶点的 x 和 y 坐标的数组
num_points顶点的总数,必须大于 3
color图像的颜色
绘制一个用红色填充的六边形例子:
<?php
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);
?>


imagefill() 函数用于图像区域填充。imagefilledarc() 函数画一椭圆弧并填充。imagefilledrectangle() 函数画一矩形并填充。imagefilledpolygon() 函数画一多边形并填充。


imagefill()

imagefill() 函数用于区域填充。

语法:
bool imagefill( resource image, int x, int y, int color )


x,y 分别为填充的起始 x 坐标和 y 坐标,与 x, y 点颜色相同且相邻的点都会被填充。

例子:
<?php
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);
?>


提示:对于用 imagecreate() 建立的图像,第一次调用 imagecolorallocate() 会自动给图像填充背景色。


imagefilledarc()

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指明用直线将起始和结束点与中心点相连
例子:
<?php
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()

imagefilledrectangle() 函数画一矩形并填充。

语法:
bool imagefilledrectangle( resource image, int x1, int y1, int x2, int y2, int color )


x1,y1为左上角左边,x2,y2为右下角坐标。

例子:
<?php
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()

imagefilledpolygon() 函数画一多边形并填充。

语法:
bool imagefilledpolygon( resource image, array points, int num_points, int color )

参数说明:
参数说明
image图像资源,欲绘制多边形的图像
points按顺序包含有多边形各顶点的 x 和 y 坐标的数组
num_points顶点的总数,必须大于 3
color图像的颜色
绘制一个用红色填充的六边形例子:
<?php
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);
?>


本文地址:http://blog.csdn.net/aerchi/article/details/51953072
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: