Allow ICNS to change size as ICO does

This commit is contained in:
Andrew Murray 2019-05-29 21:14:18 +10:00
parent 02a2e93703
commit f7d7a80b5b
2 changed files with 6 additions and 13 deletions

View File

@ -61,11 +61,10 @@ class TestFileIcns(PillowTestCase):
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):

View File

@ -251,8 +251,6 @@ class IcnsImageFile(ImageFile.ImageFile):
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 @@ class IcnsImageFile(ImageFile.ImageFile):
)
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 @@ class IcnsImageFile(ImageFile.ImageFile):
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()