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();

最新文章

  1. 1.0 多控制器管理(附:Demo)
  2. js:数据结构笔记11--排序算法(1)
  3. Quartz的配置文件quartz.properties详解
  4. HDU 1077Catching Fish(简单计算几何)
  5. WordPress搬家全攻略
  6. Java bit、byte、位、字节、汉字、字符
  7. 《FPGA零基础入门到精通视频教程》-第001b讲软件的破解
  8. Mac与Window之间的共享文件
  9. Java DB 访问之(四) spring mvc 组合mybatis
  10. mac charles抓安卓(小米)http包
  11. 【java.sql.SQLException: Before start of result set】
  12. linux 安装oracle
  13. solr集群构建的基本流程介绍
  14. php-isset和empty
  15. [转]Linux 系统挂载数据盘
  16. 【转】五分钟读懂大数据核心MapReduce架构及原理
  17. cecium 笔记
  18. 5308: [Zjoi2018]胖
  19. 2017 Tag Cloud
  20. hdu 3081

热门文章

  1. [maven] 搭建多模块企业级项目
  2. (12)odoo各种提前期和时间
  3. ztree edit_super
  4. Android基础之项目结构分析
  5. Octopus系列之如何让前台的js脚本变得灵活重用
  6. linux系统设置静态IP 查看网卡配置文件
  7. linux-网卡故障
  8. POJ 2159 Ancient Cipher 难度:0
  9. POJ 3009 Curling 2.0 回溯,dfs 难度:0
  10. 牛场围栏(vijos 1054)