From ecb1cef99b5eae47db76eb94280b840af34e0fc5 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Thu, 11 Jun 2015 11:10:05 +1000 Subject: [PATCH] Added background color index saving to GifImagePlugin --- PIL/GifImagePlugin.py | 3 ++- Tests/test_file_gif.py | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/PIL/GifImagePlugin.py b/PIL/GifImagePlugin.py index 18fcb9b21..54e92a711 100644 --- a/PIL/GifImagePlugin.py +++ b/PIL/GifImagePlugin.py @@ -537,7 +537,8 @@ def getheader(im, palette=None, info=None): # size of global color table + global color table flag header.append(o8(color_table_size + 128)) # background + reserved/aspect - header.append(o8(0) + o8(0)) + background = im.info["background"] if "background" in im.info else 0 + header.append(o8(background) + o8(0)) # end of Logical Screen Descriptor # add the missing amount of bytes diff --git a/Tests/test_file_gif.py b/Tests/test_file_gif.py index 0e9e65a18..f415a1b2b 100644 --- a/Tests/test_file_gif.py +++ b/Tests/test_file_gif.py @@ -201,6 +201,15 @@ class TestFileGif(PillowTestCase): self.assertEqual(reread.info['loop'], number_of_loops) + def test_background(self): + out = self.tempfile('temp.gif') + im = Image.new('L', (100, 100), '#000') + im.info['background'] = 1 + im.save(out) + reread = Image.open(out) + + self.assertEqual(reread.info['background'], im.info['background']) + if __name__ == '__main__': unittest.main()