|
import os |
|
from PIL import Image |
|
|
|
def resize_images(directory): |
|
|
|
output_dir = os.path.join(directory, 'resized_images') |
|
if not os.path.exists(output_dir): |
|
os.makedirs(output_dir) |
|
|
|
|
|
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: |
|
|
|
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}") |
|
|
|
|
|
directory_path = 'real_images' |
|
resize_images(directory_path) |