PIL (image) ValueError: Invalid number of quantization tables. Must be 1 to 4
I want to draw a rectangle on a picture and save it as a new file. what i am doing is below:
from PIL import Image
from PIL import ImageChops
from PIL import ImageDraw
im = Image.open('the animal picture.jpg')
draw = ImageDraw.Draw(im)
draw.rectangle((69, 17, 418, 107))
im = im.convert('RGB')
im.save('new.jpg')
An error message appears:
Traceback (most recent call last):
File "C:\Python27\draw_re.py", line 9, in <module>
im.save('new.jpg')
File "C:\Python27\lib\PIL\Image.py", line 1439, in save
save_handler(self, fp, filename)
File "C:\Python27\lib\PIL\JpegImagePlugin.py", line 471, in _save
ImageFile._save(im, fp, [("jpeg", (0,0)+im.size, 0, rawmode)])
File "C:\Python27\lib\PIL\ImageFile.py", line 494, in _save
for e, b, o, a in tile:
ValueError: Not a valid number of quantization tables. Should be between 1 and 4.
Looks like a problem in PIL - Invalid number of quantization tables. Should be between 2 and 4 , but the hint doesn't fix the problem. This makes batch processing impossible.
source to share
I did it. Problem caused by using Image and PIL libraries that I am using.
I have uninstalled and uninstalled all the previous installed PIL and image libraries (there used to be confusion and difficulties with the original installations), so I have files and folders for the libraries.
I did uninstalls via pip, and also "Control Panel \ All Control Panel Items \ Programs and Features" in Windows. Also, folders and remnant files were manually deleted.
The pillow must be used. I downloaded the MS Windows installer from https://pypi.python.org/pypi/Pillow/2.6.1 and installed it. Run the script and it works fine.
source to share