Round duration when saving animated WebP

This commit is contained in:
Andrew Murray 2023-03-07 18:07:46 +11:00
parent cdf5fd439c
commit 459f0d8352
2 changed files with 14 additions and 2 deletions

View File

@ -134,6 +134,18 @@ def test_timestamp_and_duration(tmp_path):
ts += durations[frame] 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): def test_seeking(tmp_path):
""" """
Create an animated WebP file, and then try seeking through frames in reverse-order, Create an animated WebP file, and then try seeking through frames in reverse-order,

View File

@ -285,7 +285,7 @@ def _save_all(im, fp, filename):
# Append the frame to the animation encoder # Append the frame to the animation encoder
enc.add( enc.add(
frame.tobytes("raw", rawmode), frame.tobytes("raw", rawmode),
timestamp, round(timestamp),
frame.size[0], frame.size[0],
frame.size[1], frame.size[1],
rawmode, rawmode,
@ -305,7 +305,7 @@ def _save_all(im, fp, filename):
im.seek(cur_idx) im.seek(cur_idx)
# Force encoder to flush frames # 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 # Get the final output from the encoder
data = enc.assemble(icc_profile, exif, xmp) data = enc.assemble(icc_profile, exif, xmp)