array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.imagepolygon.php', 1 => 'imagepolygon', ), 'up' => array ( 0 => 'ref.image.php', 1 => 'GD 和图像处理 函数', ), 'prev' => array ( 0 => 'function.imagepng.php', 1 => 'imagepng', ), 'next' => array ( 0 => 'function.imagerectangle.php', 1 => 'imagerectangle', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/image/functions/imagepolygon.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(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
// Create a blank image
$image = imagecreatetruecolor(400, 300);
// Allocate a color for the polygon
$col_poly = imagecolorallocate($image, 255, 255, 255);
// Draw the polygon
imagepolygon($image, array(
0, 0,
100, 200,
300, 200
),
3,
$col_poly);
// Output the picture to the browser
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
?>
以上示例的输出类似于: