Skip to content

Commit

Permalink
allow lists as arguments for Image.new
Browse files Browse the repository at this point in the history
  • Loading branch information
homm committed Oct 4, 2016
1 parent 68a0b5e commit c5e111e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 3 additions & 3 deletions PIL/Image.py
Expand Up @@ -1020,7 +1020,7 @@ def crop(self, box=None):
4-tuple defining the left, upper, right, and lower pixel
coordinate.
Note: Prior to Pillow 3.4.0, this was a lazy operation.
Note: Prior to Pillow 3.4.0, this was a lazy operation.
:param box: The crop rectangle, as a (left, upper, right, lower)-tuple.
:rtype: :py:class:`~PIL.Image.Image`
Expand Down Expand Up @@ -1993,7 +1993,7 @@ def _check_size(size):
:returns: True, or raises a ValueError
"""

if not isinstance(size, tuple):
if not isinstance(size, (list, tuple)):
raise ValueError("Size must be a tuple")
if len(size) != 2:
raise ValueError("Size must be a tuple of length 2")
Expand All @@ -2019,7 +2019,7 @@ def new(mode, size, color=0):
"""

_check_size(size)

if color is None:
# don't initialize
return Image()._new(core.new(mode, size))
Expand Down
8 changes: 5 additions & 3 deletions Tests/test_image.py
Expand Up @@ -238,7 +238,7 @@ def test_effect_spread(self):
self.assert_image_similar(im2, im3, 110)

def test_check_size(self):
# Checking that the _check_size function throws value errors when we want it to.
# Checking that the _check_size function throws value errors when we want it to.
with self.assertRaises(ValueError):
Image.new('RGB', 0) # not a tuple
with self.assertRaises(ValueError):
Expand All @@ -247,19 +247,21 @@ def test_check_size(self):
Image.new('RGB', (0,0)) # w,h <= 0

self.assertTrue(Image.new('RGB', (1,1)))
# Should pass lists too
self.assertTrue(Image.new('RGB', [1,1]))

def test_storage_neg(self):
# Storage.c accepted negative values for xsize, ysize. Was
# test_neg_ppm, but the core function for that has been
# removed Calling directly into core to test the error in
# Storage.c, rather than the size check above

with self.assertRaises(ValueError):
Image.core.fill('RGB', (2,-2), (0,0,0))





if __name__ == '__main__':
unittest.main()

0 comments on commit c5e111e

Please sign in to comment.