We need the ability to gracefully resize any photo / image to the exact width / height without distorting the image. We can use a third-party solution, or we can use the built-in .NET functionality for this. I thought this should be an easy solution, without the need for programming a complex algorithm.
Example scenario (we want all downloads to be changed to 200x100 pixels)
Landscape photo with dimensions of 1250x800:
Resizing to 200px would proportionally increase the height by 128 pixels, so that an additional 28px would be cropped top and bottom.
Landscape photo with dimensions of 1250x500:
Resizing the width to 200 pixels proportionally puts the vertex at 80 pixels, so we will need to first catch and resize it in height. Having set the height to 100 pixels, proportionally set the width to 250 pixels. An additional 50px will need to be cropped from the sides of the photo.
Portrait photo with dimensions of 800x950:
Resizing to 200px would proportionally place the height at 238 pixels, so that an additional 138px would be cropped top and bottom.
source
share