Skip to content

Do not allow base image info to set disposal or blend - #10273

Merged
radarhere merged 2 commits into
python-pillow:mainfrom
radarhere:info
Oct 27, 2026
Merged

radarhere merged 2 commits into
python-pillow:mainfrom
radarhere:info

Conversation

@radarhere

@radarhere radarhere commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Alternative to #10061

When saving a GIF or PNG with multiple frames, you can specify the disposal or blend through a keyword argument, like

im.save("out.gif", save_all=True, disposal=2)
im.save("out.gif", save_all=True, disposal=(0, 1, 2))

However, if the user doesn't provide a keyword argument when saving, Pillow will fallback to the base image's info.

disposal = im.encoderinfo.get("disposal", im.info.get("disposal"))

disposal = im.encoderinfo.get("disposal", im.info.get("disposal", Disposal.OP_NONE))
blend = im.encoderinfo.get("blend", im.info.get("blend", Blend.OP_SOURCE))

When a single integer is in the disposal, GIF ignores it. GIF doesn't write "disposal" to info when opening. im.info["disposal"] = (0, 1, 2) is the only scenario for which this would make a difference, but info["disposal"] isn't documented at https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html#gif-saving, so I suggest removing it.

For PNG, a single integer in disposal and blend variables aren't used for that specific frame only, they are the default for all frames of all images. It isn't a documented feature at
and https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html#apng-saving. I consider this unexpected.

If you would like a demonstration of the unexpected behaviour, #10061 notes that roundtripping
out

from PIL import Image
Image.open("Tests/images/iss634.apng").save("out.png", save_all=True)

produces
out

The test code that I'm removing here was added in #5611.

@radarhere
radarhere merged commit eae2b56 into python-pillow:main Oct 27, 2026
51 checks passed
@radarhere
radarhere deleted the info branch October 27, 2026 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant