如何通过yii2中的想象扩展来调整图像大小

前端之家收集整理的这篇文章主要介绍了如何通过yii2中的想象扩展来调整图像大小前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用波纹管功能上传后调整图像大小以显示在我的帖子上.
但它适用于大于500px 300px的图像.当我上传小于这个尺寸的图片时,我的网站图片行会中断.
use yii\imagine\Image;    
public function upload() {
            $this->pictureFile->saveAs('../files/upload/' . $this->pictureFile->baseName . '.' . $this->pictureFile->extension);

            Image::thumbnail('../files/upload/' . $this->pictureFile,500,300)
                    ->save('../files/upload/thumbnail-500x300/' . $this->pictureFile->baseName . '.' . $this->pictureFile->extension,['quality' => 70]);
            unlink('../files/upload/' . $this->pictureFile->baseName . '.'  . $this->pictureFile->extension);
        }
使用如下调整大小的方法
use yii\imagine\Image;  
 use Imagine\Image\Box;  

 public function upload() {
        $this->pictureFile->saveAs('../files/upload/' . $this->pictureFile->baseName . '.' . $this->pictureFile->extension);

        Image::thumbnail('../files/upload/' . $this->pictureFile,300)
                ->resize(new Box(500,300))
                ->save('../files/upload/thumbnail-500x300/' . $this->pictureFile->baseName . '.' . $this->pictureFile->extension,['quality' => 70]);
        unlink('../files/upload/' . $this->pictureFile->baseName . '.'  . $this->pictureFile->extension);
    }
原文链接:https://www.f2er.com/php/240101.html

猜你在找的PHP相关文章