这个 imagepolygon() 函数是PHP中的一个内置函数,用于绘制多边形。此函数在成功时返回TRUE,否则返回FALSE。 语法:
null
bool imagepolygon( $image, $points, $num_points, $color )
参数: 该函数接受上述四个参数,如下所述:
- $image: 函数用于创建给定大小的空白图像。
- $points: 此参数用于保持多边形的连续顶点。
- $num_点数: 此参数包含多边形中的顶点总数。它必须大于3,因为创建多边形至少需要三个顶点。
- $color: 此变量包含填充的颜色标识符。使用imagecolorallocate()函数创建的颜色标识符。
返回值: 此函数在成功时返回TRUE,失败时返回FALSE。 下面的程序说明了 imagepolygon() 函数。 项目1:
php
<?php // 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) ); // Create the size of image or blank image $image = imagecreatetruecolor(300, 300); // Set the background color of image $background_color = imagecolorallocate( $image , 0, 153, 0); // Fill background with above selected color imagefill( $image , 0, 0, $background_color ); // Allocate a color for the polygon $image_color = imagecolorallocate( $image , 255, 255, 255); // Draw the polygon imagepolygon( $image , $values , 3, $image_color ); // Output the picture to the browser header( 'Content-type: image/png' ); imagepng( $image ); ?> |
输出:
项目2:
php
<?php // 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) ); // Create the size of image or blank image $image = imagecreatetruecolor(300, 300); // Set the background color of image $background_color = imagecolorallocate( $image , 0, 153, 0); // Fill background with above selected color imagefill( $image , 0, 0, $background_color ); // Allocate a color for the polygon $col_poly = imagecolorallocate( $image , 255, 255, 255); // Draw the polygon imagepolygon( $image , $values , 5, $col_poly ); // Output the picture to the browser header( 'Content-type: image/png' ); imagepng( $image ); ?> |
输出:
相关文章:
参考: http://php.net/manual/en/function.imagepolygon.php
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END