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


先抛出composer插件

composer require intervention/image
use Intervention\Image\ImageManagerStatic 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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM