English | 简体中文 | 繁體中文
查询

imagepolygon函数—用法及示例

「 绘制多边形 」


适用PHP版本(PHP 4, PHP 5, PHP 7, PHP 8)


说明

自 PHP 8.0.0 起的签名(不支持命名参数)

imagepolygon(GdImage $image, array $points, int $color): bool
替代签名(从 PHP 8.1.0 开始弃用)

imagepolygon(
    GdImage $image,
    array $points,
    int $num_points,
    int $color
): bool
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() 创建。

返回值
成功时返回 true, 或者在失败时返回 false。

更新日志

版本说明
8.1.0弃用参数 num_points
8.0.0image 现在需要 GdImage 实例;之前需要有效的 gd resource

示例 ¶
示例 #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);
?>

以上示例的输出类似于:



补充纠错
上一个函数: imagepng函数
下一个函数: imagesetclip函数
热门PHP函数
分享链接