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)  #给指定画布绘制全真字体

  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)  #将一个图像资源复制到另一个上

  4. 响应输出

  imagepng($image)  #将指定图像资源以png格式输出到浏览器,注意设置响应头

  imagejpeg()

  5. 销毁资源

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

  

二、简介

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

  创建的资源类型:

  图像资源  imagecreatefrompng()  函数创建 

  字体资源  imageloadfont()  函数创建

  

三、使用

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

  2. 安装

  linux : 在编译安装时要加上 --with-gd[=dir]  选项,将gd库编译进php

  windows : 在php.ini中引入php_gd.dll扩展。/php/ext/目录下

  

  

猜你喜欢

转载自www.cnblogs.com/fanshehu/p/11936641.html