PHP 中的 imagepolygon() 函数


imagepolygon() 函数用于绘制多边形。

语法

bool imagepolygon( $img, $points, $num_points, $color)

参数

  • $img:使用 imagecreatetruecolor() 函数创建一个空图像。
  • $points:一个包含多边形顶点的数组。
  • $num_points:多边形中的顶点数目。
  • $color:使用 imagecolorallocate() 函数创建的颜色标识符。

返回值

如果成功,imagepolygon() 函数返回 TRUE;如果失败,返回 FALSE。

示例

以下是示例

<?php
   $img = imagecreatetruecolor(400, 300);
   $color = imagecolorallocate($img, 120, 160, 190);
   $bgcolor = imagecolorallocate($img, 10, 100, 50);  
   imagefill($img, 0, 0, $bgcolor);
   imagepolygon($img, array(
      50, 50,
      150, 200,
      340, 200
   ),
   3,
   $color);
   header('Content-type: image/png');
   imagepng($img);
   imagedestroy($img);
?>

输出

以下为输出

更新于: 31-Dec-2019

314 次浏览

开启您的事业

完成课程获取认证

开始学习
广告
© . All rights reserved.