diff --git a/Tests/test_image_reduce.py b/Tests/test_image_reduce.py index d36dbd609..e630d76e2 100644 --- a/Tests/test_image_reduce.py +++ b/Tests/test_image_reduce.py @@ -32,6 +32,29 @@ class TestImageReduce(PillowTestCase): with self.assertRaises(ValueError): im.reduce((0, 10)) + def test_args_box(self): + im = Image.new("L", (10, 10)) + + self.assertEqual((5, 5), im.reduce(2, (0, 0, 10, 10)).size) + self.assertEqual((1, 1), im.reduce(2, (5, 5, 6, 6)).size) + + with self.assertRaises(TypeError): + im.reduce(2, "stri") + with self.assertRaises(TypeError): + im.reduce(2, 2) + with self.assertRaises(ValueError): + im.reduce(2, (0, 0, 11, 10)) + with self.assertRaises(ValueError): + im.reduce(2, (0, 0, 10, 11)) + with self.assertRaises(ValueError): + im.reduce(2, (-1, 0, 10, 10)) + with self.assertRaises(ValueError): + im.reduce(2, (0, -1, 10, 10)) + with self.assertRaises(ValueError): + im.reduce(2, (0, 5, 10, 5)) + with self.assertRaises(ValueError): + im.reduce(2, (5, 0, 5, 10)) + def test_unsupported_modes(self): im = Image.new("P", (10, 10)) with self.assertRaises(ValueError): diff --git a/src/_imaging.c b/src/_imaging.c index 48240fda2..85964e913 100644 --- a/src/_imaging.c +++ b/src/_imaging.c @@ -1858,7 +1858,7 @@ _reduce(ImagingObject* self, PyObject* args) return ImagingError_ValueError("box can't exceed original image size"); } - if (box[2] < box[0] || box[3] < box[1]) { + if (box[2] <= box[0] || box[3] <= box[1]) { return ImagingError_ValueError("box can't be empty"); }