将图像保存为缩略图Python

将图像保存为缩略图Python,python,Python,我有这个代码,它最初来自这里: 我从这里向函数添加了缩略图另存为: 我试图从目录结构中选择所有文件,并根据文件结构重命名它们。我已经添加了一个使用“in”的过滤器,但是我无法使调整大小为缩略图的部分正常工作 未定义图像的名称 import os import shutil #testing import sys import image def image_thumb_filter(): size = 128, 128 for path, dirs, files in os.walk(wd)

我有这个代码,它最初来自这里: 我从这里向函数添加了缩略图另存为:

我试图从目录结构中选择所有文件,并根据文件结构重命名它们。我已经添加了一个使用“in”的过滤器,但是我无法使调整大小为缩略图的部分正常工作

未定义图像的名称

import os
import shutil
#testing
import sys
import image


def image_thumb_filter():
size = 128, 128
for path, dirs, files in os.walk(wd):
  for file in files:
    if file.endswith(".jpg"):
      src = os.path.join(path, file) 
      #print(src)
      dst = os.path.join(os.getcwd(), "Photo_selection")
      if not os.path.exists(dst): #Checks 'Photos_mirror' folder exists 
otherwise creates
        os.makedirs(dst)
      new_name = src.replace(wd+'\\', '').replace('\\', '_')
      new_dst = os.path.join(dst, new_name + "_thumb")
      if not os.path.isfile(new_dst):
        if "99\\526" in src:
             try:
               im = image.open(src)
               im.thumbnail(size)
               im.save(new_dst, "JPEG")
             except IOError:
               print ("cannot create thumbnail for", infile)            
  shutil.copy(src, dst)
  old_dst = os.path.join(dst, file)
              #Assuming your /dir/dir/... structure is inside of your working 
  directory (wd)
  os.rename(old_dst, new_dst)
  else: # it doesn't like this else statement
   continue  
  image_thumb_filter()  

您没有在代码中的任何地方专门定义对象“图像”。请记住,Python和许多其他语言都区分大小写。也许你的意思是“图像?”

哪些语言不区分大小写?我已经编辑了代码,但仍然不起作用。。。。我要求。。。pip安装映像。。。pilow,django,olefile,pytz,返回:Traceback(最近一次调用last):文件“”,第1行,在ModuleNotFoundError中:没有名为'image'@Holloway的模块-SQL在某些地方甚至不区分大小写?表名等?