-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresize_image.py
25 lines (19 loc) · 968 Bytes
/
resize_image.py
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
from PIL import Image
import os
# This file is used to resize the images to the same size, for overleaf paper.
def resize_images(input_folder, output_folder, target_size=(640, 480)):
if not os.path.exists(output_folder):
os.makedirs(output_folder)
for filename in os.listdir(input_folder):
if filename.lower().endswith(('.png', '.jpg', '.jpeg')):
with Image.open(os.path.join(input_folder, filename)) as img:
if img.mode != 'RGB':
img = img.convert('RGB')
resized_img = img.resize(target_size, Image.Resampling.LANCZOS)
# save images
output_path = os.path.join(output_folder, filename)
resized_img.save(output_path, quality=95)
print(f"处理完成: {filename}")
input_folder = "D:\桌面\image"
output_folder = "D:\桌面\imagess"
resize_images(input_folder, output_folder)