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

Use duration from info dictionary when saving WebP #5338

Merged
merged 1 commit into from Mar 21, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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