This commit is contained in:
Andrew Murray 2015-08-19 20:36:25 +00:00
commit 791fb12cd9
2 changed files with 27 additions and 4 deletions

View File

@ -24,7 +24,8 @@
# See the README file for information on usage and redistribution. # See the README file for information on usage and redistribution.
# #
from PIL import Image, ImageFile, ImagePalette, ImageChops, ImageSequence, _binary from PIL import Image, ImageFile, ImagePalette, \
ImageChops, ImageSequence, _binary
__version__ = "0.9" __version__ = "0.9"
@ -347,7 +348,14 @@ def _save(im, fp, filename, save_all=False):
# e.g. getdata(im_frame, duration=1000) # e.g. getdata(im_frame, duration=1000)
if not previous: if not previous:
# global header # global header
for s in getheader(im_frame, palette, im.encoderinfo)[0] + getdata(im_frame): duration = None
if "duration" in im.info:
duration = im.info["duration"]
loop = None
if "loop" in im.info:
loop = im.info["loop"]
for s in getheader(im_frame, palette, im.encoderinfo)[0] + \
getdata(im_frame, duration=duration, loop=loop):
fp.write(s) fp.write(s)
else: else:
# delta frame # delta frame
@ -426,7 +434,7 @@ def _get_local_header(fp, im, offset, flags):
else: else:
transparent_color_exists = False transparent_color_exists = False
if "duration" in im.encoderinfo: if im.encoderinfo.get("duration") is not None:
duration = int(im.encoderinfo["duration"] / 10) duration = int(im.encoderinfo["duration"] / 10)
else: else:
duration = 0 duration = 0
@ -443,7 +451,7 @@ def _get_local_header(fp, im, offset, flags):
o8(transparency) + # transparency index o8(transparency) + # transparency index
o8(0)) o8(0))
if "loop" in im.encoderinfo: if im.encoderinfo.get("loop") is not None:
number_of_loops = im.encoderinfo["loop"] number_of_loops = im.encoderinfo["loop"]
fp.write(b"!" + fp.write(b"!" +
o8(255) + # extension intro o8(255) + # extension intro

View File

@ -95,6 +95,21 @@ class TestFileGif(PillowTestCase):
self.assertEqual(reread.n_frames, 5) self.assertEqual(reread.n_frames, 5)
def test_headers_saving_for_animated_gifs(self):
important_headers = ['background', 'duration', 'loop']
# Multiframe image
im = Image.open("Tests/images/dispose_bgnd.gif")
out = self.tempfile('temp.gif')
im.save(out, save_all=True)
reread = Image.open(out)
for header in important_headers:
self.assertEqual(
im.info[header],
reread.info[header]
)
def test_palette_handling(self): def test_palette_handling(self):
# see https://github.com/python-pillow/Pillow/issues/513 # see https://github.com/python-pillow/Pillow/issues/513