大网数据广告活动
PHP 语言与运行手册

imagefilledpolygon · 绘制多边形并填充

· 52CE 我爱测

image由图象创建函数(例如imagecreatetruecolor())返回的 GdImage 对象。

imagefilledpolygon

(PHP 4, PHP 5, PHP 7, PHP 8)

imagefilledpolygon — 绘制多边形并填充

说明

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

function imagefilledpolygon(GdImage $image, array $points, int $color): bool

替代签名(从 PHP 8.1.0 起弃用)

function imagefilledpolygon(
    GdImage $image,
    array $points,
    int $num_points,
    int $color
): bool

imagefilledpolygon() 在指定 image 中创建多边形并填充。

参数

image

由图象创建函数(例如imagecreatetruecolor())返回的 GdImage 对象。

points

包含连续多边形顶点的 x 和 y 坐标的数组。

num_points

点(顶点)的总数,必须最少为 3。

如果根据第二个签名省略此参数,则 points 必须具有偶数个元素,并且假定 num_points 为 count($points)/2。

color

颜色标识符使用 imagecolorallocate() 创建。

返回值

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

更新日志

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

示例

示例 #1 imagefilledpolygon() 示例

<?php
// 为多边形设置点数组
$values = array(
            40,  50,  // Point 1 (x, y)
            20,  240, // Point 2 (x, y)
            60,  60,  // Point 3 (x, y)
            240, 20,  // Point 4 (x, y)
            50,  40,  // Point 5 (x, y)
            10,  10   // Point 6 (x, y)
            );

// 创建图像
$image = imagecreatetruecolor(250, 250);

// 分配颜色
$bg   = imagecolorallocate($image, 0, 0, 0);
$blue = imagecolorallocate($image, 0, 0, 255);

// 填充背景
imagefilledrectangle($image, 0, 0, 249, 249, $bg);

// 绘制多边形
imagefilledpolygon($image, $values, $blue);

// 输出图像
header('Content-type: image/png');
imagepng($image);
?>

以上示例的输出类似于:

参见

来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
PHP Documentation Group
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。