diff --git a/wagtail/wagtailimages/image_operations.py b/wagtail/wagtailimages/image_operations.py index a84bc805b..d1d90da7e 100644 --- a/wagtail/wagtailimages/image_operations.py +++ b/wagtail/wagtailimages/image_operations.py @@ -1,6 +1,7 @@ from __future__ import division import inspect +import math from wagtail.wagtailimages.exceptions import InvalidFilterSpecError @@ -158,7 +159,7 @@ class FillOperation(Operation): bottom = image_height # Crop! - willow.crop((int(left), int(top), int(right), int(bottom))) + willow.crop((math.floor(left), math.floor(top), math.ceil(right), math.ceil(bottom))) # Get scale for resizing # The scale should be the same for both the horizontal and diff --git a/wagtail/wagtailimages/tests/test_image_operations.py b/wagtail/wagtailimages/tests/test_image_operations.py index 9e6ddc6a0..8269ab553 100644 --- a/wagtail/wagtailimages/tests/test_image_operations.py +++ b/wagtail/wagtailimages/tests/test_image_operations.py @@ -154,7 +154,7 @@ class TestFillOperation(ImageOperationTestCase): # Basic usage with an oddly-sized original image # This checks for a rounding precision issue (#968) ('fill-200x200', Image(width=539, height=720), [ - ('crop', ((0, 90, 539, 629), ), {}), + ('crop', ((0, 90, 539, 630), ), {}), ('resize', ((200, 200), ), {}), ]), @@ -258,7 +258,32 @@ class TestFillOperation(ImageOperationTestCase): ), [ # This operation could probably be optimised out ('crop', ((0, 0, 1500, 1500), ), {}), - ]) + ]), + + + # A few tests for single pixel images + + ('fill-100x100', Image( + width=1, + height=1, + ), [ + ('crop', ((0, 0, 1, 1), ), {}), + ]), + + # This one once gave a ZeroDivisionError + ('fill-100x150', Image( + width=1, + height=1, + ), [ + ('crop', ((0, 0, 1, 1), ), {}), + ]), + + ('fill-150x100', Image( + width=1, + height=1, + ), [ + ('crop', ((0, 0, 1, 1), ), {}), + ]), ] TestFillOperation.setup_test_methods()