yii2 + imagine resize

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 shaped image, with width=height=100… What can be wrong?

i think you must resize the pic with maintain aspect ratio, for this you must use widen with imagine


Thanks for your answer!

How can I do that?

The Yii Imagine extension has only these methods: crop, frame, getImagine, setImagine, text, thumbnail, watermark.

An in the documentation here, they say the thumbnail method should maintain the original aspect ratio.


In your case, you need to call the underlying Imagine’s method, since yii2-imagine is just a wrapper for that library:



	->thumbnail(new Box(100, 100))


$imagineObj = new Imagine();

$imageObj = $imagineObj->open(\Yii::$app->basePath . '/../assets/images/' . $filename);

$imageObj->resize($imageObj->getSize()->widen(400))->save(\Yii::$app->basePath . '/../assets/images/' . $filename);

I did this:

use Imagine\Gd;

use Imagine\Image\Box;

use Imagine\Image\BoxInterface;


$photo = $imagine->open($path);

$photo->thumbnail(new Box(1200, 1200))->save($path, ['quality' => 90]);

Thank you for the quick responses!

does it save picture with aspect ratio? you determine both w&h together for new picture!

Yes, it saves the picture with maintaining the original aspect ratio.