yii2image-resizingphp-imagine

yii2 resize images maintaining aspect ratio with Imagine


I got this code in yii2:

Image::thumbnail($path, 100, 100)->save($thumbnail, ['quality' => 50]);

I thought that it will resize the original image maintaining the aspect ratio. But it just creates a box... What can be wrong?


Solution

  • You may use like that:

    use Imagine\Image\Box;
    
    Image::frame($path)
    ->thumbnail(new Box(100, 100))
    ->save($thumbnail, ['quality' => 50]);