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

Divisor should be double instead of integer #27

Open pnoyens opened 10 months ago

pnoyens commented 10 months ago

With the current implementation of Thumbnail.cs in the master branch, the division yielding var divisor returns an integer when in fact, a double precision number should be used. When running the code as is, aspect ratios for images are incorrect after processing. E.g. when divisor should be 1.6, a value of 1 will be returned. Same goes for divisor that should be 0.4, a value of 0 will be returned which in the end results in a "Divide by 0" exception to be thrown.

I've solved this in a forked version to explicitly cast one of the factors in the division to a double, like this:

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