imagepolygon
(PHP 4, PHP 5, PHP 7, PHP 8)
imagepolygon — 绘制多边形
说明
自 PHP 8.0.0 起的签名(不支持命名参数)
替代签名(从 PHP 8.1.0 开始弃用)
imagepolygon() 在指定 image 中创建多边形。
参数
-
image 由图象创建函数(例如imagecreatetruecolor())返回的 GdImage 对象。
points-
包含多边形顶点的数组,例如:
points[0] = x0 points[1] = y0 points[2] = x1 points[3] = y1 num_points-
点(顶点)的总数,必须最少为 3。
如果根据第二个签名省略此参数,则points必须具有偶数个元素,并且假定num_points为count($points)/2。 color-
颜色标识符使用 imagecolorallocate() 创建。
示例
示例 #1 imagepolygon() 示例
<?php
// 创建空白图像
$image = imagecreatetruecolor(400, 300);
// 为多边形分配颜色
$col_poly = imagecolorallocate($image, 255, 255, 255);
// 绘制多边形
imagepolygon($image, array(
0, 0,
100, 200,
300, 200
),
$col_poly);
// 输出图像到浏览器
header('Content-type: image/png');
imagepng($image);
?>以上示例的输出类似于:
参见
- imagefilledpolygon() - 绘制多边形并填充
- imageopenpolygon() - Draws an open polygon
- imagecreate() - 创建新的基于调色板的图像
- imagecreatetruecolor() - 新建真彩色图像