zxbodya / yii2-gallery-manager

93 stars 61 forks source link

How to create squared version of image? #58

Closed kwazaro closed 6 years ago

kwazaro commented 6 years ago

Hello! Could you help me, please, to create squared version of uploaded image? It's hard to find examples for Imagine in Yii2, and I really don't get how it works in this behavior. I need squared version of images, let's say 640x640 px, even if images has different aspect ratio (image should be centered, downscaled and filled with white background). If I try this:

'versions' => [
    'squared' => function ($img) {
        return $img->copy()->thumbnail(new \Imagine\Image\Box(640, 640));
    },
]

it just creates image with max side of 640. What manipulations should I do to achieve the goal?

bscheshirwork commented 6 years ago

See https://imagine.readthedocs.io/en/master/usage/introduction.html