如何使用PHP中的imagefilledpolygon()函数绘制填充的多边形?
Sep 14, 2023 pm 05:45 PM
php
绘制
imagefilledpolygon()
imagefilledpolygon() 是一个内置 PHP 函数,用于绘制填充多边形。
语法
bool imagefilledpolygon($image, $points, $num_points, $color)
登录后复制
参数
imagefilledpolygon()采用四个不同的参数 - $image、$points、$ num_points 和 $颜色。
$图像 - 使用 imagecreatetruecolor() 函数创建给定尺寸的空白图像。
$points - 保存多边形的连续顶点。
$num_points - 包含多边形中的顶点总数。点/顶点的总数必须至少为三个才能创建多边形。
$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); ?>
登录后复制
输出
示例 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中文网其他相关文章!
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热门文章
击败分裂小说需要多长时间?
3 周前
By DDD
仓库:如何复兴队友
3 周前
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.能量晶体解释及其做什么(黄色晶体)
1 周前
By 尊渡假赌尊渡假赌尊渡假赌
公众号网页更新缓存难题:如何避免版本更新后旧缓存影响用户体验?
3 周前
By 王林

热门文章
击败分裂小说需要多长时间?
3 周前
By DDD
仓库:如何复兴队友
3 周前
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.能量晶体解释及其做什么(黄色晶体)
1 周前
By 尊渡假赌尊渡假赌尊渡假赌
公众号网页更新缓存难题:如何避免版本更新后旧缓存影响用户体验?
3 周前
By 王林

热门文章标签

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

适用于 Ubuntu 和 Debian 的 PHP 8.4 安装和升级指南

如何设置 Visual Studio Code (VS Code) 进行 PHP 开发
