python - 将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'
我错过了什么?
解决方案
要转换,试试这个
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
推荐阅读
- ios - 如何在 ARKit 中放置自定义对象(.scn)?
- javascript - 如何跟踪消息的反应次数?
- linux - 在长时间的进程中保留 root 权限
- php - 删除或更新行后如何使用分页更新 laravel 缓存(redis 驱动程序)
- java - 递归 Json 节点更新
- opencv - opencv 中是否有相当于 skimages 的分段仿射变换?
- javascript - Woocommerce 在结帐页面触发“订单审核”更新
- python - 设置 django admin 显示数据库的所有列
- c# - 高级渐进难度怪物生成器
- php - PHP 在 fetch_all() 和 fetch_array() 之间分配获取结果