When an image gets distorted it is often because one dimension is adjusted without the other. The key to keeping the correct aspect ratio while resizing an image is the algorithm used to calculate the ratio, viz.
NewHeight = GivenWidth * (OriginalHeight / OriginalWidth)
or
NewWidth = GivenHeight * (OriginalWidth / OriginalHeight)
This calculation assumes that the “Given...” is the dimension the image should be resized to. Once we know this, we can multiply it by the original image’s aspect, and that will give us the other side's value we need. So, assuming the original image has a width of 1000 and a height of 1600 and we want it to be resized to a width of 500:
First find the aspect: (1600 / 1000) = aspect of 1.6
Now multiply the aspect by the desired new width: 1.6 * 500
The result of that multiplication is 800, which is what our height should be
In other words:
800 = 500 * (1600 / 1000)
So the resulting image would have a height of 800 and a width of 500.