#!/usr/bin/env python3

from PIL import Image
import os

def resize_to_exact(input_path, output_path, target_size=(1080, 1080)):
    """Resize image to exact dimensions"""
    try:
        with Image.open(input_path) as img:
            # Resize to exact dimensions (this will stretch slightly but ensure exact size)
            resized_img = img.resize(target_size, Image.Resampling.LANCZOS)
            resized_img.save(output_path, "PNG")
            print(f"✅ Image resized to {target_size[0]}x{target_size[1]} and saved to {output_path}")
            return resized_img.size
    except Exception as e:
        print(f"❌ Error resizing image: {str(e)}")
        return None

if __name__ == "__main__":
    input_file = "/Users/igloo/.openclaw/workspace/scratch/creative-meme-bald.png"
    output_file = "/Users/igloo/.openclaw/workspace/scratch/creative-meme-bald.png"  # Overwrite
    
    if os.path.exists(input_file):
        final_size = resize_to_exact(input_file, output_file)
        if final_size == (1080, 1080):
            print("✅ Image is now exactly 1080x1080 as required")
        else:
            print(f"⚠️  Unexpected size: {final_size}")
    else:
        print(f"❌ Input file not found: {input_file}")