python批量处理图片设置分辨率

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}")

  

posted @ 2023-03-12 14:47  无恙大势  阅读(225)  评论(0)    收藏  举报