I am trying to reduce number of colors to 1024, but got error ValueError: bad number of colors
img = img.convert('P', palette=Image.ADAPTIVE, colors=1024)
or
img = img.quantize(256, 0)
What is wrong?
I am trying to reduce number of colors to 1024, but got error ValueError: bad number of colors
img = img.convert('P', palette=Image.ADAPTIVE, colors=1024)
or
img = img.quantize(256, 0)
What is wrong?
As you can see here from the
PIL.Image
module source codehttps://pillow.readthedocs.io/en/stable/_modules/PIL/Image.html
the documenting comment for theconvert
method states that:so the
quantize
method is used for the operation because you didn't provide amatrix
argument to the convert method and now inside of thequantize
method the documenting states that:so the number of colors should be less than or equal to 256 instead a
ValueError
exception will be raised.