mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-10 19:56:47 +03:00
Change tuple background to global color table index when saving
This commit is contained in:
parent
3437d5fcb4
commit
a7eb2ea9cc
|
@ -4,6 +4,12 @@ from PIL import Image, ImagePalette, GifImagePlugin
|
|||
|
||||
from io import BytesIO
|
||||
|
||||
try:
|
||||
from PIL import _webp
|
||||
HAVE_WEBP = True
|
||||
except ImportError:
|
||||
HAVE_WEBP = False
|
||||
|
||||
codecs = dir(Image.core)
|
||||
|
||||
# sample gif stream
|
||||
|
@ -411,6 +417,11 @@ class TestFileGif(PillowTestCase):
|
|||
|
||||
self.assertEqual(reread.info['background'], im.info['background'])
|
||||
|
||||
if HAVE_WEBP and _webp.HAVE_WEBPANIM:
|
||||
im = Image.open("Tests/images/hopper.webp")
|
||||
self.assertIsInstance(im.info['background'], tuple)
|
||||
im.save(out)
|
||||
|
||||
def test_comment(self):
|
||||
im = Image.open(TEST_GIF)
|
||||
self.assertEqual(im.info['comment'],
|
||||
|
|
|
@ -711,11 +711,18 @@ def _get_global_header(im, info):
|
|||
if im.info.get("version") == b"89a":
|
||||
version = b"89a"
|
||||
|
||||
background = 0
|
||||
if "background" in info:
|
||||
background = info["background"]
|
||||
if isinstance(background, tuple):
|
||||
# WebPImagePlugin stores an RGBA value in info["background"]
|
||||
# So it must be converted to the same format as GifImagePlugin's
|
||||
# info["background"] - a global color table index
|
||||
background = im.palette.getcolor(background)
|
||||
|
||||
palette_bytes = _get_palette_bytes(im)
|
||||
color_table_size = _get_color_table_size(palette_bytes)
|
||||
|
||||
background = info["background"] if "background" in info else 0
|
||||
|
||||
return [
|
||||
b"GIF"+version + # signature + version
|
||||
o16(im.size[0]) + # canvas width
|
||||
|
|
Loading…
Reference in New Issue
Block a user