~/snippets/resize-multiple-images
Published on

Resize Multiple Images

211 words2 min read

Batch Image Resizer

This script resizes all images in a folder to a specified width and height using Python Pillow, useful for automation in web or ML projects.


šŸ”§ Setup

Install required package:

pip install pillow
from PIL import Image
import os

input_folder = 'input_images'
output_folder = 'resized_images'
new_size = (300, 300)

if not os.path.exists(output_folder):
    os.makedirs(output_folder)

for filename in os.listdir(input_folder):
    if filename.endswith(('.png', '.jpg', '.jpeg')):
        img = Image.open(os.path.join(input_folder, filename))
        img_resized = img.resize(new_size)
        img_resized.save(os.path.join(output_folder, filename))

print(f"All images resized to {new_size} and saved to '{output_folder}' folder.")