overwrite redundant Image palette with new ImageCore Palette after quantize, fixes #513

This commit is contained in:
David Schmidt 2014-02-05 13:49:08 +01:00 committed by wiredfool
parent 232c175bd9
commit 6457eed2cb
2 changed files with 5 additions and 2 deletions

View File

@ -734,7 +734,10 @@ class Image:
if mode == "P" and palette == ADAPTIVE:
im = self.im.quantize(colors)
return self._new(im)
new = self._new(im)
from PIL import ImagePalette
new.palette = ImagePalette.raw("RGB", new.im.getpalette("RGB"))
return new
# colorspace conversion
if dither is None:

View File

@ -505,7 +505,7 @@ def _save(im, fp, filename, chunk=putchunk, check=0):
else:
# check palette contents
if im.palette:
colors = max(len(im.im.getpalette("RGB"))//3, 256)
colors = max(min(len(im.palette.getdata()[1])//3, 256), 2)
else:
colors = 256