Skip to content

Commit 7070fec

Browse files
authored
Merge pull request #7570 from radarhere/gif_optimize
"optimize" default when saving GIF images
2 parents 04a4d54 + f59b51f commit 7070fec

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

docs/handbook/image-file-formats.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,12 @@ following options are available::
266266
:py:class:`PIL.ImagePalette.ImagePalette` object.
267267

268268
**optimize**
269-
If present and true, attempt to compress the palette by
270-
eliminating unused colors. This is only useful if the palette can
271-
be compressed to the next smaller power of 2 elements.
269+
Whether to attempt to compress the palette by eliminating unused colors.
270+
This is attempted by default, unless a palette is specified as an option or
271+
as part of the first image's :py:attr:`~PIL.Image.Image.info` dictionary.
272+
273+
This is only useful if the palette can be compressed to the next smaller
274+
power of 2 elements.
272275

273276
Note that if the image you are saving comes from an existing GIF, it may have
274277
the following properties in its :py:attr:`~PIL.Image.Image.info` dictionary.

src/PIL/GifImagePlugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ def _save(im, fp, filename, save_all=False):
656656
palette = im.encoderinfo.get("palette", im.info.get("palette"))
657657
else:
658658
palette = None
659-
im.encoderinfo["optimize"] = im.encoderinfo.get("optimize", True)
659+
im.encoderinfo.setdefault("optimize", True)
660660

661661
if not save_all or not _write_multiple_frames(im, fp, palette):
662662
_write_single_frame(im, fp, palette)

0 commit comments

Comments
 (0)