From b46f5c6b1e87e19866baad6b40098134d602b392 Mon Sep 17 00:00:00 2001 From: "Eric W. Brown" Date: Wed, 30 Jul 2014 10:14:09 -0400 Subject: [PATCH 1/2] Better documented limited MPO save feature. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit At present it’s only possible to save the current frame of an MPO, not the MPO in its entirety. Added testing verifying as much. --- PIL/MpoImagePlugin.py | 3 ++- Tests/test_file_mpo.py | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/PIL/MpoImagePlugin.py b/PIL/MpoImagePlugin.py index 520e683d4..0d1185205 100644 --- a/PIL/MpoImagePlugin.py +++ b/PIL/MpoImagePlugin.py @@ -25,7 +25,8 @@ from PIL import Image, JpegImagePlugin def _accept(prefix): return JpegImagePlugin._accept(prefix) -def _save(im, fp, filename): +def _save(im, fp, filename, **options): + # Note that we can only save the current frame at present return JpegImagePlugin._save(im, fp, filename) ## diff --git a/Tests/test_file_mpo.py b/Tests/test_file_mpo.py index 20589539b..a221eec15 100644 --- a/Tests/test_file_mpo.py +++ b/Tests/test_file_mpo.py @@ -13,7 +13,8 @@ class TestFileMpo(PillowTestCase): if "jpeg_encoder" not in codecs or "jpeg_decoder" not in codecs: self.skipTest("jpeg support not available") - def roundtrip(self, im, **options): + def frame_roundtrip(self, im, **options): + # Note that for now, there is no MPO saving functionality out = BytesIO() im.save(out, "MPO", **options) bytes = out.tell() @@ -106,7 +107,19 @@ class TestFileMpo(PillowTestCase): im02 = im.tobytes() self.assertEqual(im0, im02) self.assertNotEqual(im0, im1) - + + def test_save(self): + # Note that only individual frames can be saved at present + for test_file in test_files: + im = Image.open(test_file) + self.assertEqual(im.tell(), 0) + jpg0 = self.frame_roundtrip(im) + self.assert_image_similar(im, jpg0, 30) + im.seek(1) + self.assertEqual(im.tell(), 1) + jpg1 = self.frame_roundtrip(im) + self.assert_image_similar(im, jpg1, 30) + if __name__ == '__main__': unittest.main() From 3f0ff0177e973c67efd756c73128b9d0a701a171 Mon Sep 17 00:00:00 2001 From: "Eric W. Brown" Date: Wed, 30 Jul 2014 10:16:51 -0400 Subject: [PATCH 2/2] Dropped unused "options" from MPO save. --- PIL/MpoImagePlugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PIL/MpoImagePlugin.py b/PIL/MpoImagePlugin.py index 0d1185205..d053d9026 100644 --- a/PIL/MpoImagePlugin.py +++ b/PIL/MpoImagePlugin.py @@ -25,7 +25,7 @@ from PIL import Image, JpegImagePlugin def _accept(prefix): return JpegImagePlugin._accept(prefix) -def _save(im, fp, filename, **options): +def _save(im, fp, filename): # Note that we can only save the current frame at present return JpegImagePlugin._save(im, fp, filename)