Skip to content

Commit

Permalink
Merge pull request #5338 from radarhere/webp_save_duration
Browse files Browse the repository at this point in the history
Use duration from info dictionary when saving WebP
  • Loading branch information
hugovk committed Mar 21, 2021
2 parents 7235cf3 + 1d8c5a8 commit 688e6f1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions Tests/test_file_webp.py
Expand Up @@ -176,3 +176,16 @@ def test_background_from_gif(self, tmp_path):
[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
2 changes: 1 addition & 1 deletion src/PIL/WebPImagePlugin.py
Expand Up @@ -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)
Expand Down

0 comments on commit 688e6f1

Please sign in to comment.