PHP图像处理
    画图
        验证码,统计图

安装GD库-----LAMP
            安装后在D:\APMServ5.2.6\PHP\ext文件中有php_gd2.dll文件
            在php.ini中extension=php_gd2.dll
        (1)创建画布---创建资源类型---高度  宽度
            resource imagecreate ( int $x_size , int $y_size )新建一个基于调色板的图像
            resource imagecreatetruecolor ( int $width , int $height ) 新建一个真彩色图像
        (2)绘制图像
            制定各种颜色
            imagecolorallocate();为一幅图像分配颜色
            (使用imagecolorallocate()要使用imagecreate()创建图像)

imagefill()区域填充
            矩形,圆,点,线段,扇形,画字(字符,字符串,freeType)
            每一个图像对应一个函数
            imagefilledrectangle()画一矩形并填充
            imagerectangle()画一个矩形
            imageline()画一条线段
            imagesetpixel()画一个单一像素
            imageellipse() 画一个椭圆

    imagefilledellipse() 画一椭圆并填充

<?php
    //1.创建图片资源
    $img=imagecreatetruecolor(200,200);

//    $img=imagecreate(200,200);

    $red=imagecolorallocate($img, 255, 0, 0);
    $yellow=imagecolorallocate($img,255,255,0);
    $green=imagecolorallocate($img,0,255,0);
    $blue=imagecolorallocate($img,0,0,255);
    $white=imagecolorallocate($img,255,255,255);
    //区域填充
    imagefill($img,0,0,$white);

    //2.画各种图像
    //画一矩形并填充
    imagefilledrectangle($img, 10, 10, 50, 30, $blue);
    //画一个矩形
    imagerectangle($img,100,100,190,80,$green);

    //画一条线段
    imageline($img,0,0,200,200,$red);
    //画点
    imagesetpixel($img,200,90,$yellow);
    //画一个椭圆
    imageellipse($img,100,100,100,100,$green);
    //画一个椭圆并填充
    imagefilledellipse($img,100,100,10,10,$red);
    //3.输出或保存图像
    header("Content-Type:image/gif");
    imagegif($img);

    //4.释放资源
    imagedestroy($img);

?>

imagefilledarc()画一椭圆弧且填充

<?php
    //1.创建图片资源
    $img=imagecreatetruecolor(200,200);

    $white=imagecolorallocate($img,255,255,255);  //白
    $gray=imagecolorallocate($img,0xc0,0xc0,0xc0); //灰
    $darkgray=imagecolorallocate($img,0x90,0x90,0x90);  //淡灰
    $navy=imagecolorallocate($img,0,0,0x80);    //
    $darknavy=imagecolorallocate($img,0,0,0x50);
    $red=imagecolorallocate($img,255,0,0);     //红
    $darkred=imagecolorallocate($img,0x90,0,0);  //淡红

    //背景设为白色
    imagefill($img, 0, 0, $white);

    //2.制作3D的效果
    for($i=60;$i>50;$i--){
        //imagefilledarc() 画一椭圆弧且填充
        imagefilledarc($img,50,$i,100,50,-160,40,$darknavy,ING_ARC_PIE);
        imagefilledarc($img,50,$i,100,50,40,75,$darkgray,ING_ARC_PIE);
        imagefilledarc($img,50,$i,100,50,75,200,$darkred,ING_ARC_PIE);
    }
    imagefilledarc($img,50,$i,100,50,-160,40,$navy,ING_ARC_PIE);
    imagefilledarc($img,50,$i,100,50,40,75,$gray,ING_ARC_PIE);
    imagefilledarc($img,50,$i,100,50,75,200,$red,ING_ARC_PIE);
    //3.输出或保存图像
    header("Content-Type:image/gif");
    imagegif($img);

    //4.释放资源
    imagedestroy($img);

?>

    imagechar() 水平地画一个字符
            imagefttext()使用 FreeType 2 字体将文本写入图像

<?php
    //创建图片资源
    $img=imagecreatetruecolor(200,200);

    $white=imagecolorallocate($img,255,255,255);
    $gray=imagecolorallocate($img,0xc0,0xc0,0xc0);
    $darkgray=imagecolorallocate($img,0x90,0x90,0x90);
    $navy=imagecolorallocate($img,0,0,0x80);
    $darknavy=imagecolorallocate($img,0,0,0x50);
    $red=imagecolorallocate($img,255,0,0);
    $darkred=imagecolorallocate($img,0x90,0,0);

    //背景设为白色
    imagefill($img, 0, 0, $gray);
    //水平画字符
    imagechar($img,5,100,100,"A",$red);
    imagechar($img,5,120,120,"B",$red);
    //垂直画字符
    imagecharup($img,5,60,60,"C",$red);
    imagecharup($img,5,80,80,"D",$red);
    //画字符串
    imagestring($img, 3, 10, 10, "hello", $navy);
    imagestringup($img,3,150,150,"hello",$navy);

    //imagefttext()使用 FreeType 2 字体将文本写入图像
    imagettftext($img, 25, 60, 160, 160, $red, "simkai.ttf", "你好");
    //输出或保存图像
    header("Content-Type:image/gif");
    imagegif($img);

    //释放资源
    imagedestroy($img);

?>

(3)输出图像/保存处理好的图像
            输出各种类型(gif,png,jpeg)
            imagegif();
            imagejpeg();
            imagepng();
        (4)释放资源
            imagedestroy();

PHP图像处理之画图的更多相关文章

  1. Java -- AWT 画图,图像处理

    1. AWT画图  Graphics类  提供绘制简单图形的方法 更新图片时用到 repaint , update , 程序不应该主动调用paint和update, 这两个方法都应该是由AWT系统负责 ...

  2. ASP.NET 画图与图像处理-生成高质量缩略图

    http://www.cftea.com/c/2007/08/SG9WFLZJD62Z2D0O.asp

  3. ASP.NET 画图与图像处理-如何直接输出到页面

    有时候我们生成的图片并不需要保存到磁盘中,而是直接输出到页面,比如验证码.实时报表等,如何做呢?请参考如下:     protected void Page_Load(object sender, E ...

  4. opencv6.3-imgproc图像处理模块之边缘检测

    接opencv6.2-improc图像处理模块之图像尺寸上的操作 本文大部分都是来自于转http://www.opencv.org.cn/opencvdoc/2.3.2/html/doc/tutori ...

  5. 黄聪:C#图像处理(各种旋转、改变大小、柔化、锐化、雾化、底片、浮雕、黑白、滤镜效果) (转)

    一.各种旋转.改变大小 注意:先要添加画图相关的using引用. //向右旋转图像90°代码如下:private void Form1_Paint(object sender, System.Wind ...

  6. C# (GDI+相关) 图像处理(各种旋转、改变大小、柔化、锐化、雾化、底片、浮雕、黑白、滤镜效果) (转)

    C#图像处理   (各种旋转.改变大小.柔化.锐化.雾化.底片.浮雕.黑白.滤镜效果)     一.各种旋转.改变大小   注意:先要添加画图相关的using引用.   //向右旋转图像90°代码如下 ...

  7. MATLAB图像处理工具箱

    下列表格中除了个别函数外,其余函数都是图像处理工具箱提供的关于图像处理的函数,现摘录到此以备查找. 表1 图像显示 函数名 功能说明 函数名 功能说明 colorbar 颜色条显示 montage 按 ...

  8. windows“画图”工具用法

    图片编辑工具不少,photoshop功能强大,但是并不是那么容易掌握.而且,倘若一个简单的图片处理问题就使用这么强大的工具,有点“杀鸡焉用牛刀”的意思,要知道只打开photoshop就需要一段等待时间 ...

  9. matlab图像处理

    matlab图像处理 转自:http://www.cnblogs.com/lovebay/p/5094146.html 1. 图像和图像数据 缺省情况下,MATLAB将图像中的数据存储为双精度类型(d ...

随机推荐

  1. uva----(100)The 3n + 1 problem

     The 3n + 1 problem  Background Problems in Computer Science are often classified as belonging to a ...

  2. hdu-----(1507)Uncle Tom's Inherited Land*(二分匹配)

    Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  3. uva----(10794) A Different Task

      A Different Task  The (Three peg) Tower of Hanoi problem is a popular one in computer science. Bri ...

  4. SQL Sever 2008 安装

    http://jingyan.baidu.com/article/4b07be3c1daf1248b380f33b.html 大致出错信息如下:RebootRequiredCheck 检查是否需要挂起 ...

  5. 84. Largest Rectangle in Histogram *HARD* -- 求柱状图中的最大矩形面积

    Given n non-negative integers representing the histogram's bar height where the width of each bar is ...

  6. log4j配置文件的详解

    1.配置根Logger,其语法为: log4j.rootLogger = [ level ] , appenderName, appenderName, … 其中,level 是日志记录的优先级,分为 ...

  7. extjs 控件属性

    1.textfield labelSeparator :''   这个属性当fieldLabel有值得时候,默认会加上一个分号,这个属性就是控制那个的... 2.numberfield decimal ...

  8. 上国际网络——通过配置host

    http://laod.cn/hosts/2016-google-hosts.html

  9. C#图书资源【更新中...】喜欢的就转存吧

    百度分享暂时取消了,需要的朋友可以直接关注我,我发给你. 重点篇 1.C#与.NET3.5高级程序设计 2.C#与.NET3.5高级程序设计.rar 3.Effective_C#_中文版_改善C#程序 ...

  10. 让你的WPF程序使用多线程——BackgroundWorker

    在wpf中可以使用许多方法执行异步操作.利用.NET的芳芳就是手动创建一个新的System.Threading.Thread对象,提供一步代码,并使用THread.Start()方法加载代码.这种方法 ...