thinkphp图片压缩-composer-Intervention-Image-ImageManagerStatic

先抛出composer插件

composer require intervention/image
use InterventionImageImageManagerStatic as Image;
public function youhua()
    {
        $hostdir=ROOT_PATH . 'public' . DS .'yh'; //要读取的文件夹
        $filesnames = scandir($hostdir); 
        foreach ($filesnames as $name) {
            if($name=='.'||$name=='..'){
                continue;
            }else{
                $aurl= ROOT_PATH . 'public' . DS .'yh'  . DS . $name;
                $img = Image::make($aurl);//打开的路径
                $img->resize(200, 266);//定制宽高
                $img->save($aurl);//保存
                echo $aurl . "<br/>"; //输出
            }
        }
    }

我这段代码实现的是在原来的基础上直接覆盖,相当于无痕压缩。

有输出另外需求的可以改变save路径

附上官方文档:http://image.intervention.io/api/save

原文地址:https://www.cnblogs.com/chenliuxiao/p/12614494.html