from PIL import Image import os # 设置图片路径和分辨率 input_path = "input_folder" output_path = "output_folder" resolution = (1280, 720) # 循环处理图片 for filename in os.listdir(input_path): # 忽略非图片文件 if not filename.lower().endswith(('.png', '.jpg', '.jpeg', '.bmp')): continue # 打开原始图像文件 with Image.open(os.path.join(input_path, filename)) as img: # 调整分辨率 img_resized = img.resize(resolution) # 保存调整后的图像文件 output_filename = os.path.join(output_path, filename) img_resized.save(output_filename) print(f"已保存:{output_filename}")
标签:img,批量,python,分辨率,filename,output,path,os,input From: https://www.cnblogs.com/dashenblog/p/17208163.html