Skip to content

Commit

Permalink
Allow ICNS to change size as ICO does
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Jun 8, 2019
1 parent d7c25b6 commit 23c609b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
9 changes: 4 additions & 5 deletions Tests/test_file_icns.py
Expand Up @@ -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):
Expand Down
10 changes: 2 additions & 8 deletions src/PIL/IcnsImagePlugin.py
Expand Up @@ -269,8 +269,6 @@ def _open(self):
self.best_size = self.icns.bestsize()
self.size = (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):
Expand Down Expand Up @@ -299,7 +297,8 @@ def load(self):
self.best_size[1] * self.best_size[2])

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.
Expand All @@ -311,11 +310,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()


Expand Down

0 comments on commit 23c609b

Please sign in to comment.