Skip to content
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
13 changes: 13 additions & 0 deletions Tests/test_file_webp_animated.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,19 @@ def test_frame_durations(tmp_path: Path) -> None:
assert reloaded.info["duration"] == duration


def test_save_info_loop(tmp_path: Path) -> None:
temp_file = tmp_path / "temp.webp"
frames = [Image.new("RGB", (1, 1), color) for color in ("#f00", "#0f0")]
frames[0].save(temp_file, save_all=True, append_images=frames[1:], loop=2)

with Image.open(temp_file) as im:
assert im.info["loop"] == 2
im.save(temp_file, save_all=True)

with Image.open(temp_file) as im:
assert im.info["loop"] == 2


def test_float_duration(tmp_path: Path) -> None:
temp_file = tmp_path / "temp.webp"
with Image.open("Tests/images/iss634.apng") as im:
Expand Down
3 changes: 2 additions & 1 deletion docs/handbook/image-file-formats.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1560,7 +1560,8 @@ will be saved, and the following options will also be available.
duration for each frame separately.

**loop**
Number of times to repeat the animation. Defaults to [0 = infinite].
Number of times to repeat the animation. Defaults to the ``loop`` value in
:py:attr:`~PIL.Image.Image.info`, or 0 (infinite) if there is none.

**background**
Background color of the canvas, as an RGBA tuple with values in
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/WebPImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def _save_all(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
background = (background, background, background, 255)

duration = im.encoderinfo.get("duration")
loop = im.encoderinfo.get("loop", 0)
loop = im.encoderinfo.get("loop", im.info.get("loop", 0))
minimize_size = im.encoderinfo.get("minimize_size", False)
kmin = im.encoderinfo.get("kmin", None)
kmax = im.encoderinfo.get("kmax", None)
Expand Down
Loading