forked from devmalik7/Code_Script
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresize_images.py
More file actions
21 lines (19 loc) · 901 Bytes
/
Copy pathresize_images.py
File metadata and controls
21 lines (19 loc) · 901 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import os
from PIL import Image
def batch_resize_images(input_folder, output_folder, target_width, target_height):
if not os.path.exists(output_folder):
os.makedirs(output_folder)
# Process only JPG, JPEG, PNG files
for filename in os.listdir(input_folder):
if filename.lower().endswith(('.png', '.jpg', '.jpeg')):
input_path = os.path.join(input_folder, filename)
output_path = os.path.join(output_folder, filename)
try:
with Image.open(input_path) as img:
img_resized = img.resize((target_width, target_height))
img_resized.save(output_path)
print(f"Resized: {filename}")
except Exception as e:
print(f"Error processing {filename}: {e}")
# Example usage
# batch_resize_images("input_folder_path", "output_folder_path", 800, 600)