From ed4c0a58e8c84ee842e88d2c3fc81ca54e1596bb Mon Sep 17 00:00:00 2001 From: hugovk Date: Wed, 30 Nov 2016 16:36:04 +0200 Subject: [PATCH 1/3] Test case for #2266 --- Tests/test_file_ico.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Tests/test_file_ico.py b/Tests/test_file_ico.py index dc5c041b2..3904340f3 100644 --- a/Tests/test_file_ico.py +++ b/Tests/test_file_ico.py @@ -61,6 +61,24 @@ class TestFileIco(PillowTestCase): # Assert self.assertEqual(im_saved.size, (256, 256)) + def test_only_save_relevant_sizes(self): + """Issue #2266 https://github.com/python-pillow/Pillow/issues/2266 + Should save in 16x16, 24x24, 32x32, 48x48 sizes + and not in 16x16, 24x24, 32x32, 48x48, 48x48, 48x48, 48x48 sizes + """ + # Arrange + im = Image.open("Tests/images/python.ico") # 16x16, 32x32, 48x48 + outfile = self.tempfile("temp_saved_python.ico") + + # Act + im.save(outfile) + im_saved = Image.open(outfile) + + # Assert + self.assertEqual( + im_saved.info['sizes'], + set([(16, 16), (24, 24), (32, 32), (48, 48)])) + if __name__ == '__main__': unittest.main() From 880464f46c231e4e1c74abf61613af1306be1128 Mon Sep 17 00:00:00 2001 From: hugovk Date: Wed, 30 Nov 2016 16:41:43 +0200 Subject: [PATCH 2/3] Only save relevant sizes --- PIL/IcoImagePlugin.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/PIL/IcoImagePlugin.py b/PIL/IcoImagePlugin.py index 5dbf31f9f..195bbe42e 100644 --- a/PIL/IcoImagePlugin.py +++ b/PIL/IcoImagePlugin.py @@ -46,8 +46,9 @@ def _save(im, fp, filename): [(16, 16), (24, 24), (32, 32), (48, 48), (64, 64), (128, 128), (256, 256)]) width, height = im.size - filter(lambda x: False if (x[0] > width or x[1] > height or - x[0] > 256 or x[1] > 256) else True, sizes) + sizes = filter(lambda x: False if (x[0] > width or x[1] > height or + x[0] > 256 or x[1] > 256) else True, + sizes) fp.write(struct.pack(" Date: Wed, 30 Nov 2016 16:50:44 +0200 Subject: [PATCH 3/3] Python 3 compatibility --- PIL/IcoImagePlugin.py | 1 + 1 file changed, 1 insertion(+) diff --git a/PIL/IcoImagePlugin.py b/PIL/IcoImagePlugin.py index 195bbe42e..3436ae84f 100644 --- a/PIL/IcoImagePlugin.py +++ b/PIL/IcoImagePlugin.py @@ -49,6 +49,7 @@ def _save(im, fp, filename): sizes = filter(lambda x: False if (x[0] > width or x[1] > height or x[0] > 256 or x[1] > 256) else True, sizes) + sizes = list(sizes) fp.write(struct.pack("