From 69bea50810ebc0b4234de4bf461ce5c76f2af72b Mon Sep 17 00:00:00 2001 From: wiredfool Date: Tue, 29 Nov 2016 19:25:49 +0000 Subject: [PATCH] Allow 0 size images, Fixes #2259 --- PIL/Image.py | 4 ++-- Tests/test_image.py | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/PIL/Image.py b/PIL/Image.py index c086dfcd7..03f3973ee 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -1994,8 +1994,8 @@ def _check_size(size): raise ValueError("Size must be a tuple") if len(size) != 2: raise ValueError("Size must be a tuple of length 2") - if size[0] <= 0 or size[1] <= 0: - raise ValueError("Width and Height must be > 0") + if size[0] < 0 or size[1] < 0: + raise ValueError("Width and Height must be => 0") return True diff --git a/Tests/test_image.py b/Tests/test_image.py index ef9aa16af..f1457a85b 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -256,7 +256,11 @@ class TestImage(PillowTestCase): with self.assertRaises(ValueError): Image.new('RGB', (0,)) # Tuple too short with self.assertRaises(ValueError): - Image.new('RGB', (0,0)) # w,h <= 0 + Image.new('RGB', (-1,-1)) # w,h < 0 + + # this should pass with 0 sized images, #2259 + im = Image.new('L', (0, 0)) + self.assertEqual(im.size, (0, 0)) self.assertTrue(Image.new('RGB', (1,1))) # Should pass lists too