melinath / django-daguerre

On-the-fly image manipulation for Django.
http://django-daguerre.readthedocs.org/
BSD 3-Clause "New" or "Revised" License
85 stars 15 forks source link

Hotfix/round dimension #100

Closed fitodic closed 7 years ago

fitodic commented 7 years ago

If the newly calculated dimension of an image is a floating point number and by a fraction smaller than the specified/requested dimension, it will be taken into consideration and converted into an integer, i.e. rounded down.

For instance, if the original image is a portrait image of 666x1000px, and the desired variation is a landscape image of 300x180px, the original image will be scaled to 666x399px before calculating the variation. The newly calculated height of the variation is roughly 179.73, making it smaller than the specified height and therefore the new height. Since the minimum dimension is converted into an integer, it is rounded down, which results in a loss of one row/column of pixels.

Since the difference between the calculated and the specified height is infinitesimal, the proposed solution is to round the calculated value. This solution is already implemented and I would be happy to contribute.

Stjepan Zlodi was added as a co-contributor because he was the one who initially found the bug and made a quick fix. Given the circumstances in which this bug arouse, it was a fix with an intention of researching it more thoroughly in the future.

We have finally found the time to reproduce this bug, analyze it and implement a more acceptable solution.

melinath commented 7 years ago

This is great, thanks! Just one request - could you implement this for the cases where width & height are None? They would suffer from the same problem.

fitodic commented 7 years ago

Thanks for pointing that out! The round function was added to the two remaining cases.

melinath commented 7 years ago

Thanks for fixing those cases as well! Could you also add tests for those new changes? Then we're good to go!

fitodic commented 7 years ago

The tests have been added.