mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-10 19:56:47 +03:00
Wait until mode is normalized to copy im.info into encoderinfo
This commit is contained in:
parent
1e56ed8c00
commit
de2fbc9dff
|
@ -491,6 +491,27 @@ class TestFileGif(PillowTestCase):
|
|||
|
||||
self.assertEqual(reloaded.info['transparency'], 253)
|
||||
|
||||
def test_rgb_transparency(self):
|
||||
out = self.tempfile('temp.gif')
|
||||
|
||||
# Single frame
|
||||
im = Image.new('RGB', (1, 1))
|
||||
im.info['transparency'] = (255, 0, 0)
|
||||
self.assert_warning(UserWarning, im.save, out)
|
||||
|
||||
reloaded = Image.open(out)
|
||||
self.assertNotIn('transparency', reloaded.info)
|
||||
|
||||
# Multiple frames
|
||||
im = Image.new('RGB', (1, 1))
|
||||
im.info['transparency'] = b""
|
||||
ims = [Image.new('RGB', (1, 1))]
|
||||
self.assert_warning(UserWarning,
|
||||
im.save, out, save_all=True, append_images=ims)
|
||||
|
||||
reloaded = Image.open(out)
|
||||
self.assertNotIn('transparency', reloaded.info)
|
||||
|
||||
def test_bbox(self):
|
||||
out = self.tempfile('temp.gif')
|
||||
|
||||
|
|
|
@ -372,6 +372,8 @@ def _normalize_palette(im, palette, info):
|
|||
|
||||
def _write_single_frame(im, fp, palette):
|
||||
im_out = _normalize_mode(im, True)
|
||||
for k, v in im_out.info.items():
|
||||
im.encoderinfo.setdefault(k, v)
|
||||
im_out = _normalize_palette(im_out, palette, im.encoderinfo)
|
||||
|
||||
for s in _get_global_header(im_out, im.encoderinfo):
|
||||
|
@ -392,8 +394,8 @@ 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)
|
||||
duration = im.encoderinfo.get("duration", im.info.get("duration"))
|
||||
disposal = im.encoderinfo.get("disposal", im.info.get("disposal"))
|
||||
|
||||
im_frames = []
|
||||
frame_count = 0
|
||||
|
@ -402,6 +404,9 @@ def _write_multiple_frames(im, fp, palette):
|
|||
for im_frame in ImageSequence.Iterator(imSequence):
|
||||
# a copy is required here since seek can still mutate the image
|
||||
im_frame = _normalize_mode(im_frame.copy())
|
||||
if frame_count == 0:
|
||||
for k, v in im_frame.info.items():
|
||||
im.encoderinfo.setdefault(k, v)
|
||||
im_frame = _normalize_palette(im_frame, palette, im.encoderinfo)
|
||||
|
||||
encoderinfo = im.encoderinfo.copy()
|
||||
|
@ -460,12 +465,10 @@ def _save_all(im, fp, filename):
|
|||
|
||||
|
||||
def _save(im, fp, filename, save_all=False):
|
||||
for k, v in im.info.items():
|
||||
im.encoderinfo.setdefault(k, v)
|
||||
# header
|
||||
try:
|
||||
palette = im.encoderinfo["palette"]
|
||||
except KeyError:
|
||||
if "palette" in im.encoderinfo or "palette" in im.info:
|
||||
palette = im.encoderinfo.get("palette", im.info.get("palette"))
|
||||
else:
|
||||
palette = None
|
||||
im.encoderinfo["optimize"] = im.encoderinfo.get("optimize", True)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user