A simple python function to downsize an image and calculate the new dimensions while keeping aspect ratio.

I needed this functionality for a web application. There are some variations found on the net from which I constructed this simple but effective python function to get ‘the other’ value.

Based on the original image dimensions “i_…” it figures out whether the image is portrait or landscape and calculates either the width or height.

Dropping the function in a python shell and calling it results in this output:

I deliberately left in the obvious 150 so you know instantly which dimension was calculated “c_…”.

Hope this saves people the trouble to figure it out by them selves.

GrtzG