Closing only single frame TIFF images

This commit is contained in:
wiredfool 2017-01-01 23:17:39 +00:00
parent 58484db509
commit b69b70198f

View File

@ -970,6 +970,7 @@ class TiffImageFile(ImageFile.ImageFile):
self.__frame += 1
self.fp.seek(self._frame_pos[frame])
self.tag_v2.load(self.fp)
self.__next = self.tag_v2.next
# fill the legacy tag/ifd entries
self.tag = self.ifd = ImageFileDirectory_v1.from_v2(self.tag_v2)
self.__frame = frame
@ -1009,6 +1010,12 @@ class TiffImageFile(ImageFile.ImageFile):
return self._load_libtiff()
return super(TiffImageFile, self).load()
def load_end(self):
# allow closing if we're on the first frame, there's no next
# This is the ImageFile.load path only, libtiff specific below.
if self.__frame == 0 and not self.__next:
self._exclusive_fp = True
def _load_libtiff(self):
""" Overload method triggered when we detect a compressed tiff
Calls out to libtiff """
@ -1087,15 +1094,13 @@ class TiffImageFile(ImageFile.ImageFile):
self.readonly = 0
# libtiff closed the fp in a, we need to close self.fp, if possible
if hasattr(self.fp, 'close'):
if not self.__next:
if self.__frame == 0 and not self.__next:
self.fp.close()
self.fp = None # might be shared
if err < 0:
raise IOError(err)
self.load_end()
return Image.Image.load(self)
def _setup(self):