时间:2014年4月8日15:01:12 GD库安装及画图流程


学习目标:

GD扩展库的引入

图片处理流程

图片处理的坐标体系

GD      库常用函数

GD库生成缩略图

GD库生成验证码

GD库给图片添加水印


GD扩展库的引入

php.ini中开启

extension=php_gd2.dll

重新启动Apache服务器

测试:使用gd_info()函数,

<?php


print_r(gd_info()); //返回一个数组,包含GD库的基本信息

/*

Array

(

    [GD Version] => bundled (2.0.34  compatible)  //GD库版本

   [FreeType Support] => 1    //是否支持FreeType字体

    [FreeType Linkage] => with freetype

    [T1Lib Support] => 1

    [GIF Read Support] => 1  //能否读取GIF图片

    [GIF Create Support] => 1 //能否写GIF图片

    [JPG Support] => 1       //是否支持JPG

    [PNG Support] => 1      //是否支持PNG

    [WBMP Support] => 1    //是否支持WBMP

    [XPM Support] =>

    [XBM Support] => 1

    [JIS-mapped Japanese Font Support] =>

)

*/

?>


GD库函数:

1 理解绘图的过程

2 理解屏幕的坐标体系;

GD库画图的流程:

1. 创建画布

2. 创建各种颜色

3. 画图如写字,画线,画矩形等

4. 保存成图片

5. 销毁画布

<?php

/*1. 创建画布宽和高*/

$width = 300;

$height = 200;

$image = imagecreatetruecolor($width,  $height);//返回值为资源对象

//print_r($image); //Resource id #2

/*2. 创建原料 imagecolorallocate(画布资源, ,绿,)*/

$blue = imagecolorallocate($image, 0, 0,  255);

/*3. 画图  imagefill(画布资源,起始X,起始Y,颜色值);*/

imagefill($image, 0, 0, $blue);

/*4. 保存  imagepng imagejpeg  imagegif*/

if (imagepng($image,'./1.png')) {

     echo  "图片生成成功";

}else{

     echo  "图片生成失败";

}

/*5. 销毁画布,释放资源*/

imagedestroy($image);

?>


你可能感兴趣的:(服务器,验证码,图片处理,流程图,学习目标)