diff --git a/PIL/PngImagePlugin.py b/PIL/PngImagePlugin.py index a6038d9f2..30fdfb8ac 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 = len(im.palette.getdata()[1])//3 + colors = max(len(im.im.getpalette("RGB"))//3, 256) else: colors = 256