使用python模块将图像从tifs转换为JPEG时,如何将图像保存到新目录?

使用python模块将图像从tifs转换为JPEG时,如何将图像保存到新目录?,python,python-imaging-library,Python,Python Imaging Library,我正在尝试将大量.tif图像转换为.jpgs,但似乎无法解决如何将这些新创建的.jpgs保存到新目录中的问题。这是我的代码: from PIL import Image os.chdir('C:\\Users\\kmh250\\Desktop') os.getcwd() destination = 'C:\\Users\\kmh250\\testfolder' def get_photos(): list = [os.path.join('31735073107447'), os.pa

我正在尝试将大量.tif图像转换为.jpgs,但似乎无法解决如何将这些新创建的.jpgs保存到新目录中的问题。这是我的代码:

from PIL import Image

os.chdir('C:\\Users\\kmh250\\Desktop')
os.getcwd()
destination = 'C:\\Users\\kmh250\\testfolder'
def get_photos():
    list = [os.path.join('31735073107447'), os.path.join('31735073107033')]
    for i in list:
        for root, dirs, files in os.walk(i):
            for name in files:
                print(os.path.join(root, name))
                if os.path.splitext(os.path.join(root, name))[1].lower() == ".tif":
                    outfile = os.path.splitext(os.path.join(destination, name))[0] + ".jpg"
                    im = Image.open(os.path.join(root, name))
                    print ("Generating jpeg for %s" % name)
                    im.thumbnail(im.size)
                    im.save(outfile, "JPEG", quality=100)```

And this is the error I receive: 
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\kmh250\\testfolder\\0001.jpg'

I get that this has something to do with the outfile variable, but I can't seem to figure out how to fix the problem. Many thanks to any and all suggestions! 



这回答了你的问题吗?