-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresize.py
More file actions
28 lines (22 loc) · 916 Bytes
/
resize.py
File metadata and controls
28 lines (22 loc) · 916 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
28
from PIL import Image
from pathlib import Path
# Set folder path
input_folder = Path('./data/backdrops')
output_folder = input_folder / 'converted'
# Create output folder if it doesn't exist
output_folder.mkdir(parents=True, exist_ok=True)
# Supported formats
valid_extensions = ['.jpg', '.jpeg', '.png']
resize_size = (1920, 1080)
for input_path in input_folder.iterdir():
if input_path.suffix.lower() in valid_extensions:
base_name = input_path.stem
output_path = output_folder / f"{base_name}.avif"
try:
with Image.open(input_path) as img:
img = img.convert("RGB")
img = img.resize(resize_size)
img.save(output_path, format='AVIF', lossless=True)
print(f"Converted: {input_path.name} → {output_path.name}")
except Exception as e:
print(f"Failed to process {input_path.name}: {e}")