Skip to content

Conversation

@radarhere
Copy link
Member

https://pillow.readthedocs.io/en/latest/handbook/image-file-formats.html#gif-saving states that when saving GIF, you can specify "optimize", and that it is off by default.

optimize
If present and true, attempt to compress the palette by eliminating unused colors. This is only useful if the palette can be compressed to the next smaller power of 2 elements.

This doesn't line up with the reality - it is only off by default if "palette" is provided in im.encoderinfo or im.info.

def _save(im, fp, filename, save_all=False):
# header
if "palette" in im.encoderinfo or "palette" in im.info:
palette = im.encoderinfo.get("palette", im.info.get("palette"))
else:
palette = None
im.encoderinfo["optimize"] = im.encoderinfo.get("optimize", True)

This PR corrects the documentation, and also simplifies the code by using setdefault().

@radarhere radarhere added the GIF label Nov 25, 2023
@hugovk hugovk merged commit 7070fec into python-pillow:main Nov 25, 2023
@radarhere radarhere deleted the gif_optimize branch November 25, 2023 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants