diff --git a/PIL/TiffImagePlugin.py b/PIL/TiffImagePlugin.py index 810f99e75..8c6e23676 100644 --- a/PIL/TiffImagePlugin.py +++ b/PIL/TiffImagePlugin.py @@ -1092,10 +1092,6 @@ class TiffImageFile(ImageFile.ImageFile): self.tile = [] 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: - self.fp.close() self.fp = None # might be shared if err < 0: diff --git a/Tests/test_file_libtiff.py b/Tests/test_file_libtiff.py index 2d1b33154..532cc36ca 100644 --- a/Tests/test_file_libtiff.py +++ b/Tests/test_file_libtiff.py @@ -370,7 +370,8 @@ class TestFileLibTiff(LibTiffTestCase): fn = im.fp.fileno() os.fstat(fn) - im.load() # this should close it. + im.load() + im.close() # this should close it. self.assertRaises(OSError, lambda: os.fstat(fn)) im = None # this should force even more closed. self.assertRaises(OSError, lambda: os.fstat(fn)) @@ -399,6 +400,19 @@ class TestFileLibTiff(LibTiffTestCase): TiffImagePlugin.READ_LIBTIFF = False + def test_multipage_nframes(self): + # issue #862 + TiffImagePlugin.READ_LIBTIFF = True + im = Image.open('Tests/images/multipage.tiff') + frames = im.n_frames + self.assertEqual(frames, 3) + for idx in range(frames): + im.seek(0) + # Should not raise ValueError: I/O operation on closed file + im.load() + + TiffImagePlugin.READ_LIBTIFF = False + def test__next(self): TiffImagePlugin.READ_LIBTIFF = True im = Image.open('Tests/images/hopper.tif') @@ -521,7 +535,7 @@ class TestFileLibTiff(LibTiffTestCase): except: self.fail("Should not get permission error here") - + if __name__ == '__main__':