先抛出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

相关文章:

  • 2021-09-03
  • 2022-01-15
  • 2022-12-23
  • 2021-11-23
  • 2022-12-23
  • 2021-07-20
  • 2021-12-01
  • 2021-10-18
猜你喜欢
  • 2021-06-28
  • 2021-11-22
  • 2022-12-23
  • 2022-12-23
  • 2021-08-12
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案