diff --git a/PIL/Image.py b/PIL/Image.py index e71e2ad5f..442393a9e 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -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: diff --git a/PIL/PngImagePlugin.py b/PIL/PngImagePlugin.py index 30fdfb8ac..d72a9c141 100644 --- a/PIL/PngImagePlugin.py +++ b/PIL/PngImagePlugin.py @@ -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