首页 > 解决方案 > 将bmp转换为tiff,python

问题描述

我正在尝试做一些简单的事情,我在每一篇解释如何在 python 中将 bmp 转换为 tiff 的帖子中都找到了这行代码,但我不确定会发生什么,tiff 图像永远不会发生。

from PIL import Image
img=Image.open('./data/x.bmp')
img.save('x.tiff','tiff') #TypeError: argument 3 must be str, not int
img.save('x.tiff') #TypeError: argument 3 must be str, not int
img.save('x.tiff','.tiff') #KeyError: '.TIFF'

我错过了什么?

标签: pythonpython-imaging-library

解决方案


要转换,试试这个

from PIL import Image

img = Image.open('./data/x.bmp').convert('RGB')
img.save('x.tiff', format='TIFF', compression='tiff_lzw')

更新:

如果失败,请检查您是否已libtiff正确安装

from PIL import features
print(features.check('libtiff'))   # True

推荐阅读