小编Gau*_*ard的帖子

使用PIL修改然后保存TIFF会返回错误

TLDR; 我正在尝试使用TIFF,调整大小,然后保存它.但是它会返回错误.如果我将保存的文件类型更改为png或jpg,这可以正常工作.

系统:Windows 7使用Python 3.4和2.7进行尝试.

码:

from PIL import Image

try:                                               #test file exists
    im = Image.open(r"c:\temp\file.tif")
except:
    print("Error opening image")

multiply = 5                                       #how much bigger
processing = tuple([multiply*x for x in im.size])  #maths
saved = (r"c:\temp\biggerfile.tif")               #save location

imB = im.resize((processing))                      #resizing

imB.save(saved)                                    #saving
Run Code Online (Sandbox Code Playgroud)

我需要调整TIFF的大小,因为我正在使用tesseract-ocr,并调整图像大小以获得更好的输出.该程序似乎与TIFF一起使用效果最佳.

我收到的错误是:

_TIFFVSetField: c:\temp\biggerfile.tif: Bad value 2 for "ExtraSamples" tag.
Traceback (most recent call last):
  File "step1.py", line 15, in <module>
    imB.save(saved)
  File "C:\Python34\lib\site-packages\PIL\Image.py", line 1684, in save
    save_handler(self, fp, filename)
  File "C:\Python34\lib\site-packages\PIL\TiffImagePlugin.py", line …
Run Code Online (Sandbox Code Playgroud)

python python-imaging-library pillow

11
推荐指数
1
解决办法
1015
查看次数

标签 统计

pillow ×1

python ×1

python-imaging-library ×1