From f7d7a80b5bf69a29433551068a13412a2fa82855 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Wed, 29 May 2019 21:14:18 +1000 Subject: [PATCH] Allow ICNS to change size as ICO does --- Tests/test_file_icns.py | 9 ++++----- src/PIL/IcnsImagePlugin.py | 10 ++-------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/Tests/test_file_icns.py b/Tests/test_file_icns.py index ac60731f957..b8e1b98789b 100644 --- a/Tests/test_file_icns.py +++ b/Tests/test_file_icns.py @@ -61,11 +61,10 @@ def test_sizes(self): for w, h, r in im.info['sizes']: wr = w * r hr = h * r - im2 = Image.open(TEST_FILE) - im2.size = (w, h, r) - im2.load() - self.assertEqual(im2.mode, 'RGBA') - self.assertEqual(im2.size, (wr, hr)) + im.size = (w, h, r) + im.load() + self.assertEqual(im.mode, 'RGBA') + self.assertEqual(im.size, (wr, hr)) # Check that we cannot load an incorrect size with self.assertRaises(ValueError): diff --git a/src/PIL/IcnsImagePlugin.py b/src/PIL/IcnsImagePlugin.py index cd620a337df..9ab9d00f22a 100644 --- a/src/PIL/IcnsImagePlugin.py +++ b/src/PIL/IcnsImagePlugin.py @@ -251,8 +251,6 @@ def _open(self): self.best_size[0] * self.best_size[2], self.best_size[1] * self.best_size[2], ) - # Just use this to see if it's loaded or not yet. - self.tile = ("",) @property def size(self): @@ -286,7 +284,8 @@ def load(self): ) Image.Image.load(self) - if not self.tile: + if self.im and self.im.size == self.size: + # Already loaded return self.load_prepare() # This is likely NOT the best way to do it, but whatever. @@ -298,11 +297,6 @@ def load(self): self.im = im.im self.mode = im.mode self.size = im.size - if self._exclusive_fp: - self.fp.close() - self.fp = None - self.icns = None - self.tile = () self.load_end()