源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

php使用gd2绘制基本图形示例(直线、圆、正方形)

  • 时间:2022-08-17 11:44 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:php使用gd2绘制基本图形示例(直线、圆、正方形)
本文实例讲述了php使用gd2绘制基本图形。分享给大家供大家参考,具体如下: 应用GD2函数可以绘制的图形有多种,最基本的图形包括条、圆、方形等。无论开发人员绘制多么复杂的图形,都是在这些最基本的图形的基础上进行深化的,只有掌握了最基本的图形的绘制方法,才能绘制出各种具有独特风格的图形。 在GD2中可以分别应用imageline()函数、imagearc()函数和imagerectangle()函数绘制直线,圆形和方法。 下面将介绍这些函数的使用方法: [code]bool imageline( resource image, int x1, int y1, int x2, int y2, int color )[/code] imageline()函数用color颜色在图像image中从坐标(x1,y1)到(x2,y2)(图像左上角为(0,0))绘制一条线段。 [code]bool imagearc( resource image, int cx, int cy, int w, int h, int s, int e, int color)[/code] image : 表示图像的handle cx,cy 原点坐标(0,0)为图片的左上角,参数cx,cy为椭圆圆心坐标 w,h分别为水平轴长和垂直轴长 s,e分别为起始角与结束角 color为弧线的颜色 [code]bool imagerectangle( resource image, int x1, int y1, int x2, int y2, int color)[/code] imagerectangle()函数以color颜色在image图像中绘制一个矩形,其左上角坐标为( x1,y1),右下角坐标为( x2, y2)。图像的左上角坐标为(0,0) 例如应用以上函数,分别绘制直线、正圆和正方形,并且以白色作为线条的基色,代码如下
<?php
  header("Content-type: image/png");//将图像输出到浏览器
  $img = imagecreate(560, 200);//创建一个560X200像素的图像
  $bg = imagecolorallocate($img, 0, 0, 255);//设置图像的背景颜色
  $white = imagecolorallocate($img, 255, 255, 255);//设置绘制图像的线的颜色
  imageline($img, 20, 20, 150, 180, $white);//绘制一条线
  imagearc($img, 250, 100, 150, 150, 0, 360, $white);//绘制一个圆
  imagerectangle($img, 350, 20, 500, 170, $white);//绘制一个正方形
  imagepng($img);//以PNG格式输出图像
  imagedestroy($img);//释放资源

运行结果如下: [img]http://files.jb51.net/file_images/article/201702/2017215121657036.jpg?2017115122033[/img] 更多关于PHP相关内容感兴趣的读者可查看本站专题:《[url=http://www.1sucai.cn/Special/455.htm]PHP图形与图片操作技巧汇总[/url]》、《[url=http://www.1sucai.cn/Special/348.htm]PHP基本语法入门教程[/url]》、《[url=http://www.1sucai.cn/Special/43.htm]php面向对象程序设计入门教程[/url]》、《[url=http://www.1sucai.cn/Special/495.htm]PHP网络编程技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/623.htm]PHP数组(Array)操作技巧大全[/url]》、《[url=http://www.1sucai.cn/Special/47.htm]php字符串(string)用法总结[/url]》、《[url=http://www.1sucai.cn/Special/84.htm]php+mysql数据库操作入门教程[/url]》及《[url=http://www.1sucai.cn/Special/231.htm]php常见数据库操作技巧汇总[/url]》 希望本文所述对大家PHP程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部