Merge pull request #1 from radarhere/webp

_decoder.get_next() may return None
This commit is contained in:
k128 2023-08-01 09:54:11 -04:00 committed by GitHub
commit 9c6b8c423e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 8 deletions

View File

@ -233,5 +233,4 @@ class TestFileWebp:
im.save(out_webp, save_all=True)
with Image.open(out_webp) as reloaded:
reloaded.load()
assert reloaded.info["duration"] == 1000

View File

@ -74,9 +74,9 @@ class WebPImageFile(ImageFile.ImageFile):
self.info["background"] = (bg_r, bg_g, bg_b, bg_a)
self.n_frames = frame_count
self.is_animated = self.n_frames > 1
_, ts = self._decoder.get_next()
if ts:
self.info["duration"] = ts
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 = []
@ -93,7 +93,7 @@ class WebPImageFile(ImageFile.ImageFile):
self.info["xmp"] = xmp
# Initialize seek state
self._reset(reset=True)
self._reset()
def _getexif(self):
if "exif" not in self.info:
@ -116,9 +116,8 @@ class WebPImageFile(ImageFile.ImageFile):
# 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