open(Yii::getAlias($imageAlias)); $size = $img->getSize(); $ratio = $size->getWidth()/$size->getHeight(); $height = $h; $width = round($height * $ratio); $imagine = new Imagine(); $imagine->open($imageAlias) ->resize(new Box($width, $h)) ->save($imageAlias, array('flatten' => false)); Image::crop($imageAlias, $w, $h,[($width/2)-($w/2),0]) ->save(Yii::getAlias($imageAliasSave), ['quality' => 100]); } }