Actually, the task is to resize the image to an explicitly specified width using the yiisoft / yii2-imagine extension in Yii2, but the height should be calculated proportionally to the difference on which the width is reduced.

    1 answer 1

    $img = Image::getImagine()->open('path to file ...'); $size = $img->getSize(); $ratio = $size->getWidth()/$size->getHeight(); $height = round($width/$ratio); $box = new Box($width, $height); $img->resize($box)->save($filePath.'/thumb/' . $fileName); //Или Image::thumbnail($fullName,$width,$height)->save($filePath.'/thumb/' . $fileName); 

    A source