牛牛在线工具

imagefilledpolygon()

收录 8868 个 PHP 函数,含用途说明与用法示例。

imagefilledpolygon()

创建一个填充的多边形

函数名:imagefilledpolygon() 适用版本:PHP 4 >= 4.0.6, PHP 5, PHP 7 用法:imagefilledpolygon() 函数用于创建一个填充的多边形。它接受一个图像资源作为第一个参数,以及一个包含多边形顶点坐标的数组作为第二个参数。还可以选择性地指定填充颜色。 语法:bool imagefilledpolygon ( resource $image , array $points , int $num_points , int $color ) 参数: $image:图像资源,使用 imagecreatetruecolor() 或 imagecreate() 创建。 $points:包含多边形顶点坐标的数组。数组每两个连续的元素表示一个顶点的 x 和 y 坐标。 $num_points:多边形的顶点数。 $color:填充颜色,使用 imagecolorallocate() 创建。 返回值:成功时返回 true,失败时返回 false。 示例: // 创建一个 200x200 的图像 $image = imagecreatetruecolor(200, 200); // 分配填充颜色 $fillColor = imagecolorallocate($image, 255, 0, 0); // 定义多边形的顶点坐标 $points = array( 100, 10, // 顶点1的坐标 150, 100, // 顶点2的坐标 100, 190, // 顶点3的坐标 50, 100 // 顶点4的坐标 ); // 创建填充的多边形 imagefilledpolygon($image, $points, 4, $fillColor); // 输出图像到浏览器 header('Content-type: image/png'); imagepng($image); // 释放内存 imagedestroy($image); 以上示例创建了一个红色填充的四边形,并将其输出到浏览器。你可以根据需要修改顶点坐标和填充颜色来创建不同形状和颜色的填充多边形。