mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 09:56:17 +03:00
Do not save duplicates when duplicate sizes are supplied
This commit is contained in:
parent
475b7233d6
commit
a8586fe1ff
|
@ -1,4 +1,5 @@
|
||||||
import io
|
import io
|
||||||
|
import os
|
||||||
|
|
||||||
import pytest
|
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"))
|
@pytest.mark.parametrize("mode", ("1", "L", "P", "RGB", "RGBA"))
|
||||||
def test_save_to_bytes_bmp(mode):
|
def test_save_to_bytes_bmp(mode):
|
||||||
output = io.BytesIO()
|
output = io.BytesIO()
|
||||||
|
|
|
@ -51,7 +51,7 @@ def _save(im, fp, filename):
|
||||||
else True,
|
else True,
|
||||||
sizes,
|
sizes,
|
||||||
)
|
)
|
||||||
sizes = list(sizes)
|
sizes = set(sizes)
|
||||||
fp.write(struct.pack("<H", len(sizes))) # idCount(2)
|
fp.write(struct.pack("<H", len(sizes))) # idCount(2)
|
||||||
offset = fp.tell() + len(sizes) * 16
|
offset = fp.tell() + len(sizes) * 16
|
||||||
bmp = im.encoderinfo.get("bitmap_format") == "bmp"
|
bmp = im.encoderinfo.get("bitmap_format") == "bmp"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user