From 88fca0f55531777d578831dd42d39819beea90dc Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Mon, 24 Aug 2015 23:23:07 +1000 Subject: [PATCH] Fixed palette issue when saving --- PIL/GifImagePlugin.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/PIL/GifImagePlugin.py b/PIL/GifImagePlugin.py index 1287f2a52..bd45e2dbc 100644 --- a/PIL/GifImagePlugin.py +++ b/PIL/GifImagePlugin.py @@ -301,14 +301,17 @@ RAWMODE = { } -def _convert_mode(im): +def _convert_mode(im, initial_call=False): # convert on the fly (EXPERIMENTAL -- I'm not sure PIL # should automatically convert images on save...) if Image.getmodebase(im.mode) == "RGB": - palette_size = 256 - if im.palette: - palette_size = len(im.palette.getdata()[1]) // 3 - return im.convert("P", palette=1, colors=palette_size) + if initial_call: + palette_size = 256 + if im.palette: + palette_size = len(im.palette.getdata()[1]) // 3 + return im.convert("P", palette=1, colors=palette_size) + else: + return im.convert("P") return im.convert("L") @@ -330,7 +333,7 @@ def _save(im, fp, filename, save_all=False): if im.mode in RAWMODE: im_out = im.copy() else: - im_out = _convert_mode(im) + im_out = _convert_mode(im, True) # header try: