Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ImageOps contain() #5417

Merged
merged 8 commits into from May 1, 2021
Merged

Added ImageOps contain() #5417

merged 8 commits into from May 1, 2021

Conversation

radarhere
Copy link
Member

Resolves #5415

Adds a contain() method to ImageOps. I would describe it as the inverse of fit().

Running this code for each method in turn for comparison -

from PIL import Image, ImageOps
im = Image.open("Tests/images/hopper.png")
ImageOps.fit(im, (200, 300))
Fit Pad Contain
Size 200 x 300 200 x 300 200 x 200
Image fit pad contain

@radarhere
Copy link
Member Author

3.10-dev failures seem to be due to pytest-dev/pytest#8539, which has been resolved, but is not available in a pytest release yet.

@radarhere radarhere changed the title Added contain method Added ImageOps contain() Apr 19, 2021
@axu2
Copy link

axu2 commented Apr 20, 2021

Looks great, exactly what I was looking for.

@axu2
Copy link

axu2 commented Apr 25, 2021

Sorry, I left a bunch of comments that I quickly deleted, since I had made an error. I was using a super old version of Pillow using Python2 but Python3 was fine. Seems like ImageOps.pad was always broken on Python2.

Copy link
Member

@hugovk hugovk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also include this in the docs (autofunction in docs/reference/ImageOps.rst?) and release notes.

src/PIL/ImageOps.py Outdated Show resolved Hide resolved
src/PIL/ImageOps.py Outdated Show resolved Hide resolved
src/PIL/ImageOps.py Outdated Show resolved Hide resolved
Tests/test_imageops.py Outdated Show resolved Hide resolved
radarhere and others added 3 commits May 1, 2021 21:56
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
docs/releasenotes/8.3.0.rst Outdated Show resolved Hide resolved
@hugovk
Copy link
Member

hugovk commented May 1, 2021

Thank you!

@hugovk hugovk merged commit 8a8ac60 into python-pillow:master May 1, 2021
@axu2
Copy link

axu2 commented May 1, 2021

🥳

@axu2
Copy link

axu2 commented May 1, 2021

Oh one last comment, just realized this function is similar to Image.thumbnail except it will upscale the image, if needed.

Also, for upscaling low resolution text, NEAREST might be a better choice.
https://en.wikipedia.org/wiki/Comparison_gallery_of_image_scaling_algorithms
Not a big deal though, since I can specify the method if I want, and bicubic is probably a better default for every other use case.

EDIT: nvm, just tested, NEAREST looks terrible for my use case haha.

@radarhere radarhere deleted the contain branch May 1, 2021 22:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Function similar to pad but returns resized image without padding
3 participants