图:python实现批量为图片添加边框
一、案例
大量图片需要统一设置图片边框,用制图工具一个一个进行添加的话,工作效率太低,用python批量为图片添加边框
二、python代码
from PIL import Image, ImageOps
import os
def add_borders(input_folder, output_folder, border_size, border_color):
# Ensure the output folder exists
os.makedirs(output_folder, exist_ok=True)
# List all image files in the input folder
image_files = [file for file in os.listdir(input_folder) if file.lower().endswith(('.png', '.jpg', '.jpeg', '.gif', '.bmp'))]
for image_file in image_files:
input_path = os.path.join(input_folder, image_file)
output_path = os.path.join(output_folder, image_file)
# Open the image using