【Python】:图像批量进行尺寸缩放

话不多说,直接看代码!

from PIL import Image
import os


fin = "C:\\Users\\Lenovo\\Desktop\\EXdark\\158"     # 输入图像所在路径
fout = "C:\\Users\\Lenovo\\Desktop\\EXdark\\158"    # 输出图像的路径

for file in os.listdir(fin):
    file_fullname = fin + '/' +file
    print(file_fullname)                            # 所操作图片的名称可视化
    img = Image.open(file_fullname)
    im_resized = img.resize((128, 128))             # resize至所需大小
    out_path = fout + '/' + file
    im_resized.save(out_path)                       # 保存图像

Guess you like

Origin blog.csdn.net/qq_42856191/article/details/121271760