![](/img/trans.png)
[英]Using Pillow's Image.save() function throws an AttributeError when trying to download an image from a page using Splinter
[英]Why using Image.save() (from Pillow in Python) with variables is not working?
在 Python 課程中,我必須編寫一個腳本來將一堆圖像(格式(.tiff)和大小錯誤)轉換為“.jpeg”,並將它們以相同的名稱保存到另一個文件夾中!
問題是它不會使用路徑 + 文件變量 + 圖像格式將它保存到我想要的目錄(即使在同一目錄中)。 我也使用了 os.path.join() 方法,但它也不起作用。 我設法做了幾次,但不在我想要的目錄中。 你能給我一些建議嗎? 謝謝!
#!/usr/bin/env python3
from PIL import Image
import os
files = os.listdir('/home/dani/images')
if not os.path.exists('/home/dani/images/opt/icons'):
os.makedirs('/home/dani/images/opt/icons')
for file in files[1:]:
if not os.path.isdir('/home/dani/images/'+ file):
im = Image.open('/home/dani/images/'+file)
im.convert('RGB').rotate(-90).resize((128,\
128)).save('/home/dani/images/opt/icons/'+file +'.jpeg')
有時保存有權限問題。 嘗試將文件保存在您擁有 .py 文件的同一文件夾中。 如果保存在同一文件夾中有效,則問題是權限。 試試os.umask()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.