mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-09 14:54:46 +03:00
Merge a86c5ec043
into e4f68d0658
This commit is contained in:
commit
791fb12cd9
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user