PHP扩展使用-GD

一、相关函数

  1. 获取信息

  gd_info()  #查看当前系统环境gd库支持的图片格式

  getimagesize(imagefile)  #获取图像大小,非GD库函数

  imagex(imagefile)  #获取原图宽

  imagey(imagefile)  #获取原图高

  2. 创建图像资源

  imagecreatefrompng("images/button1.png");  #以png图片创建图像资源(画布)

  imagecreatetruecolor(width,height)  #创建指定大小的无色(显示为黑)图像资源(画布)

  3. 绘制内容

  imagecolorallocate($image,255,255,255)  #创建指定图像资源允许的颜色(画笔)

  imagefill($image,x,y,$color)  #给指定画布填充设定的颜色

  imagestring($image,int,x,y,string,$color)  #给指定画布绘制字符串

  imagettftext($image,size,角度,x,y,$color,font,string)  #给指定画布绘制指定字体的字符串

  imageline($image,x,y,x,y,$color)  #给指定画布绘制直线

  imagerectangle($image,x,y,x,y,$color)  #给指定画布绘制矩形

  imagefilledrectangle($image,x,y,x,y,$color)  #给指定画布绘制填充矩形

  imagellipse($image,x,y,width,height,$color)  #给指定画布绘制椭圆

  imagearc($image,center-x,center-y,width,height,start,ent,$color)  #绘制弧形

  imagefilledarc($image,center-x,center-y,width,height,start,ent,$color[,IMG_ARC_PIE])  #绘制填充弧形

  imagecopy($dis_img,$src_img,$dis_x,$dis_y,$src_x,$src_y,$src_w,$src_h)  #将一个图像资源复制到另一个上

  imagecopyresampled(dis_img,$src_img,$dis_x,$dis_y,$src_x,$src_y,$dis_w,$dis_h,$src_w,$src_h)

  4. 响应输出

  imagepng($image[,filename])  #将指定图像资源以png格式输出到浏览器,注意设置响应头。或写到文件

  imagejpeg()

  5. 销毁资源

  imagedestroy($image)  #销毁图像资源

  

二、简介

  1.功能:是被PHP用来创建和处理图片的扩展,能支持jpeg,png,gif,webp,xbp,xpm,bmp 图片格式

  2.创建的资源类型:图像资源imagecreatefrompng()  字体资源imageloadfont() 

  3.应用场景:验证码,图表,图像压缩

三、安装

  1.下载地址:https://github.com/libgd/libgd/releases

  2. 安装

  linux : 在编译安装时要加上 --with-gd[=dir]选项,将gd库编译进php(静态编译)或用phpize生成动态链接库引入(动态编译)

  windows : 在php.ini中引入php_gd.dll扩展

四、应用

  1. 图片压缩(用户上传文件过大,等比压缩后上传)

  

  

posted on 2019-11-26 16:41  反射弧  阅读(1504)  评论(0编辑  收藏  举报

导航