From 378f74672c96607ac68c083c050352f75b68d18b Mon Sep 17 00:00:00 2001 From: wiredfool Date: Thu, 21 Dec 2017 22:26:58 +0000 Subject: [PATCH] Added per-frame disposal, tests --- PIL/GifImagePlugin.py | 3 +++ Tests/test_file_gif.py | 24 ++++++++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/PIL/GifImagePlugin.py b/PIL/GifImagePlugin.py index 078a2f24b..71d8ce59a 100644 --- a/PIL/GifImagePlugin.py +++ b/PIL/GifImagePlugin.py @@ -392,6 +392,7 @@ def _write_single_frame(im, fp, palette): def _write_multiple_frames(im, fp, palette): duration = im.encoderinfo.get("duration", None) + disposal = im.encoderinfo.get('disposal', None) im_frames = [] frame_count = 0 @@ -404,6 +405,8 @@ def _write_multiple_frames(im, fp, palette): encoderinfo = im.encoderinfo.copy() if isinstance(duration, (list, tuple)): encoderinfo['duration'] = duration[frame_count] + if isinstance(disposal, (list, tuple)): + encoderinfo["disposal"] = disposal[frame_count] frame_count += 1 if im_frames: diff --git a/Tests/test_file_gif.py b/Tests/test_file_gif.py index 9e6db85f6..4a227e0cf 100644 --- a/Tests/test_file_gif.py +++ b/Tests/test_file_gif.py @@ -274,12 +274,24 @@ class TestFileGif(PillowTestCase): disposal=method ) img = Image.open(out) - try: - while True: - img.seek(img.tell() + 1) - self.assertEqual(img.disposal_method, method) - except EOFError: - pass + for _ in range(2): + img.seek(img.tell() + 1) + self.assertEqual(img.disposal_method, method) + + + # check per frame disposal + im_list[0].save( + out, + save_all=True, + append_images=im_list[1:], + disposal=range(len(im_list)) + ) + + img = Image.open(out) + + for i in range(2): + img.seek(img.tell() + 1) + self.assertEqual(img.disposal_method, i+1) def test_iss634(self): img = Image.open("Tests/images/iss634.gif")