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

Raise an error when performing a negative crop #5972

Merged
merged 2 commits into from Jan 21, 2022

Conversation

radarhere
Copy link
Member

Resolves #5957

At the moment, mixing up the order of the box values for crop(), so that a negative crop is performed, doesn't raise an error.

from PIL import Image
im = Image.new("RGB", (10, 10))
im.crop((10, 10, 0, 0))

gives a (0, 0) image.

In the issue, this was done unintentionally by a user, and because no error was raised, they didn't realise their mistake.

This PR raises an error is the right of a crop region is less than the left, or if the bottom of the region is less than the top.

I am presuming that it is uncommon for users to want a negative crop, and more common for users to mix up the order of the values.

Copy link
Contributor

@alexwlchan alexwlchan left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks!

src/PIL/Image.py Outdated Show resolved Hide resolved
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
@hugovk hugovk merged commit 53d0dd5 into python-pillow:main Jan 21, 2022
@hugovk
Copy link
Member

hugovk commented Jan 21, 2022

Thanks!

@radarhere radarhere deleted the crop branch January 21, 2022 22:13
radarhere added a commit to radarhere/Pillow that referenced this pull request Feb 10, 2022
radarhere added a commit to radarhere/Pillow that referenced this pull request Feb 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide an error message when user gives incorrect arguments to Image.crop()
3 participants