Thinkphp Image类图像处理用法

   上传图片后,我们要对图片进行处理,使用Think\Image类进行图像处理功能,支持Gd库和Imagick库,包括对GIf图像处理的支持

1,实例化,打开一张图片

  $image = new \Think\Image(); 
  $image->open('./product.jpg');

2,获取图像信息

$image = new \Think\Image(); 
$image->open('./1.jpg');
$width = $image->width(); // 返回图片的宽度
$height = $image->height(); // 返回图片的高度
$type = $image->type(); // 返回图片的类型
$mime = $image->mime(); // 返回图片的mime类型
$size = $image->size(); // 返回图片的尺寸数组 0 图片宽度 1 图片高度

3,生成缩略图

$image = new \Think\Image(); 
$image->open('./1.jpg');
// 按照原图的比例生成一个最大为150*150的缩略图并保存为thumb.jpg
$image->thumb(150, 150)->save('./thumb.jpg');

注意 采用固定大小的缩略图可能会有所变形,生成的缩略图效果

文章来自 www.huthon.com

猜你喜欢

转载自blog.csdn.net/gzxiaomei/article/details/82947163