错误:姓名'图片'没有定义的

时间:2017-08-06 07:35:41

标签: python-3.x numpy python-imaging-library

我试图将所有图像转置到文件夹中并尝试执行此代码:

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.

请帮忙。谢谢!!

1 个答案:

答案 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')