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