Spaces:
Sleeping
Sleeping
File size: 705 Bytes
f8c0ae2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
from PIL import Image
import os
def resize_image(image_path, output_path, size=(100, 100)):
with Image.open(image_path) as img:
img.thumbnail(size)
img.save(output_path, quality=85)
# Directory where your images are stored
image_dir = 'images/'
# Output directory for resized images
output_dir = 'resized_images/'
os.makedirs(output_dir, exist_ok=True)
# Resize all images in the directory
for image_file in os.listdir(image_dir):
if image_file.endswith(('png', 'jpg', 'jpeg')):
input_path = os.path.join(image_dir, image_file)
output_path = os.path.join(output_dir, image_file)
resize_image(input_path, output_path)
print("Image resizing complete.")
|