Azure-Samples / function-image-upload-resize

Sample function in Azure Functions that demonstrates how to upload and resize images in Azure Storage.
MIT License
67 stars 161 forks source link

Fix rounding error which causes aspect ratio to not be retained #24

Open johnnyoshika opened 1 year ago

johnnyoshika commented 1 year ago

To reproduce the error, try uploading an image that's 1024x1024 pixels, then resize to 900px width. The width will be 900px but the height will be calculated as 1024px, because the divisor will be 1 due to integer truncation.

var divisor = 1024 / 900; // 1

The fix is:

var divisor = (decimal)image.Width / thumbnailWidth;