-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess_sample.py
More file actions
31 lines (24 loc) · 877 Bytes
/
process_sample.py
File metadata and controls
31 lines (24 loc) · 877 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
29
30
31
from PIL import Image
import os
# Paths
INPUT_PATH = ""
OUTPUT_PATH = ""
def process_image():
if not os.path.exists(INPUT_PATH):
print(f"Error: Input file not found at {INPUT_PATH}")
return
try:
with Image.open(INPUT_PATH) as img:
# 1. Convert to Grayscale
img_gray = img.convert("L")
# 2. Resize to 320x180
# We use LANCZOS for high quality downsampling
img_resized = img_gray.resize((320, 180), Image.Resampling.LANCZOS)
# 3. Save
img_resized.save(OUTPUT_PATH)
print(f"Successfully processed and saved to {OUTPUT_PATH}")
print(f"Format: {img_resized.mode}, Size: {img_resized.size}")
except Exception as e:
print(f"Error processing image: {e}")
if __name__ == "__main__":
process_image()