Do not save duplicates when duplicate sizes are supplied

This commit is contained in:
Andrew Murray 2022-03-11 21:37:45 +11:00
parent 475b7233d6
commit a8586fe1ff
2 changed files with 16 additions and 1 deletions

View File

@ -1,4 +1,5 @@
import io
import os
import pytest
@ -70,6 +71,20 @@ def test_save_to_bytes():
)
def test_no_duplicates(tmp_path):
temp_file = str(tmp_path / "temp.ico")
temp_file2 = str(tmp_path / "temp2.ico")
im = hopper()
sizes = [(32, 32), (64, 64)]
im.save(temp_file, "ico", sizes=sizes)
sizes.append(sizes[-1])
im.save(temp_file2, "ico", sizes=sizes)
assert os.path.getsize(temp_file) == os.path.getsize(temp_file2)
@pytest.mark.parametrize("mode", ("1", "L", "P", "RGB", "RGBA"))
def test_save_to_bytes_bmp(mode):
output = io.BytesIO()

View File

@ -51,7 +51,7 @@ def _save(im, fp, filename):
else True,
sizes,
)
sizes = list(sizes)
sizes = set(sizes)
fp.write(struct.pack("<H", len(sizes))) # idCount(2)
offset = fp.tell() + len(sizes) * 16
bmp = im.encoderinfo.get("bitmap_format") == "bmp"