Added width and height properties

This commit is contained in:
Andrew Murray 2015-06-24 10:35:37 +10:00
parent 951923f755
commit afa4cadb23
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