mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-13 18:56:17 +03:00
add append_images support for ico, much like icns
This commit is contained in:
parent
a0d8e550ec
commit
07b24c6e6e
|
@ -52,6 +52,9 @@ def _save(im, fp, filename):
|
|||
sizes = list(sizes)
|
||||
fp.write(struct.pack("<H", len(sizes))) # idCount(2)
|
||||
offset = fp.tell() + len(sizes) * 16
|
||||
alt_images = {
|
||||
im.size: im for im in im.encoderinfo.get("append_images", [])
|
||||
}
|
||||
for size in sizes:
|
||||
width, height = size
|
||||
# 0 means 256
|
||||
|
@ -63,9 +66,12 @@ def _save(im, fp, filename):
|
|||
fp.write(struct.pack("<H", 32)) # wBitCount(2)
|
||||
|
||||
image_io = BytesIO()
|
||||
# TODO: invent a more convenient method for proportional scalings
|
||||
tmp = im.copy()
|
||||
tmp.thumbnail(size, Image.LANCZOS, reducing_gap=None)
|
||||
if size in alt_images:
|
||||
tmp = alt_images[size]
|
||||
else:
|
||||
# TODO: invent a more convenient method for proportional scalings
|
||||
tmp = im.copy()
|
||||
tmp.thumbnail(size, Image.LANCZOS, reducing_gap=None)
|
||||
tmp.save(image_io, "png")
|
||||
image_io.seek(0)
|
||||
image_bytes = image_io.read()
|
||||
|
|
Loading…
Reference in New Issue
Block a user