Use rounding in ImageOps contain() and pad() #6522
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes ImageOps.contain function
Changes proposed in this pull request:
I tried to use ImageOps.pad on an image of size (4307, 6030) and I needed to resize it to (50,70). The image was resized but it had extended only on the right side. But actually, these two sizes don't need any expansion since both sizes are proportional.
So I checked the pillow code and found that ImageOps.pad is using ImageOps.contain and in contain function there is a code for calculating new height or new width based on the size.
new_height = int(image.height / image.width * size[0])
or
new_width = int(image.width / image.height * size[1])
But the problem here is when I ran that function with (50,70), it gave output (49,70).
code explanation:
Expected output :
But the new width should have been 50. So I changed " int " method with "round"