php imagepolygon()函数在给定图像中创建一个多边形。
语法
PHP imagepolygon()函数具有以下语法。
bool imagepolygon ( resource $image , array $points , int $num_points , int $color )
参数
PHP imagepolygon()函数具有以下参数。
image - 由图像创建函数(如imagecreatetruecolor())返回的图像资源。
points - 包含多边形顶点的数组。
num_points - 点(顶点)的总数。
color - 使用imagecolorallocate()创建的颜色标识符。
点格式
看看下面的代码:
$myPoints = array( 20, 20,
185, 55,
70, 80 );
imagepolygon( $myImage, $myPoints, 3, $myBlack );
此示例创建一个多边形点的数组,称为$ myPoints。数组中有六个元素,或三个x / y坐标对。
这意味着这个多边形有三个角:在(20,20),(185,55)和(70,80)。
返回值
成功时返回TRUE,失败时返回FALSE。
实例
/*
http://www.manongjc.com/article/1756.html
作者:码农教程
*/
// Create a blank image
$image = imagecreatetruecolor(400, 300);
// Allocate a color for the polygon
$col_poly = imagecolorallocate($image, 255, 255, 255);
// Draw the polygon
imagepolygon($image, array(
0, 0,
100, 200,
300, 200
),
3,
$col_poly);
// Output the picture to the browser
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
?>