imagefilledpolygon() 函数画一多边形并填充。
语法:
bool imagefilledpolygon( resource image, array points, int num_points, int color )
| 参数 | 说明 |
|---|---|
| image | 图像资源,欲绘制多边形的图像 |
| points | 按顺序包含有多边形各顶点的 x 和 y 坐标的数组 |
| num_points | 顶点的总数,必须大于 3 |
| color | 图像的颜色 |
绘制一个用红色填充的六边形例子:
<?php
header('Content-type: image/png');
$points = array(
50, 50, // Point 1 (x, y)
100, 50, // Point 2 (x, y)
150, 100, // Point 3 (x, y)
150, 150, // Point 4 (x, y)
100, 150, // Point 5 (x, y)
50, 100 // Point 6 (x, y)
);
$im = imagecreatetruecolor(200, 200);
$red = imagecolorallocate($im, 255, 0, 0);
imagefilledpolygon($im, $points, 6, $red);
imagepng($im);
imagedestroy($im);
?>