首页 > 其他 > 详细

使用gd2绘制基本图形

时间:2016-08-03 20:29:32      阅读:191      评论:0      收藏:0      [点我收藏+]
        应用GD2函数可以绘制的图形有多种,最基本的图形包括条、圆、方形等。无论开发人员绘制多么复杂的图形,都是在这些最基本的图形的基础上进行深化的,只有掌握了最基本的图形的绘制方法,才能绘制出各种具有独特风格的图形。
        在GD2中可以分别应用imageline()函数、imagearc()函数和imagerectangle()函数绘制直线,圆形和方法。
        下面将介绍这些函数的使用方法:
        bool imageline( resource image, int x1, int y1, int x2, int y2, int color )
        imageline()函数用color颜色在图像image中从坐标(x1,y1)到(x2,y2)(图像左上角为(0,0))绘制一条线段。

        bool imagearc( resource image, int cx, int cy, int w, int h, int s, int e, int color)
        image : 表示图像的handle 
        cx,cy 原点坐标(0,0)为图片的左上角,参数cx,cy为椭圆圆心坐标
        w,h分别为水平轴长和垂直轴长
        s,e分别为起始角与结束角
        color为弧线的颜色
        
        bool imagerectangle( resource image, int x1, int y1, int x2, int y2, int color)
        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);//释放资源

运行结果如下:
技术分享






使用gd2绘制基本图形

原文:http://blog.csdn.net/qq_28602957/article/details/52106525

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!