Skip to content

Correct saving APNG images with background disposal - #10269

Merged
radarhere merged 2 commits into
python-pillow:mainfrom
radarhere:apng_mode
Oct 21, 2026
Merged

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

Conversation

@radarhere

Copy link
Copy Markdown
Member

#10061 (comment) found that

from PIL import Image, PngImagePlugin
im = Image.new("L", (8, 8))
im.save("out.png", save_all=True, disposal=PngImagePlugin.Disposal.OP_BACKGROUND, append_images=[im.copy()])

raises

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "PIL/Image.py", line 2712, in save
    save_handler(self, fp, filename)
  File "PIL/PngImagePlugin.py", line 1349, in _save_all
    _save(im, fp, filename, save_all=True)
  File "PIL/PngImagePlugin.py", line 1555, in _save
    single_im = _write_multiple_frames(
                ^^^^^^^^^^^^^^^^^^^^^^^
  File "PIL/PngImagePlugin.py", line 1249, in _write_multiple_frames
    base_im.paste(dispose, bbox)
  File "PIL/Image.py", line 1935, in paste
    self.im.paste(source, box)
ValueError: images do not match

The solution is simply to ensure that PngImagePlugin converts the image internally when saving.

glaziermag and others added 2 commits October 21, 2026 15:59
The disposal fill is RGBA, so pasting it onto an L, P, 1 or I;16 frame
raised "images do not match", and for RGB it left opaque black instead of
the transparent background that the APNG spec uses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@radarhere
radarhere enabled auto-merge (squash) October 21, 2026 05:27
@radarhere
radarhere disabled auto-merge October 21, 2026 05:31
@radarhere
radarhere enabled auto-merge October 21, 2026 05:31
@radarhere
radarhere merged commit 4e66aa0 into python-pillow:main Oct 21, 2026
50 checks passed
@radarhere
radarhere deleted the apng_mode branch October 21, 2026 05:32
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