php polygon,PHP imagefilledpolygon()用法及代码示例

imagefilledpolygon()函数是PHP中的一个内置函数,用于绘制填充的多边形。此函数成功返回TRUE,否则返回FALSE。

用法:

bool imagefilledpolygon( $image, $points, $num_points, $color )

参数:该函数接受上述和以下所述的四个参数:

$image:imagecreatetruecolor()函数用于创建给定尺寸的空白图像。

$points:此参数用于保存多边形的连续顶点。

$num_points:此参数包含一个顶点中的顶点总数。它必须大于3,因为创建多边形至少需要三个顶点。

$color:此变量包含填充的颜色标识符。使用imagecolorallocate()函数创建的颜色标识符。

返回值:如果成功,则此函数返回TRUE;如果失败,则返回FALSE。

以下示例程序旨在说明PHP中的imagefilledpolygon()函数。

程序1:

// Set the vertices of polygon

$values = array(

150,  50, // Point 1 (x, y)

50, 250,  // Point 2 (x, y)

250,  250 // Point 3 (x, y)

);

// It create the size of image or blank image.

$image = imagecreatetruecolor(300, 300);

// Set image background color

$bg   = imagecolorallocate($image, 255, 255, 255);

// Set image color

$gr = imagecolorallocate($image, 0, 153, 0);

// fill the background

imagefilledrectangle($image, 0, 0, 300, 300, $bg);

// Draw the polygon

imagefilledpolygon($image, $values, 3, $gr);

// Output of the image.

header('Content-type:image/png');

imagepng($image);

?>

输出:

9e52d6e02d9f30cbd545dc08c53c749e.png

程序2:

// Set the vertices of polygon

$values = array(

150, 50, // Point 1 (x, y)

55, 119, // Point 2 (x, y)

91, 231, // Point 3 (x, y)

209, 231, // Point 4 (x, y)

245, 119  // Point 5 (x, y)

);

// It create the size of image or blank image.

$image = imagecreatetruecolor(300, 300);

// Set image background color

$bg   = imagecolorallocate($image, 255, 255, 255);

// Set image color

$blue = imagecolorallocate($image, 0, 153, 0);

// fill the background

imagefilledrectangle($image, 0, 0, 300, 300, $bg);

// Draw the polygon

imagefilledpolygon($image, $values, 5, $blue);

// Output of the image.

header('Content-type:image/png');

imagepng($image);

imagedestroy($image);

?>

输出:

c41b33dea3f1dd62e1441465bda3255e.png

相关文章:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值