mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-03-03 19:45:56 +03:00
Merge pull request #3385 from radarhere/gif_background
Change tuple background to global color table index when saving as GIF
This commit is contained in:
commit
4530f55c61
|
@ -4,6 +4,12 @@ from PIL import Image, ImagePalette, GifImagePlugin
|
||||||
|
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
|
try:
|
||||||
|
from PIL import _webp
|
||||||
|
HAVE_WEBP = True
|
||||||
|
except ImportError:
|
||||||
|
HAVE_WEBP = False
|
||||||
|
|
||||||
codecs = dir(Image.core)
|
codecs = dir(Image.core)
|
||||||
|
|
||||||
# sample gif stream
|
# sample gif stream
|
||||||
|
@ -411,6 +417,11 @@ class TestFileGif(PillowTestCase):
|
||||||
|
|
||||||
self.assertEqual(reread.info['background'], im.info['background'])
|
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):
|
def test_comment(self):
|
||||||
im = Image.open(TEST_GIF)
|
im = Image.open(TEST_GIF)
|
||||||
self.assertEqual(im.info['comment'],
|
self.assertEqual(im.info['comment'],
|
||||||
|
|
|
@ -711,11 +711,18 @@ def _get_global_header(im, info):
|
||||||
if im.info.get("version") == b"89a":
|
if im.info.get("version") == b"89a":
|
||||||
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)
|
palette_bytes = _get_palette_bytes(im)
|
||||||
color_table_size = _get_color_table_size(palette_bytes)
|
color_table_size = _get_color_table_size(palette_bytes)
|
||||||
|
|
||||||
background = info["background"] if "background" in info else 0
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
b"GIF"+version + # signature + version
|
b"GIF"+version + # signature + version
|
||||||
o16(im.size[0]) + # canvas width
|
o16(im.size[0]) + # canvas width
|
||||||
|
|
Loading…
Reference in New Issue
Block a user