Skip to content

Commit

Permalink
Merge pull request #7311 from k128/main
Browse files Browse the repository at this point in the history
Read WebP duration after opening
  • Loading branch information
radarhere authored Aug 11, 2023
2 parents f39f74f + 9c6b8c4 commit 39d866b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
1 change: 0 additions & 1 deletion Tests/test_file_webp.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,5 +233,4 @@ def test_duration(self, tmp_path):
im.save(out_webp, save_all=True)

with Image.open(out_webp) as reloaded:
reloaded.load()
assert reloaded.info["duration"] == 1000
10 changes: 6 additions & 4 deletions src/PIL/WebPImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ def _open(self):
self.info["background"] = (bg_r, bg_g, bg_b, bg_a)
self.n_frames = frame_count
self.is_animated = self.n_frames > 1
ret = self._decoder.get_next()
if ret is not None:
self.info["duration"] = ret[1]
self._mode = "RGB" if mode == "RGBX" else mode
self.rawmode = mode
self.tile = []
Expand All @@ -90,7 +93,7 @@ def _open(self):
self.info["xmp"] = xmp

# Initialize seek state
self._reset(reset=False)
self._reset()

def _getexif(self):
if "exif" not in self.info:
Expand All @@ -113,9 +116,8 @@ def seek(self, frame):
# Set logical frame to requested position
self.__logical_frame = frame

def _reset(self, reset=True):
if reset:
self._decoder.reset()
def _reset(self):
self._decoder.reset()
self.__physical_frame = 0
self.__loaded = -1
self.__timestamp = 0
Expand Down

0 comments on commit 39d866b

Please sign in to comment.