Skip to content

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!

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