-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathresize.py
36 lines (27 loc) · 1 KB
/
resize.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
26
27
28
29
30
31
32
33
34
35
36
from PIL import Image
import os
import sys
def get_resized_filename(input_path):
"""Generate output filename by adding '-resized' before extension"""
base, ext = os.path.splitext(input_path)
return f"{base}-resized{ext}"
def resize_image(input_path, scale=5):
"""Resize image by given scale factor using Lanczos resampling"""
try:
# Open and resize image
with Image.open(input_path) as img:
width, height = img.size
new_img = img.resize((width * scale, height * scale), Image.LANCZOS)
# Save resized image
output_path = get_resized_filename(input_path)
new_img.save(output_path)
print(f"Saved resized image to: {output_path}")
except Exception as e:
print(f"Error processing image: {e}")
sys.exit(1)
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python resize_image.py <image_path>")
sys.exit(1)
input_path = sys.argv[1]
resize_image(input_path)