Use rounding in ImageOps contain() and pad()#6522
Merged
hugovk merged 5 commits intopython-pillow:mainfrom Sep 21, 2022
Merged
Conversation
Member
|
I've created bibinhashley#1 to suggest a test, and to also use |
Member
|
@bibinhashley I find it slightly odd that you liked my comment, but haven't made any response to my pull request itself. If you're taking a moment to review my suggestions, not to worry, but in case you're not familiar with this procedure - the intention is for you to look at bibinhashley#1, and if you're ok with my ideas, merge it. Those changes will then become a part of this PR. |
Contributor
Author
|
Sorry I was busy and I couldn't follow the procedure. I will check the test and merge it. |
…in-finding-new-size Round position in pad()
Member
|
Thank you both for the PR! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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"