mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-10 19:56:47 +03:00
Merge pull request #3471 from radarhere/background
Change color table index background to tuple when saving as WebP
This commit is contained in:
commit
231604e921
|
@ -153,6 +153,26 @@ class TestFileWebp(PillowTestCase):
|
|||
Image.open(blob).load()
|
||||
Image.open(blob).load()
|
||||
|
||||
@unittest.skipUnless(HAVE_WEBP and _webp.HAVE_WEBPANIM,
|
||||
"WebP save all not available")
|
||||
def test_background_from_gif(self):
|
||||
im = Image.open("Tests/images/chi.gif")
|
||||
original_value = im.convert("RGB").getpixel((1, 1))
|
||||
|
||||
# Save as WEBP
|
||||
out_webp = self.tempfile("temp.webp")
|
||||
im.save(out_webp, save_all=True)
|
||||
|
||||
# Save as GIF
|
||||
out_gif = self.tempfile("temp.gif")
|
||||
Image.open(out_webp).save(out_gif)
|
||||
|
||||
reread = Image.open(out_gif)
|
||||
reread_value = reread.convert("RGB").getpixel((1, 1))
|
||||
difference = sum([abs(original_value[i] - reread_value[i])
|
||||
for i in range(0, 3)])
|
||||
self.assertLess(difference, 5)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -191,7 +191,19 @@ def _save_all(im, fp, filename):
|
|||
_save(im, fp, filename)
|
||||
return
|
||||
|
||||
background = encoderinfo.get("background", (0, 0, 0, 0))
|
||||
background = (0, 0, 0, 0)
|
||||
if "background" in encoderinfo:
|
||||
background = encoderinfo["background"]
|
||||
elif "background" in im.info:
|
||||
background = im.info["background"]
|
||||
if isinstance(background, int):
|
||||
# GifImagePlugin stores a global color table index in
|
||||
# info["background"]. So it must be converted to an RGBA value
|
||||
palette = im.getpalette()
|
||||
if palette:
|
||||
r, g, b = palette[background*3:(background+1)*3]
|
||||
background = (r, g, b, 0)
|
||||
|
||||
duration = im.encoderinfo.get("duration", 0)
|
||||
loop = im.encoderinfo.get("loop", 0)
|
||||
minimize_size = im.encoderinfo.get("minimize_size", False)
|
||||
|
|
Loading…
Reference in New Issue
Block a user