import os
from PIL import Image

def crea_versione_mobile():
    file_originale = "hero.webp"
    file_mobile = "hero-mobile.webp"
    
    if os.path.exists(file_originale):
        with Image.open(file_originale) as img:
            # Calcola l'altezza proporzionale mantenendo l'aspetto
            width_mobile = 480
            aspect_ratio = img.height / img.width
            height_mobile = int(width_mobile * aspect_ratio)
            
            # Ridimensiona
            img_small = img.resize((width_mobile, height_mobile), Image.Resampling.LANCZOS)
            
            # Salva
            img_small.save(file_mobile, quality=80)
            print(f"Fatto! Creato {file_mobile} ({width_mobile}x{height_mobile})")
    else:
        print(f"Errore: Non trovo il file {file_originale}")

if __name__ == "__main__":
    crea_versione_mobile()
