Skip to content

Saving to apng has wrong durations #8102

@Yay295

Description

@Yay295

Using https://github.com/python-pillow/Pillow/blob/main/Tests/images/apng/different_durations.png

from PIL import Image, ImageSequence

ddp = Image.open('different_durations.png')
print([frame.info.get('duration') for frame in ImageSequence.Iterator(ddp)]) # [4000.0, 1000.0]
ddp.save('different_durations.gif',save_all=True)

ddg = Image.open('different_durations.gif')
print([frame.info.get('duration') for frame in ImageSequence.Iterator(ddg)]) # [4000, 1000]
ddg.save('same_durations.png',save_all=True)

sdp = Image.open('same_durations.png')
print([frame.info.get('duration') for frame in ImageSequence.Iterator(sdp)]) # [1000.0, 1000.0]

Also, ImageMagick (version 7.1.1-33) says the duration of the second frame is actually 990, not 1000.

> magick identify -format %T\n apng:different_durations.png
400
99

I'm not sure what's going on there though, because the duration parsing isn't complicated.

delay_num, delay_den = i16(s, 20), i16(s, 22)
if delay_den == 0:
delay_den = 100
self.im_info["duration"] = float(delay_num) / float(delay_den) * 1000

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