Image Resizer
Image Resizer Tool
Width: Height: Resize
<script src="script.js"></script>
from PIL import Image
import os
def resize_image(input_path, output_path, size):
“””
Resize an image to the given size.
:param input_path: Path to the input image
:param output_path: Path to save the resized image
:param size: Tuple of (width, height)
"""
with Image.open(input_path) as img:
img = img.resize(size, Image.ANTIALIAS)
img.save(output_path)
print(f"Image saved to {output_path}")
def resize_images_in_directory(input_dir, output_dir, size):
“””
Resize all images in a directory to the given size.
:param input_dir: Directory containing images to resize
:param output_dir: Directory to save resized images
:param size: Tuple of (width, height)
"""
if not os.path.exists(output_dir):
os.makedirs(output_dir)
for filename in os.listdir(input_dir):
input_path = os.path.join(input_dir, filename)
output_path = os.path.join(output_dir, filename)
try:
resize_image(input_path, output_path, size)
except Exception as e:
print(f"Error resizing image {input_path}: {e}")
Example usage:
input_dir = ‘path/to/input/images’
output_dir = ‘path/to/output/images’
size = (800, 600) # Resize to 800×600 pixels
resize_images_in_directory(input_dir, output_dir, size)