Skip to content

Commit d84fd20

Browse files
committed
Simplified is_animated
1 parent 0306b80 commit d84fd20

2 files changed

Lines changed: 6 additions & 24 deletions

File tree

Tests/test_file_tiff.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,6 @@ def test_n_frames(self):
229229
['Tests/images/multipage-lastframe.tif', 1],
230230
['Tests/images/multipage.tiff', 3]
231231
]:
232-
# Test is_animated before n_frames
233-
im = Image.open(path)
234-
self.assertEqual(im.is_animated, n_frames != 1)
235-
236-
# Test is_animated after n_frames
237232
im = Image.open(path)
238233
self.assertEqual(im.n_frames, n_frames)
239234
self.assertEqual(im.is_animated, n_frames != 1)

src/PIL/TiffImagePlugin.py

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,6 @@ def _open(self):
985985
self.__fp = self.fp
986986
self._frame_pos = []
987987
self._n_frames = None
988-
self._is_animated = None
989988

990989
if DEBUG:
991990
print("*** TiffImageFile._open ***")
@@ -1009,19 +1008,6 @@ def n_frames(self):
10091008

10101009
@property
10111010
def is_animated(self):
1012-
if self._is_animated is None:
1013-
if self._n_frames is not None:
1014-
self._is_animated = self._n_frames != 1
1015-
else:
1016-
current = self.tell()
1017-
1018-
try:
1019-
self.seek(1)
1020-
self._is_animated = True
1021-
except EOFError:
1022-
self._is_animated = False
1023-
1024-
self.seek(current)
10251011
return self._is_animated
10261012

10271013
def seek(self, frame):
@@ -1053,6 +1039,8 @@ def _seek(self, frame):
10531039
print("Loading tags, location: %s" % self.fp.tell())
10541040
self.tag_v2.load(self.fp)
10551041
self.__next = self.tag_v2.next
1042+
if len(self._frame_pos) == 1:
1043+
self._is_animated = self.__next != 0
10561044
self.__frame += 1
10571045
self.fp.seek(self._frame_pos[frame])
10581046
self.tag_v2.load(self.fp)
@@ -1086,7 +1074,7 @@ def load(self):
10861074
def load_end(self):
10871075
# allow closing if we're on the first frame, there's no next
10881076
# This is the ImageFile.load path only, libtiff specific below.
1089-
if len(self._frame_pos) == 1 and not self.__next:
1077+
if not self._is_animated:
10901078
self._close_exclusive_fp_after_loading = True
10911079

10921080
def _load_libtiff(self):
@@ -1166,10 +1154,9 @@ def _load_libtiff(self):
11661154
self.tile = []
11671155
self.readonly = 0
11681156
# libtiff closed the fp in a, we need to close self.fp, if possible
1169-
if self._exclusive_fp:
1170-
if len(self._frame_pos) == 1 and not self.__next:
1171-
self.fp.close()
1172-
self.fp = None # might be shared
1157+
if self._exclusive_fp and not self._is_animated:
1158+
self.fp.close()
1159+
self.fp = None # might be shared
11731160

11741161
if err < 0:
11751162
raise IOError(err)

0 commit comments

Comments
 (0)