Use duration from info dictionary when saving

This commit is contained in:
Andrew Murray 2021-03-17 20:37:31 +11:00
parent 9dcb1f402c
commit 1d8c5a820c
2 changed files with 14 additions and 1 deletions

View File

@ -176,3 +176,16 @@ class TestFileWebp:
[abs(original_value[i] - reread_value[i]) for i in range(0, 3)]
)
assert difference < 5
@skip_unless_feature("webp")
@skip_unless_feature("webp_anim")
def test_duration(self, tmp_path):
with Image.open("Tests/images/dispose_bgnd.gif") as im:
assert im.info["duration"] == 1000
out_webp = str(tmp_path / "temp.webp")
im.save(out_webp, save_all=True)
with Image.open(out_webp) as reloaded:
reloaded.load()
assert reloaded.info["duration"] == 1000

View File

@ -192,7 +192,7 @@ def _save_all(im, fp, filename):
r, g, b = palette[background * 3 : (background + 1) * 3]
background = (r, g, b, 0)
duration = im.encoderinfo.get("duration", 0)
duration = im.encoderinfo.get("duration", im.info.get("duration"))
loop = im.encoderinfo.get("loop", 0)
minimize_size = im.encoderinfo.get("minimize_size", False)
kmin = im.encoderinfo.get("kmin", None)