PIL (Image) ValueError:不是有效数量的量化表。应该在1到4之间

时间:2022-07-03 00:24:40

I want to draw a rectangle on a picture and save it as a new file. what I'm 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')

It gives an error message:

它给出一个错误信息:

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.

It looks like the problem in PIL - Not a valid numbers of quantization tables. Should be between 2 and 4, but the tip doesn't solve the problem. It makes batch processing impossible.

它看起来像PIL中的问题——不是一个有效的量子化表。应该在2到4之间,但是小费并不能解决问题。它使批处理成为不可能。

1 个解决方案

#1


4  

I worked it out. The problem caused by the Image and PIL libraries I am using.

我出来工作。由我正在使用的映像和PIL库引起的问题。

I uninstalled and removed all previous installed PIL and Image libraries (there were confusion before and difficulties in original installations) so I have cross files and folders for the libraries.

我卸载并删除了所有以前安装的PIL和Image库(在初始安装之前存在混乱和困难),所以我有用于库的交叉文件和文件夹。

I did the uninstallations through pip, and "Control Panel\All Control Panel Items\Programs and Features" in Windows as well. Also have manually removed the residues folders and files.

我通过pip和“控制面板的所有控制面板项目和功能”在Windows中卸载。也有手动删除残留文件夹和文件。

Pillow is the one shall be used. I downloaded a MS Windows installer from https://pypi.python.org/pypi/Pillow/2.6.1 and installed it. Run the script and it's working fine.

枕头是应使用。我从https://pypi.python.org/pypi/Pillow/2.6.1下载了一个MS Windows安装程序并安装了它。运行脚本,它运行良好。

#1


4  

I worked it out. The problem caused by the Image and PIL libraries I am using.

我出来工作。由我正在使用的映像和PIL库引起的问题。

I uninstalled and removed all previous installed PIL and Image libraries (there were confusion before and difficulties in original installations) so I have cross files and folders for the libraries.

我卸载并删除了所有以前安装的PIL和Image库(在初始安装之前存在混乱和困难),所以我有用于库的交叉文件和文件夹。

I did the uninstallations through pip, and "Control Panel\All Control Panel Items\Programs and Features" in Windows as well. Also have manually removed the residues folders and files.

我通过pip和“控制面板的所有控制面板项目和功能”在Windows中卸载。也有手动删除残留文件夹和文件。

Pillow is the one shall be used. I downloaded a MS Windows installer from https://pypi.python.org/pypi/Pillow/2.6.1 and installed it. Run the script and it's working fine.

枕头是应使用。我从https://pypi.python.org/pypi/Pillow/2.6.1下载了一个MS Windows安装程序并安装了它。运行脚本,它运行良好。