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;
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.
The fix is: