GD库常用函数

创建句柄

  • imagecreate($width, $height)                                                  //新建图像
  • imagecreatefromjpeg($path)                                               //打开已有的图像

  • imagecreatefromgif($path)

  • imagecreatefrompng($path)

getimagesize($path)                        //获取图像信息

imagecopyresampled($newImage, $image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);// 创建缩略图

imagearc($image, $cx, $cy, $width, $height, $start, $end, $color) //创建圆

imagestring($image, $font, $x, $y, $string, $color)        //水平绘制字符串

imagestringup($image, $font, $x, $y, $string, $color)      //垂直绘制字符串

$color= imagecolorallocate($image, $red, $green, $blue)     //设置图像颜色

imagefilledrectangle($image, 0, 0, 100, 100, $white);       //矩形填充

header("Content-type: image/png");

imagepng($image);                        //输出png图像(jpeg/gif)

imagedestroy($image)                       //关闭句柄

imagecopymerge($dst, $src, 10, 10, 0, 0, $src_w, $src_h, 50);   //图片叠加

用法:创建验证码,图片添加水印,创建缩略图等

原文地址:https://www.cnblogs.com/docter/p/5984058.html