from PIL import Image
import os

def create_assets():
    source_path = 'logo.png'
    if not os.path.exists(source_path):
        print(f"Error: {source_path} not found.")
        return

    img = Image.open(source_path)

    # 1. Generate logo.ico
    # Ico format supports multiple sizes.
    icon_sizes = [(256, 256), (128, 128), (64, 64), (48, 48), (32, 32), (16, 16)]
    img.save('logo.ico', format='ICO', sizes=icon_sizes)
    print("Created logo.ico")

    # 2. Generate katta_rasm.bmp (WizardImageFile)
    # Standard size is often 164x314. We'll resize/crop to fit or just resize.
    # To keep aspect ratio and fill, we might need to be smart, but for now strict resize.
    # A better approach for a sidebar image is to center the logo on a white/colored background.
    # Let's create a 164x314 white background and paste the resized logo.
    
    wizard_image_size = (164, 314)
    # Resize logo to fit within width, keeping aspect ratio
    logo_w_ratio = 140 / img.width
    new_h = int(img.height * logo_w_ratio)
    logo_resized = img.resize((140, new_h), Image.Resampling.LANCZOS)
    
    wizard_img = Image.new('RGB', wizard_image_size, (255, 255, 255))
    # Center paste
    paste_x = (164 - 140) // 2
    paste_y = (314 - new_h) // 2
    
    # Handle transparency if png has alpha
    if len(logo_resized.split()) == 4:
         # Paste with mask
         wizard_img.paste(logo_resized, (paste_x, paste_y), logo_resized)
    else:
         wizard_img.paste(logo_resized, (paste_x, paste_y))
         
    wizard_img.save('katta_rasm.bmp')
    print("Created katta_rasm.bmp")

    # 3. Generate kichik_logotip.bmp (WizardSmallImageFile)
    # Standard size 55x58.
    small_size = (55, 58)
    small_img = Image.new('RGB', small_size, (255, 255, 255))
    
    # Resize logo to fit height/width
    ratio = 50 / max(img.width, img.height)
    new_small_w = int(img.width * ratio)
    new_small_h = int(img.height * ratio)
    logo_small = img.resize((new_small_w, new_small_h), Image.Resampling.LANCZOS)
    
    paste_small_x = (55 - new_small_w) // 2
    paste_small_y = (58 - new_small_h) // 2

    if len(logo_small.split()) == 4:
         small_img.paste(logo_small, (paste_small_x, paste_small_y), logo_small)
    else:
         small_img.paste(logo_small, (paste_small_x, paste_small_y))

    small_img.save('kichik_logotip.bmp')
    print("Created kichik_logotip.bmp")

if __name__ == "__main__":
    create_assets()
