Skip to content

Commit 0d20a00

Browse files
authored
Remove duration and timestamp from WebP info after seek (#9791)
2 parents 895e7f3 + d0da59b commit 0d20a00

3 files changed

Lines changed: 35 additions & 0 deletions

File tree

Tests/test_file_webp_animated.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ def test_seeking(tmp_path: Path) -> None:
180180
ts = dur * (im.n_frames - 1)
181181
for frame in reversed(range(im.n_frames)):
182182
im.seek(frame)
183+
assert "duration" not in im.info
184+
assert "timestamp" not in im.info
185+
183186
im.load()
184187
assert im.info["duration"] == dur
185188
assert im.info["timestamp"] == ts

docs/handbook/image-file-formats.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,6 +1376,36 @@ WebP
13761376

13771377
Pillow reads and writes WebP files. Requires libwebp v0.5.0 or later.
13781378

1379+
Opening
1380+
~~~~~~~
1381+
1382+
The :py:meth:`~PIL.Image.open` method sets the following
1383+
:py:attr:`~PIL.Image.Image.info` properties:
1384+
1385+
**background**
1386+
Background color of the canvas, as an RGBA tuple with values in
1387+
the range of (0-255).
1388+
1389+
**loop**
1390+
The number of times the WEBP should loop. 0 means that it will loop forever.
1391+
1392+
**icc_profile**
1393+
May not be present. The ICC color profile for the image.
1394+
1395+
**exif**
1396+
May not be present. Raw EXIF data from the image.
1397+
1398+
**xmp**
1399+
May not be present. Raw XMP data from the image.
1400+
1401+
**duration**
1402+
Only present after the current frame is loaded. The time to display the current
1403+
frame of the WEBP, in milliseconds.
1404+
1405+
**timestamp**
1406+
Only present after the current frame is loaded. The total duration of all previous
1407+
frames of the WEBP, in milliseconds.
1408+
13791409
.. _webp-saving:
13801410

13811411
Saving

src/PIL/WebPImagePlugin.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ def _getexif(self) -> dict[int, Any] | None:
8686
def seek(self, frame: int) -> None:
8787
if not self._seek_check(frame):
8888
return
89+
self.info.pop("timestamp", None)
90+
self.info.pop("duration", None)
8991

9092
# Set logical frame to requested position
9193
self.__logical_frame = frame

0 commit comments

Comments
 (0)