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

Gracefully handle out-of-bounds crops #92

Merged
merged 1 commit into from Feb 25, 2022

Commits on Feb 21, 2022

  1. Gracefully handle out-of-bounds crops

    When passed a crop rectangle that extends outside an image's boundaries, Pillow gracefully returns an image of the requested size (padding with background / transparent pixels as required), but Wand throws a value error. If the calling app is sloppy about dimensions (as is apparently the case in wagtail/wagtail#7766), this will result in errors that only surface when Wand is in use (i.e. for animated gifs).
    
    This PR gives the two backends a consistent "middle ground" behaviour that hopefully makes intuitive sense: the crop rectangle is clamped to the image boundary so that if it overlaps, the final image is smaller than requested. Totally out of bounds or nonsensical parameters (e.g. left > right) will raise a BadImageOperationError.
    
    Fixes wagtail/wagtail#7766, although we'll also want to fix the rounding error that leads to the out-of-bounds condition in the first place.
    gasman committed Feb 21, 2022
    Copy the full SHA
    d45ac09 View commit details
    Browse the repository at this point in the history