diff --git a/Tests/test_file_webp_animated.py b/Tests/test_file_webp_animated.py index 600448fb9e1..956139a88af 100644 --- a/Tests/test_file_webp_animated.py +++ b/Tests/test_file_webp_animated.py @@ -178,6 +178,9 @@ def test_seeking(tmp_path: Path) -> None: ts = dur * (im.n_frames - 1) for frame in reversed(range(im.n_frames)): im.seek(frame) + assert "duration" not in im.info + assert "timestamp" not in im.info + im.load() assert im.info["duration"] == dur assert im.info["timestamp"] == ts diff --git a/docs/handbook/image-file-formats.rst b/docs/handbook/image-file-formats.rst index 6b38b7278e8..95c95e5155f 100644 --- a/docs/handbook/image-file-formats.rst +++ b/docs/handbook/image-file-formats.rst @@ -1376,6 +1376,36 @@ WebP Pillow reads and writes WebP files. Requires libwebp v0.5.0 or later. +Opening +~~~~~~~ + +The :py:meth:`~PIL.Image.open` method sets the following +:py:attr:`~PIL.Image.Image.info` properties: + +**background** + Background color of the canvas, as an RGBA tuple with values in + the range of (0-255). + +**loop** + The number of times the WEBP should loop. 0 means that it will loop forever. + +**icc_profile** + May not be present. The ICC color profile for the image. + +**exif** + May not be present. Raw EXIF data from the image. + +**xmp** + May not be present. Raw XMP data from the image. + +**duration** + Only present after the current frame is loaded. The time to display the current + frame of the WEBP, in milliseconds. + +**timestamp** + Only present after the current frame is loaded. The total duration of all previous + frames of the WEBP, in milliseconds. + .. _webp-saving: Saving diff --git a/src/PIL/WebPImagePlugin.py b/src/PIL/WebPImagePlugin.py index 63a48169182..129f8255dc1 100644 --- a/src/PIL/WebPImagePlugin.py +++ b/src/PIL/WebPImagePlugin.py @@ -86,6 +86,8 @@ def _getexif(self) -> dict[int, Any] | None: def seek(self, frame: int) -> None: if not self._seek_check(frame): return + self.info.pop("timestamp", None) + self.info.pop("duration", None) # Set logical frame to requested position self.__logical_frame = frame