-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscratch_10.py
More file actions
34 lines (25 loc) · 1.09 KB
/
Copy pathscratch_10.py
File metadata and controls
34 lines (25 loc) · 1.09 KB
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
28
29
30
31
32
33
34
from PIL import Image
import os
def crop_images(input_path, output_path):
# 确保输出路径存在,如果不存在则创建
if not os.path.exists(output_path):
os.makedirs(output_path)
# 遍历输入路径下的所有文件
for filename in os.listdir(input_path):
if filename.endswith('.png'):
print(filename)
# 构建完整的文件路径
input_image_path = os.path.join(input_path, filename)
output_image_path = os.path.join(output_path, filename)
# 打开图片
with Image.open(input_image_path) as img:
# 裁剪图片
cropped_img = img.crop((0, 0, 992, 1424))
# 保存裁剪后的图片到输出路径
cropped_img.save(output_image_path)
print("图片裁剪完成。")
# 输入和输出路径
input_images_path = r'I:\gwentcards\back1' # 替换为实际的输入路径
output_images_path = r'I:\gwentcards\croppedimages' # 替换为实际的输出路径
# 执行裁剪操作
crop_images(input_images_path, output_images_path)