Add option to preserve identical consecutive APNG frames when saving
Author: DelganCreated Sep 26, 2026Updated Sep 29, 2026
Hi again.
I'd like to be able to save animated PNGs without Pillow merging the consecutive identical frames. As far as know, this is not cleanly possible with the current API.
Related (for GIFs):
- https://github.com/python-pillow/Pillow/issues/7809
- https://github.com/python-pillow/Pillow/issues/8397
I would like this feature for two reasons:
- I have dynamically generated APNGs that sometimes fail to
.save()because of this. It causesValueErrorwhile the individual frame delays are correctly representable, but their sum is not (numerator exceeds65535) - I would like to preserve the original number of frames distinctly, as they are meaningful for my workflow when the APNG is reopened later for editing or studying. I would like the frames and their durations to be saved losslessly so that the process is reversible.
Here is a reproducible example regarding the first point (with pillow==12.3.0):
from PIL import Image
frame_a = Image.new("RGB", (1, 1), "green")
frame_b = Image.new("RGB", (1, 1), "red")
# ValueError: cannot write duration
frame_a.save(
"output.png",
format="PNG",
save_all=True,
append_images=[frame_b, frame_b],
duration=[100, 32768, 32769],
)Would you please consider adding a save() option to help with these use cases?
Source: python-pillow/Pillow