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

Round duration when saving animated WebP images #6996

Merged
merged 1 commit into from
Mar 23, 2023

Conversation

radarhere
Copy link
Member

@radarhere radarhere commented Mar 8, 2023

Helps #7015

Alternative to #6977. This uses round() instead of int() to better approximate the data, and has a test using one of our existing images.

Animated PNGs can have float durations

self.im_info["duration"] = float(delay_num) / float(delay_den) * 1000

but when WebP goes to save the duration, it expects an integer.
enc.add(None, timestamp, 0, 0, "", lossless, quality, 0)

Pillow/src/_webp.c

Lines 206 to 209 in cdf5fd4

"z#iiisifi",
(char **)&rgb,
&size,
&timestamp,

The WebP API itself also expects the duration to be an integer. See https://developers.google.com/speed/webp/docs/container-api#webpanimencoderadd

int WebPAnimEncoderAdd(
WebPAnimEncoder* enc, struct WebPPicture* frame, int timestamp_ms,
const struct WebPConfig* config);

So this PR rounds the duration.

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.

None yet

2 participants