Skip to content

Only combine PNG frames if the combined duration is still writable - #10070

Open
radarhere wants to merge 1 commit into
python-pillow:mainfrom
radarhere:apng
Open

radarhere wants to merge 1 commit into
python-pillow:mainfrom
radarhere:apng

Conversation

@radarhere

@radarhere radarhere commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Resolves #10063

If PNG's fcTL chunk cannot express the delay numerator in 2 bytes, we raise an error.

delay = Fraction(frame_duration / 1000).limit_denominator(65535)
if delay.numerator > 65535:
msg = "cannot write duration"
raise ValueError(msg)

If consecutive PNG frames are identical, we combine them to result in a smaller file.

bbox = delta.getbbox(alpha_only=False)
if (
not bbox
and prev_disposal == encoderinfo.get("disposal")
and prev_blend == encoderinfo.get("blend")
and "duration" in encoderinfo
):
previous.encoderinfo["duration"] += encoderinfo["duration"]

Let's not have these two features work against each other. If the combined duration of frames cannot be expressed in an fcTL chunk, then let's not combine them.

This branch has not been deployed

No deployments
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.

Add option to preserve identical consecutive APNG frames when saving

1 participant