Answer the question
In order to leave comments, you need to log in
yii2 imagine. How to crop an image proportionally in width?
BaseImage::thumbnail($_FILES["attachment"]["tmp_name"]["file"],1000,0)->save($folder.$_FILES["attachment"]["name"]["file"]);
exception 'Imagine\Exception\InvalidArgumentException' with message 'Length of either side cannot be 0 or negative, current size is 1000x0'
Answer the question
In order to leave comments, you need to log in
$img = imagine\Image::getImagine()->open(Yii::getAlias($fullName));
$size = $img->getSize();
$ratio = $size->getWidth()/$size->getHeight();
$width = 200;
$height = round($width/$ratio);
$box = new Box($width, $height);
$img->resize($box)->save($filePath.'/thumb/' . $fileName);
// OR:
imagine\Image::thumbnail($fullName,$width,$height)
->save($filePath.'/thumb/' . $fileName);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question