From a77ee2d8c56c07ebf97adde4677d821cb7229ae0 Mon Sep 17 00:00:00 2001 From: wiredfool Date: Tue, 4 Mar 2014 21:43:11 -0800 Subject: [PATCH] Fix test failure when optimizing the palette on mode L gifs --- PIL/GifImagePlugin.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/PIL/GifImagePlugin.py b/PIL/GifImagePlugin.py index 8882f9beb..c6d449425 100644 --- a/PIL/GifImagePlugin.py +++ b/PIL/GifImagePlugin.py @@ -252,6 +252,12 @@ def _save(im, fp, filename): except KeyError: palette = None im.encoderinfo["optimize"] = im.encoderinfo.get("optimize", True) + if im.encoderinfo["optimize"]: + # When the mode is L, and we optimize, we end up with + # im.mode == P and rawmode = L, which fails. + # If we're optimizing the palette, we're going to be + # in a rawmode of P anyway. + rawmode = 'P' header, usedPaletteColors = getheader(imOut, palette, im.encoderinfo) for s in header: