-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscratch_11.py
More file actions
27 lines (21 loc) · 961 Bytes
/
Copy pathscratch_11.py
File metadata and controls
27 lines (21 loc) · 961 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from PIL import Image, ImageOps
import os
# 指定源文件夹和目标文件夹
source_folder = r'.\inputs' # 替换为源文件夹路径
target_folder = r'.\outputs' # 替换为目标文件夹路径
# 确保目标文件夹存在,如果不存在则创建
if not os.path.exists(target_folder):
os.makedirs(target_folder)
# 遍历源文件夹中的所有文件
for filename in os.listdir(source_folder):
if filename.lower().endswith('.jpg'):
# 构建完整的文件路径
source_file = os.path.join(source_folder, filename)
target_file = os.path.join(target_folder, filename.split(".")[0]+"_mirror.jpg")
# 打开图片文件
with Image.open(source_file) as img:
# 创建左右镜像的图片
mirrored_img = ImageOps.mirror(img)
# 保存镜像后的图片到目标文件夹
mirrored_img.save(target_file)
print(f'Processed {filename} successfully.')