ps202
(Pallaszilveszter)
May 17, 2015, 5:08pm
1
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
ps202
(Pallaszilveszter)
May 17, 2015, 5:38pm
3
Hi!
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.
madand
(Dev Madand)
May 17, 2015, 9:07pm
5
ps202:
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?
In your case, you need to call the underlying Imagine’s method, since yii2-imagine is just a wrapper for that library:
Image::getImagine()
->open($originalFilePath))
->thumbnail(new Box(100, 100))
->save($thumbFilePath);
$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);
ps202
(Pallaszilveszter)
May 18, 2015, 9:10pm
7
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!
ps202:
I did this:
…
does it save picture with aspect ratio? you determine both w&h together for new picture!
ps202
(Pallaszilveszter)
May 19, 2015, 5:48pm
9
Yes, it saves the picture with maintaining the original aspect ratio.