Visitar URL original
Fixed using info dictionary when writing multiple APNG frames by radarhere · Pull Request #5611 · python-pillow/Pillow · GitHub
Skip to content

Fixed using info dictionary when writing multiple APNG frames - #5611

Merged
hugovk merged 2 commits into
python-pillow:masterfrom
radarhere:apng_info
Aug 24, 2021
Merged

hugovk merged 2 commits into
python-pillow:masterfrom
radarhere:apng_info

Conversation

@radarhere

Copy link
Copy Markdown
Member

Two changes here.

  1. Fixed using info dictionary when writing multiple APNG frames.

duration can come from encoderinfo or info when saving multiple frames.

duration = im.encoderinfo.get("duration", im.info.get("duration", 0))

The duration variable is only part of the individual frame's encoderinfo when it is a list or tuple though, or if it was part of the actual image's encoderinfo.

encoderinfo = im.encoderinfo.copy()
if isinstance(duration, (list, tuple)):
encoderinfo["duration"] = duration[frame_count]

So when it comes to fetch it for writing, it is ignored.

disposal = frame_data["encoderinfo"].get("disposal", APNG_DISPOSE_OP_NONE)

The same applies to disposal and blend.

  1. if "duration" in previous["encoderinfo"]:
    previous["encoderinfo"]["duration"] += frame_duration
    else:
    previous["encoderinfo"]["duration"] = frame_duration

Duration is either specified for every frame (in which case the condition is true), or a single value is used (in which case previous["encoderinfo"]["duration"] = frame_duration is unnecessary). So the else code can be removed.

@hugovk
hugovk merged commit d5d6c3b into python-pillow:master Aug 24, 2021
@radarhere
radarhere deleted the apng_info branch August 24, 2021 09:07
@aclark4life aclark4life added the PNG label Oct 8, 2026
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.

3 participants