Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"optimize" default when saving GIF images #7570

Merged
merged 2 commits into from
Nov 25, 2023

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
57 checks passed
@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.

None yet

2 participants