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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Round duration when saving animated WebP
  • Loading branch information
radarhere committed Mar 7, 2023
commit 459f0d8352f1bf0394e99b19fd09d529aa928d73
12 changes: 12 additions & 0 deletions Tests/test_file_webp_animated.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,18 @@ def test_timestamp_and_duration(tmp_path):
ts += durations[frame]


def test_float_duration(tmp_path):
temp_file = str(tmp_path / "temp.webp")
with Image.open("Tests/images/iss634.apng") as im:
assert im.info["duration"] == 70.0

im.save(temp_file, save_all=True)

with Image.open(temp_file) as reloaded:
reloaded.load()
assert reloaded.info["duration"] == 70


def test_seeking(tmp_path):
"""
Create an animated WebP file, and then try seeking through frames in reverse-order,
Expand Down
4 changes: 2 additions & 2 deletions src/PIL/WebPImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def _save_all(im, fp, filename):
# Append the frame to the animation encoder
enc.add(
frame.tobytes("raw", rawmode),
timestamp,
round(timestamp),
frame.size[0],
frame.size[1],
rawmode,
Expand All @@ -305,7 +305,7 @@ def _save_all(im, fp, filename):
im.seek(cur_idx)

# Force encoder to flush frames
enc.add(None, timestamp, 0, 0, "", lossless, quality, 0)
enc.add(None, round(timestamp), 0, 0, "", lossless, quality, 0)

# Get the final output from the encoder
data = enc.assemble(icc_profile, exif, xmp)
Expand Down