一、GD库的简介
验证码
水印(文字、图片)
动态图表
图片的剪切和缩减
作用:动态图片处理
二、GD库的应用
安装:1、phpinfo.php
<?php
phpinfo();
phpinfo()
系统函数:输出PHP的配置信息
2、打开php.ini配置文件
去掉:extension=php_gd2.dll
前面的分号
3、查找: extension_dir
将目录改为:php.ini所在目录的
子目录 ext目录的地址
例如:
E:/PSD1604/php5.4
E:/PSD1604/php5.4/ext
把目录分隔符改为正向分隔符
保存文件
4、重新启动web 服务器(apache)
5、确认是否安装成功
三、GD库的应用
1、画布(纸)
imagecreatetruecolor(int width,int height)
功能:创建画布
参数:
width 画布的宽
height 画布的高
返回:GD资源
2、画
画笔(颜色)
imagecolorallocate(resource img,int red,int green,int blue)
功能:创建颜色
参数:
img 创建的资源
red:颜色值(0~255)
green: 颜色值(0~255)
blue:颜色值(0~255)
返回:创建的颜色
画画
imagefill(resource img,int x,int y,int $color)
功能:填充画布背景色
参数:
img 创建的资源
x 画布上的x轴坐标
y 画布上的y轴坐标
color 填充的颜色
返回 成功 true
失败 false
点 线 面
imagesetpixel(resource img,int x,int y,int color)
功能:画点
参数:
img 申请的资源
x 画布的x轴坐标
y 画布的y轴坐标
color 画的点的颜色
imageline(resource img,int x_1,int y_1,
int x_2,int y_2,int color)
功能:画线
参数:
img 申请的资源
x_1,y_1 启示点的x轴和y轴坐标
x_2,y_2 终止点的x轴和y轴坐标
color 线的颜色
imagerectangle(resource img,
int x_1,int y_1,
int x_2,int y_2,
int color)
功能:画一个矩形边框
参数:
img 申请的图片资源
x_1,y_1 矩形的启示点x轴和y轴坐标
x_2,y_2 矩形的终止点x轴和y轴坐标
color 矩形边框的颜色
imagefilledrectangle(resource img,
int x_1,int y_1,
int x_2,int y_2,
int color)
功能:画一个实心矩形
参数:
img 申请的图片资源
x_1,y_1 矩形的启示点x轴和y轴坐标
x_2,y_2 矩形的终止点x轴和y轴坐标
color 矩形的颜色
imageellipse(resource img,int x,int y,
int width,int height,
int color)
功能:画椭圆
参数:
img 申请的资源
x 圆心的x轴坐标
y 圆心的y轴坐标
width 圆的宽
height 圆的高
color 空心圆的边框颜色
imagefilledellipse(resource img,
int x,int y,
int width,int height,
int color)
功能:画实心圆
img 申请的资源
x 圆心的x轴坐标
y 圆心的y轴坐标
width 圆的宽
height 圆的高
color 圆的颜色
imagestring(resource img,int font,int
x,int y,string str,int color)
功能:在图片上输出文字
参数:
img 申请的资源
font 大小(1~5)其中5最大,1最小
x,y 文字的起始点坐标
str 书写的文字
color 文字的颜色
imagettftext(resource img,float fontsize,float angle,int x,int y,int color,
string filename,string str)
功能:输出一段文字
参数:
img 申请的资源
fontsize 文字大小
angle 角度
x,y 文字输出的起始点坐标
color 文字的颜色
filename 字体文件
C:\WINDOWS\Fonts
str 输出的文字
支持中文:文件要求UTF-8
TTF文件要求支持中文
3、展览/保存
展示(gif,jpg,png)
header("Content-Type:image/gif")
imagegif(resource img)
header("Content-Type:image/jpeg")
imagejpeg(resource img)
header("Content-Type:image/png")
imagepng(resource img)
4、收拾 (清理资源)
imagedestroy(resource img)
功能:释放资源占据的内存空间
参数:
img 申请的资源
返回 成功 true
失败 false
应用不同的图片最为背景
cat.jpg
imagecreatefrom图片文件的格式
imagecreatefromjpeg(string filename)
imagecreatefrompng(string filename)
imagecreatefromgif(string filename)
功能:
应用不同的图片作为背景,从不同的图片上获取资源
参数:
filename 文件名称
返回:资源
getimagesize(string filename)
功能:获取图片的信息
参数:
filename 获取信息的文件名称
返回:数组(文件信息)
[0]图片的宽,
[1]图片的高,
[2]图片的类型 (1=>gif,2=>jpeg,3=>png)
自定义函数
funciton 函数名(){
函数体
return 返回结果给调用者 90%
echo 输出结果 10%
}
r g b red(255,0,0)
green(0,255,0)
水印
imagefontwidth(int $font)
功能:获取系统指定font字体的大小,(1-5)
参数是字体大小
返回值:字体的高度
验证码
水印(文字、图片)
动态图表
图片的剪切和缩减
作用:动态图片处理
二、GD库的应用
安装:1、phpinfo.php
<?php
phpinfo();
phpinfo()
系统函数:输出PHP的配置信息
2、打开php.ini配置文件
去掉:extension=php_gd2.dll
前面的分号
3、查找: extension_dir
将目录改为:php.ini所在目录的
子目录 ext目录的地址
例如:
E:/PSD1604/php5.4
E:/PSD1604/php5.4/ext
把目录分隔符改为正向分隔符
保存文件
4、重新启动web 服务器(apache)
5、确认是否安装成功
三、GD库的应用
1、画布(纸)
imagecreatetruecolor(int width,int height)
功能:创建画布
参数:
width 画布的宽
height 画布的高
返回:GD资源
2、画
画笔(颜色)
imagecolorallocate(resource img,int red,int green,int blue)
功能:创建颜色
参数:
img 创建的资源
red:颜色值(0~255)
green: 颜色值(0~255)
blue:颜色值(0~255)
返回:创建的颜色
画画
imagefill(resource img,int x,int y,int $color)
功能:填充画布背景色
参数:
img 创建的资源
x 画布上的x轴坐标
y 画布上的y轴坐标
color 填充的颜色
返回 成功 true
失败 false
点 线 面
imagesetpixel(resource img,int x,int y,int color)
功能:画点
参数:
img 申请的资源
x 画布的x轴坐标
y 画布的y轴坐标
color 画的点的颜色
imageline(resource img,int x_1,int y_1,
int x_2,int y_2,int color)
功能:画线
参数:
img 申请的资源
x_1,y_1 启示点的x轴和y轴坐标
x_2,y_2 终止点的x轴和y轴坐标
color 线的颜色
imagerectangle(resource img,
int x_1,int y_1,
int x_2,int y_2,
int color)
功能:画一个矩形边框
参数:
img 申请的图片资源
x_1,y_1 矩形的启示点x轴和y轴坐标
x_2,y_2 矩形的终止点x轴和y轴坐标
color 矩形边框的颜色
imagefilledrectangle(resource img,
int x_1,int y_1,
int x_2,int y_2,
int color)
功能:画一个实心矩形
参数:
img 申请的图片资源
x_1,y_1 矩形的启示点x轴和y轴坐标
x_2,y_2 矩形的终止点x轴和y轴坐标
color 矩形的颜色
imageellipse(resource img,int x,int y,
int width,int height,
int color)
功能:画椭圆
参数:
img 申请的资源
x 圆心的x轴坐标
y 圆心的y轴坐标
width 圆的宽
height 圆的高
color 空心圆的边框颜色
imagefilledellipse(resource img,
int x,int y,
int width,int height,
int color)
功能:画实心圆
img 申请的资源
x 圆心的x轴坐标
y 圆心的y轴坐标
width 圆的宽
height 圆的高
color 圆的颜色
imagestring(resource img,int font,int
x,int y,string str,int color)
功能:在图片上输出文字
参数:
img 申请的资源
font 大小(1~5)其中5最大,1最小
x,y 文字的起始点坐标
str 书写的文字
color 文字的颜色
imagettftext(resource img,float fontsize,float angle,int x,int y,int color,
string filename,string str)
功能:输出一段文字
参数:
img 申请的资源
fontsize 文字大小
angle 角度
x,y 文字输出的起始点坐标
color 文字的颜色
filename 字体文件
C:\WINDOWS\Fonts
str 输出的文字
支持中文:文件要求UTF-8
TTF文件要求支持中文
3、展览/保存
展示(gif,jpg,png)
header("Content-Type:image/gif")
imagegif(resource img)
header("Content-Type:image/jpeg")
imagejpeg(resource img)
header("Content-Type:image/png")
imagepng(resource img)
4、收拾 (清理资源)
imagedestroy(resource img)
功能:释放资源占据的内存空间
参数:
img 申请的资源
返回 成功 true
失败 false
应用不同的图片最为背景
cat.jpg
imagecreatefrom图片文件的格式
imagecreatefromjpeg(string filename)
imagecreatefrompng(string filename)
imagecreatefromgif(string filename)
功能:
应用不同的图片作为背景,从不同的图片上获取资源
参数:
filename 文件名称
返回:资源
getimagesize(string filename)
功能:获取图片的信息
参数:
filename 获取信息的文件名称
返回:数组(文件信息)
[0]图片的宽,
[1]图片的高,
[2]图片的类型 (1=>gif,2=>jpeg,3=>png)
自定义函数
funciton 函数名(){
函数体
return 返回结果给调用者 90%
echo 输出结果 10%
}
r g b red(255,0,0)
green(0,255,0)
水印
imagefontwidth(int $font)
功能:获取系统指定font字体的大小,(1-5)
参数是字体大小
返回值:字体的高度