Skip to content

Commit be80b08

Browse files
committed
Automatically populate _n_frames if seeking to the last frame
1 parent d84fd20 commit be80b08

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

src/PIL/TiffImagePlugin.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -998,11 +998,8 @@ def _open(self):
998998
def n_frames(self):
999999
if self._n_frames is None:
10001000
current = self.tell()
1001-
try:
1002-
while True:
1003-
self._seek(self.tell() + 1)
1004-
except EOFError:
1005-
self._n_frames = self.tell() + 1
1001+
while self._n_frames is None:
1002+
self._seek(self.tell() + 1)
10061003
self.seek(current)
10071004
return self._n_frames
10081005

@@ -1039,6 +1036,8 @@ def _seek(self, frame):
10391036
print("Loading tags, location: %s" % self.fp.tell())
10401037
self.tag_v2.load(self.fp)
10411038
self.__next = self.tag_v2.next
1039+
if self.__next == 0:
1040+
self._n_frames = frame + 1
10421041
if len(self._frame_pos) == 1:
10431042
self._is_animated = self.__next != 0
10441043
self.__frame += 1

0 commit comments

Comments
 (0)