mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-12 16:24:45 +03:00
Changed GifImagePlugin so that save_all roundtrips duration and loop
This commit is contained in:
parent
4918a39a77
commit
26da91ca56
|
@ -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") != 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") != 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
|
||||||
|
|
|
@ -96,7 +96,7 @@ class TestFileGif(PillowTestCase):
|
||||||
self.assertEqual(reread.n_frames, 5)
|
self.assertEqual(reread.n_frames, 5)
|
||||||
|
|
||||||
def test_headers_saving_for_animated_gifs(self):
|
def test_headers_saving_for_animated_gifs(self):
|
||||||
important_headers = ['background', 'version', 'transparency', 'duration', 'loop']
|
important_headers = ['background', 'duration', 'loop']
|
||||||
# Multiframe image
|
# Multiframe image
|
||||||
im = Image.open("Tests/images/dispose_bgnd.gif")
|
im = Image.open("Tests/images/dispose_bgnd.gif")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user