import os
from PIL import Image
def crop_images_to_square(input_folder, output_folder):
# Create output folder if it doesn't exist
os.makedirs(output_folder, exist_ok=True)
# Loop through all files in the input folder
for filename in os.listdir(input_folder):
if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.gif', '.bmp')):
# Open image
img_path = os.path.join(input_folder, filename)
with Image.open(img_path) as img:
# Get dimensions
width, height = img.size
# Calculate the new size (the smaller dimension)
new_size = min(width, height)