我试图将所有图像转置到文件夹中并尝试执行此代码:
import os
import glob
path = 'C:/Users/mail2/Desktop/flippin/pics/'
i = 0
for infile in glob.glob( os.path.join(path, '*.jpg') ):
img = Image.open(infile)
print ("current file is: " + infile)
img.transpose(Image.FLIP_LEFT_RIGHT)
img.transpose(Image.FLIP_TOP_BOTTOM)
img.transpose(
Image.FLIP_LEFT_RIGHT).transpose(
Image.FLIP_TOP_BOTTOM).save("combined%s.jpg")
print('done')
但我得到了name 'image' not defined error.
请帮忙。谢谢!!
答案 0 :(得分:1)
这是因为您没有定义Image
来执行此操作只需从Image
模块导入PIL
。要完成此操作,只需在代码中添加以下代码:from PIL import Image
:
import os
from PIL import Image
import glob
path = 'C:/Users/mail2/Desktop/flippin/pics/' i = 0
for infile in glob.glob( os.path.join(path, '*.jpg') ):
img = Image.open(infile)
print ("current file is: " + infile)
img.transpose(Image.FLIP_LEFT_RIGHT)
img.transpose(Image.FLIP_TOP_BOTTOM)
img.transpose(
Image.FLIP_LEFT_RIGHT).transpose(
Image.FLIP_TOP_BOTTOM).save("combined%s.jpg")
print('done')