imagefilledpolygon()函数是PHP中的一个内置函数,用于绘制填充的多边形。此函数成功返回TRUE,否则返回FALSE。
用法:
bool imagefilledpolygon( $image, $points, $num_points, $color )
参数:该函数接受上述和以下所述的四个参数:
$image:imagecreatetruecolor()函数用于创建给定尺寸的空白图像。
$points:此参数用于保存多边形的连续顶点。
$num_points:此参数包含一个顶点中的顶点总数。它必须大于3,因为创建多边形至少需要三个顶点。
$color:此变量包含填充的颜色标识符。使用imagecolorallocate()函数创建的颜色标识符。
返回值:如果成功,则此函数返回TRUE;如果失败,则返回FALSE。
以下示例程序旨在说明PHP中的imagefilledpolygon()函数。
程序1:
// Set the vertices of polygon
$values = array(
150, 50, // Point 1 (x, y)
50, 250, // Point 2 (x, y)
250, 250 // Point 3 (x, y)
);
// It create the size of image or blank image.
$image = imagecreatetruecolor(300, 300);
// Set image background color
$bg = imagecolorallocate($image, 255, 255, 255);
// Set image color
$gr = imagecolorallocate($image, 0, 153, 0);
// fill the background
imagefilledrectangle($image, 0, 0, 300, 300, $bg);
// Draw the polygon
imagefilledpolygon($image, $values, 3, $gr);
// Output of the image.
header('Content-type:image/png');
imagepng($image);
?>
输出:
程序2:
// Set the vertices of polygon
$values = array(
150, 50, // Point 1 (x, y)
55, 119, // Point 2 (x, y)
91, 231, // Point 3 (x, y)
209, 231, // Point 4 (x, y)
245, 119 // Point 5 (x, y)
);
// It create the size of image or blank image.
$image = imagecreatetruecolor(300, 300);
// Set image background color
$bg = imagecolorallocate($image, 255, 255, 255);
// Set image color
$blue = imagecolorallocate($image, 0, 153, 0);
// fill the background
imagefilledrectangle($image, 0, 0, 300, 300, $bg);
// Draw the polygon
imagefilledpolygon($image, $values, 5, $blue);
// Output of the image.
header('Content-type:image/png');
imagepng($image);
imagedestroy($image);
?>
输出:
相关文章: