如何使用PHP中的imagefilledpolygon()函数绘制填充的多边形?

王林
发布: 2023-09-14 17:45:08
转载
1091人浏览过

imagefilledpolygon() 是一个内置 php 函数,用于绘制填充多边形。

语法

bool imagefilledpolygon($image, $points, $num_points, $color)
登录后复制

参数

imagefilledpolygon()采用四个不同的参数 - $image、$points、$ num_points 和 $颜色。

  • $图像 - 使用 imagecreatetruecolor() 函数创建给定尺寸的空白图像。

  • $points - 保存多边形的连续顶点。

  • $num_points - 包含多边形中的顶点总数。点/顶点的总数必须至少为三个才能创建多边形。

    立即学习PHP免费学习笔记(深入)”;

    即构数智人
    即构数智人

    即构数智人是由即构科技推出的AI虚拟数字人视频创作平台,支持数字人形象定制、短视频创作、数字人直播等。

    即构数智人 36
    查看详情 即构数智人
  • $color - 包含使用 imagecolorallocate() 函数填充颜色标识符。

返回值

成功时返回 True,失败时返回 False。

示例1

<?php
   // set up array of points for a polygon
   $values = array(
      40, 50, // Point 1 (x, y)
      20, 240, // Point 2 (x, y)
      60, 60, // Point 3 (x, y)
      240, 20, // Point 4 (x, y)
      50, 40, // Point 5 (x, y)
      10, 10 // Point 6 (x, y)
   );
   // create the image using imagecreatetruecolor function
   $img = imagecreatetruecolor(700, 350);

   // allocated the blue and gray colors
   $bg = imagecolorallocate($img, 122, 122, 122);
   $blue = imagecolorallocate($img, 0, 0, 255);

   // filled the background
   imagefilledrectangle($img, 0, 0, 350, 350, $bg);

   // draw a polygon
   imagefilledpolygon($img, $values, 6, $blue);

   // flush image
   header('Content-type: image/png');
   imagepng($img);
   imagedestroy($img);
?>
登录后复制

输出

如何使用PHP中的imagefilledpolygon()函数绘制填充的多边形?

示例 2

<?php
   // Set the vertices of the 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 creates the size of the image or blank image.
   $img = imagecreatetruecolor(700, 350);

   // Set the gray background image color
   $bg = imagecolorallocate($img, 122, 122, 122);

   // Set the red image color
   $red = imagecolorallocate($img, 255, 0, 0);

   // fill the background
   imagefilledrectangle($img, 0, 0, 350, 350, $bg);

   // Draw the polygon image
   imagefilledpolygon($img, $values, 5, $red);

   // Output of the image.
   header('Content-type: image/png');
   imagepng($img);
   imagedestroy($img);
?>
登录后复制

输出

如何使用PHP中的imagefilledpolygon()函数绘制填充的多边形?

以上就是如何使用PHP中的imagefilledpolygon()函数绘制填充的多边形?的详细内容,更多请关注php中文网其它相关文章!

相关标签:
PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:tutorialspoint网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号