Added per-frame disposal, tests

This commit is contained in:
wiredfool 2017-12-21 22:26:58 +00:00
parent 364a7b895e
commit 378f74672c
2 changed files with 21 additions and 6 deletions

View File

@ -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:

View File

@ -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")