Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving to apng has wrong durations #8102

Closed
Yay295 opened this issue Jun 4, 2024 · 4 comments · Fixed by #8104
Closed

Saving to apng has wrong durations #8102

Yay295 opened this issue Jun 4, 2024 · 4 comments · Fixed by #8104

Comments

@Yay295
Copy link
Contributor

Yay295 commented Jun 4, 2024

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

@radarhere
Copy link
Member

Regarding saving to APNG, I've created #8104

I'm having trouble convincing ImageMagick to tell me the durations on my local machine or on GitHub Actions. I opened different_durations.png with https://davidmz.github.io/apng-js/ and it reported 4000 and 1000. If you think that ImageMagick isn't reading the duration according to the specification, then maybe that's something for you to raise with ImageMagick?

@Yay295
Copy link
Contributor Author

Yay295 commented Jun 4, 2024

I don't know why I didn't check this before, but saving from APNG to APNG has the same issue; it not only when the source is a GIF.

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

I think it probably is an issue in ImageMagick, or perhaps in libpng. I've filed an issue with ImageMagick though.

@Yay295 Yay295 changed the title Saving gif to apng has wrong durations Saving to apng has wrong durations Jun 4, 2024
@radarhere
Copy link
Member

The ImageMagick issue is ImageMagick/ImageMagick#7371

@radarhere
Copy link
Member

ImageMagick has made a change to fix their problem.

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 a pull request may close this issue.

2 participants