From afa4cadb2327935d6b5ebb036e4f26a831c84827 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Wed, 24 Jun 2015 10:35:37 +1000 Subject: [PATCH] Added width and height properties --- PIL/Image.py | 8 ++++++++ Tests/test_image.py | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/PIL/Image.py b/PIL/Image.py index a6b08d196..3740b51c6 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -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 diff --git a/Tests/test_image.py b/Tests/test_image.py index 469045909..bd5fd3522 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -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