Merge pull request #1304 from radarhere/size

Added width and height properties
This commit is contained in:
Hugo van Kemenade 2015-06-26 13:01:02 +03:00
commit 4cf2240093
2 changed files with 17 additions and 0 deletions

View File

@ -504,6 +504,14 @@ class Image(object):
self.readonly = 0
self.pyaccess = None
@property
def width(self):
return self.size[0]
@property
def height(self):
return self.size[1]
def _new(self, im):
new = Image()
new.im = im

View File

@ -30,6 +30,15 @@ class TestImage(PillowTestCase):
# self.assertRaises(
# MemoryError, lambda: Image.new("L", (1000000, 1000000)))
def test_width_height(self):
im = Image.new("RGB", (1, 2))
self.assertEqual(im.width, 1)
self.assertEqual(im.height, 2)
im.size = (3, 4)
self.assertEqual(im.width, 3)
self.assertEqual(im.height, 4)
def test_invalid_image(self):
if str is bytes:
import StringIO