您现在的位置是: 首页 >  ThinkPHP8 ThinkPHP8

thinkphp5/thinkphp6图片处理

冬寂 2022-04-12 22:53:10 【ThinkPHP8】 4594人已围观

安装图片处理类库

composer require topthink/think-image

打开图片

$image = \think\Image::open('./image.png');
$image = \think\Image::open(request()->file('image'));

获取图像信息

 $image = \think\Image::open(ROOT_PATH.'public/static/image/image.png'); // 返回图片的宽度 $width = $image->width(); // 返回图片的高度 $height = $image->height(); // 返回图片的类型 $type = $image->type(); // 返回图片的mime类型 $mime = $image->mime(); // 返回图片的尺寸数组 0 图片宽度 1 图片高度 $size = $image->size();

裁剪图片

$image = \think\Image::open(ROOT_PATH.'public/static/image/image.png');$image->crop(300, 300)->save(ROOT_PATH.'public/static/image/crop.png');

缩略图

$image = \think\Image::open(ROOT_PATH.'public/static/image/image.png');$image->thumb(150, 150)->save(ROOT_PATH.'public/static/image/thumb.png');

添加水印

$image = \think\Image::open(ROOT_PATH.'public/static/image/image.png');$image->water(ROOT_PATH.'public/static/image/logo.png',\think\Image::WATER_SOUTHEAST)->save(ROOT_PATH.'public/static/image/water_image.png');

添加文本水印(字体文件ttf需要准备)

$image = \think\Image::open(ROOT_PATH.'public/static/image/image.png');$image->text('This is text water',ROOT_PATH.'public/static/font/Apple Symbols.ttf',50,'#000000')->save(ROOT_PATH.'public/static/image/text_image.png');



很赞哦! ( 5 )

站点信息

  • 建站时间:2020-08-10
  • 文章统计100篇文章
  • 标签管理标签云
  • 统计数据百度统计
  • 微信公众号:扫描二维码,关注我