diff --git a/PIL/FliImagePlugin.py b/PIL/FliImagePlugin.py index 32cd05049..0660ddeb6 100644 --- a/PIL/FliImagePlugin.py +++ b/PIL/FliImagePlugin.py @@ -131,7 +131,6 @@ class FliImageFile(ImageFile.ImageFile): self._seek(f) def _seek(self, frame): - if frame == 0: self.__frame = -1 self.__fp.seek(self.__rewind) @@ -157,7 +156,6 @@ class FliImageFile(ImageFile.ImageFile): self.__offset += framesize def tell(self): - return self.__frame # diff --git a/Tests/images/hopper.im b/Tests/images/hopper.im new file mode 100644 index 000000000..ceeb01049 Binary files /dev/null and b/Tests/images/hopper.im differ diff --git a/Tests/images/hopper_merged.psd b/Tests/images/hopper_merged.psd new file mode 100644 index 000000000..6b5c7ebe1 Binary files /dev/null and b/Tests/images/hopper_merged.psd differ diff --git a/Tests/test_file_dcx.py b/Tests/test_file_dcx.py index 2acf7b459..7d2ae32d8 100644 --- a/Tests/test_file_dcx.py +++ b/Tests/test_file_dcx.py @@ -30,6 +30,10 @@ class TestFileDcx(PillowTestCase): # Assert self.assertEqual(frame, 0) + def test_n_frames(self): + im = Image.open(TEST_FILE) + self.assertEqual(im.n_frames, 1) + def test_seek_too_far(self): # Arrange im = Image.open(TEST_FILE) diff --git a/Tests/test_file_fli.py b/Tests/test_file_fli.py index e6634c799..04c2006c9 100644 --- a/Tests/test_file_fli.py +++ b/Tests/test_file_fli.py @@ -18,6 +18,10 @@ class TestFileFli(PillowTestCase): self.assertEqual(im.size, (128, 128)) self.assertEqual(im.format, "FLI") + def test_n_frames(self): + im = Image.open(test_file) + self.assertEqual(im.n_frames, 2) + if __name__ == '__main__': unittest.main() diff --git a/Tests/test_file_gif.py b/Tests/test_file_gif.py index 08b2f10c9..0e9e65a18 100644 --- a/Tests/test_file_gif.py +++ b/Tests/test_file_gif.py @@ -134,6 +134,10 @@ class TestFileGif(PillowTestCase): except EOFError: self.assertEqual(framecount, 5) + def test_n_frames(self): + im = Image.open("Tests/images/iss634.gif") + self.assertEqual(im.n_frames, 43) + def test_dispose_none(self): img = Image.open("Tests/images/dispose_none.gif") try: diff --git a/Tests/test_file_im.py b/Tests/test_file_im.py new file mode 100644 index 000000000..24e00b2f0 --- /dev/null +++ b/Tests/test_file_im.py @@ -0,0 +1,33 @@ +from helper import unittest, PillowTestCase, hopper + +from PIL import Image + +# sample im +TEST_IM = "Tests/images/hopper.im" + + +class TestFileIm(PillowTestCase): + + def test_sanity(self): + im = Image.open(TEST_IM) + im.load() + self.assertEqual(im.mode, "RGB") + self.assertEqual(im.size, (128, 128)) + self.assertEqual(im.format, "IM") + + def test_n_frames(self): + im = Image.open(TEST_IM) + self.assertEqual(im.n_frames, 1) + + def test_roundtrip(self): + out = self.tempfile('temp.im') + im = hopper() + im.save(out) + reread = Image.open(out) + + self.assert_image_equal(reread, im) + +if __name__ == '__main__': + unittest.main() + +# End of file diff --git a/Tests/test_file_mpo.py b/Tests/test_file_mpo.py index 7850744af..1a0ebc453 100644 --- a/Tests/test_file_mpo.py +++ b/Tests/test_file_mpo.py @@ -95,6 +95,10 @@ class TestFileMpo(PillowTestCase): im.seek(0) self.assertEqual(im.tell(), 0) + def test_n_frames(self): + im = Image.open("Tests/images/sugarshack.mpo") + self.assertEqual(im.n_frames, 2) + def test_image_grab(self): for test_file in test_files: im = Image.open(test_file) diff --git a/Tests/test_file_psd.py b/Tests/test_file_psd.py index 51b8cf3f4..dca3601b2 100644 --- a/Tests/test_file_psd.py +++ b/Tests/test_file_psd.py @@ -16,6 +16,13 @@ class TestImagePsd(PillowTestCase): self.assertEqual(im.size, (128, 128)) self.assertEqual(im.format, "PSD") + def test_n_frames(self): + im = Image.open("Tests/images/hopper_merged.psd") + self.assertEqual(im.n_frames, 1) + + im = Image.open(test_file) + self.assertEqual(im.n_frames, 2) + if __name__ == '__main__': unittest.main() diff --git a/Tests/test_file_spider.py b/Tests/test_file_spider.py index 7bfedad1a..7d24b2fe5 100644 --- a/Tests/test_file_spider.py +++ b/Tests/test_file_spider.py @@ -42,6 +42,10 @@ class TestImageSpider(PillowTestCase): # Assert self.assertEqual(index, 0) + def test_n_frames(self): + im = Image.open(TEST_FILE) + self.assertEqual(im.n_frames, 1) + def test_loadImageSeries(self): # Arrange not_spider_file = "Tests/images/hopper.ppm" diff --git a/Tests/test_file_tiff.py b/Tests/test_file_tiff.py index 745412324..02a63586c 100644 --- a/Tests/test_file_tiff.py +++ b/Tests/test_file_tiff.py @@ -150,6 +150,13 @@ class TestFileTiff(PillowTestCase): self.assertEqual( im.getextrema(), (-3.140936851501465, 3.140684127807617)) + def test_n_frames(self): + im = Image.open('Tests/images/multipage-lastframe.tif') + self.assertEqual(im.n_frames, 1) + + im = Image.open('Tests/images/multipage.tiff') + self.assertEqual(im.n_frames, 3) + def test_multipage(self): # issue #862 im = Image.open('Tests/images/multipage.tiff')