python tif转jpg_无法将tiff图像转换为jpg
我試圖創建一個簡單的腳本,將目錄中的所有tiff圖像轉換為jpg,但我得到以下錯誤:cannot write mode RGBA as JPEG
我的代碼是:import os
from PIL import Image
yourpath = os.getcwd()
for root, dirs, files in os.walk(yourpath, topdown=False):
for name in files:
print(os.path.join(root, name))
if os.path.splitext(os.path.join(root, name))[1].lower() == ".tiff":
if os.path.isfile(os.path.splitext(os.path.join(root, name))[0] + ".jpg"):
print ("A jpeg file already exists for %s" % name)
# If a jpeg is *NOT* present, create one from the tiff.
else:
outfile = os.path.splitext(os.path.join(root, name))[0] + ".jpg"
try:
im = Image.open(os.path.join(root, name))
print ("Generating jpeg for %s" % name)
im.thumbnail(im.size)
im.save(outfile, "JPEG", quality=100)
except Exception as e:
print (e)
你知道怎么修嗎?在
總結
以上是生活随笔為你收集整理的python tif转jpg_无法将tiff图像转换为jpg的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python + Opencv 实现图像
- 下一篇: 【无为则无心Python基础】— 18、