Skip to content

Commit

Permalink
✨ Added script to resize images as part of postprocessing
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanZhouDev committed Dec 27, 2024
1 parent cbb10fd commit 0b74841
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions resize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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)

0 comments on commit 0b74841

Please sign in to comment.