#!/bin/bash

# Set source and destination directories
SOURCE_DIR="alliance"
DEST_DIR="alliance_small"

# Create destination directory if it doesn't exist
mkdir -p "$DEST_DIR"

# Set target dimensions (224x224 is common for many AI image classifiers)
TARGET_SIZE="224x224"

# Find all JPG files in the source directory (case insensitive)
find "$SOURCE_DIR" -type f -iname "*.jpg" | while read -r file; do
    # Determine the target path
    rel_path="${file#$SOURCE_DIR/}"
    target_file="$DEST_DIR/$rel_path"
    
    # Create target directory structure if it doesn't exist
    target_dir=$(dirname "$target_file")
    mkdir -p "$target_dir"
    
    # Check if target file already exists
    if [ ! -f "$target_file" ]; then
        echo "Resizing: $file -> $target_file"
        
        # Use ImageMagick to resize the image
        # maintain aspect ratio with ^ and then center crop with -gravity center -extent
        convert "$file" -resize "$TARGET_SIZE^" -gravity center -extent "$TARGET_SIZE" "$target_file"
    else
        echo "Skipping: $target_file (already exists)"
    fi
done

echo "Resizing complete!"
