thinkphp5图片处理

发布时间:2021-11-05 23:35:21 阅读:1129次

我们经常需要对上传的图片进行缩略处理

因为大图片访问起来很占带宽

我们可以通过安装包composer require topthink/think-image

<?php
1 use thinkImage;

15 class Upload extends Common
16 {
17
18 public function index(){
19
20
21 $file = request()->file('file'); //获取到上传的文件
22 $file_size = $file->getSize()/1000;
23 if($file_size > 3000){
24 return $this->error('最大只能上传3M的文件');
25 }
26 //大于1M小于3M缩略处理
27 if($file_size > 1000){
28 $image = \think\Image::open($file->getPathname());
29 $width = $image->width();
30 //echo $width;
31 $height = $image->height();
32 if($width > 700){
33 $image->thumb($width*0.8, $height*0.8)->save($file->getPathname());
34 }
35 }

如有问题,可以QQ搜索群1028468525加入群聊,欢迎一起研究技术

支付宝 微信

有疑问联系站长,请联系QQ:QQ咨询

转载请注明:thinkphp5图片处理 出自老鄢博客 | 欢迎分享