StreetView360X / resize.py
everettshen's picture
Upload 14 files
d7b4a46 verified
import os
from PIL import Image
def resize_images(directory):
# Directory where the resized images will be saved
output_dir = os.path.join(directory, 'resized_images')
if not os.path.exists(output_dir):
os.makedirs(output_dir)
# Image extensions to look for
valid_extensions = ('.jpg', '.jpeg', '.png', '.gif', '.tiff', '.bmp')
for filename in os.listdir(directory):
if filename.lower().endswith(valid_extensions):
original_path = os.path.join(directory, filename)
resized_path = os.path.join(output_dir, filename)
try:
with Image.open(original_path) as img:
# Resize the image
img = img.resize((1536, 768), Image.LANCZOS)
img.save(resized_path)
print(f"Resized and saved {filename} to {resized_path}")
except Exception as e:
print(f"Error processing {filename}: {e}")
# Replace '/path/to/your/directory' with the path to the directory containing your images
directory_path = 'real_images'
resize_images(directory_path)