Added tuple option for durations

This commit is contained in:
wiredfool 2016-12-27 03:04:37 -08:00
parent 87092ad4f8
commit e530f2a228
2 changed files with 21 additions and 1 deletions

View File

@ -361,7 +361,7 @@ def _save(im, fp, filename, save_all=False):
for im_frame in ImageSequence.Iterator(imSequence):
encoderinfo = im.encoderinfo.copy()
im_frame = _convert_mode(im_frame)
if isinstance(duration, list):
if isinstance(duration, (list, tuple)):
encoderinfo["duration"] = duration[frame_count]
frame_count += 1

View File

@ -290,6 +290,8 @@ class TestFileGif(PillowTestCase):
Image.new('L', (100, 100), '#111'),
Image.new('L', (100, 100), '#222'),
]
#duration as list
im_list[0].save(
out,
save_all=True,
@ -305,6 +307,24 @@ class TestFileGif(PillowTestCase):
except EOFError:
pass
# duration as tuple
im_list[0].save(
out,
save_all=True,
append_images=im_list[1:],
duration=tuple(duration_list)
)
reread = Image.open(out)
for duration in duration_list:
self.assertEqual(reread.info['duration'], duration)
try:
reread.seek(reread.tell() + 1)
except EOFError:
pass
def test_number_of_loops(self):
number_of_loops = 2