PHP 中的 imagepolygon() 函数
phpserver side programmingprogramming更新于 2025/7/6 9:52:17
imagepolygon() 函数用于绘制多边形。
语法
bool imagepolygon( $img, $points, $num_points, $color)
参数
- $img:使用 imagecreatetruecolor() 函数创建空白图像。
- $points:包含多边形顶点的数组。
- $num_points:多边形的顶点总数。
- $color:使用 imagecolorallocate() 函数创建的颜色标识符。
返回
imagepolygon() 函数在成功或失败时返回 TRUE失败时返回 FALSE。
示例
以下是示例:
<?php
$img = imagecreatetruecolor(400, 300);
$color = imagecolorallocate($img, 120, 160, 190);
$bgcolor = imagecolorallocate($img, 10, 100, 50);
imagefill($img, 0, 0, $bgcolor);
imagepolygon($img, array(
50, 50,
150, 200,
340, 200
),
3,
$color);
header('Content-type: image/png');
imagepng($img);
imagedestroy($img);
?>
输出
输出结果如下:


