Resize an Image height propotionnaly to a given width


I want to resize all images that I receive from the user to 200px of width; Is there any function that can help me if I give the width and resize the height proportionnaly to the given width?

All portrait or landscape image will be resize but if the image width is less than 200px I will not resize it;

height = (height/width)*200;

That’s great!!! and how can I get the width of the image? The image is store in $model->photo attribute which is of type file; I wanna user yii\imagine\Image;


you may use getimagesize(‘path to image’) function and the return array will give you all the values you require.