Skip to content

Add option to preserve identical consecutive APNG frames when saving #10063

Description

@Delgan

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):

I would like this feature for two reasons:

  1. I have dynamically generated APNGs that sometimes fail to .save() because of this. It causes ValueError while the individual frame delays are correctly representable, but their sum is not (numerator exceeds 65535)
  2. 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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions