from pathlib import Path
from PIL import Image

CANVAS = (3840, 2160)
BG = (255, 255, 255)
MARGIN_X = 120
MARGIN_Y = 120

sources = [
    Path('/home/ubuntu/autonomize_final/diagrams/master_logical_architecture.png'),
    Path('/home/ubuntu/autonomize_final/diagrams/aws_deployment_architecture.png'),
    Path('/home/ubuntu/autonomize_final/diagrams/uc2_referral_matching.png'),
    Path('/home/ubuntu/autonomize_final/diagrams/uc5_claims_ingestion.png'),
    Path('/home/ubuntu/autonomize_final/diagrams/reuse_and_roadmap.png'),
    Path('/home/ubuntu/autonomize_final/charts/value_vs_lift.png'),
    Path('/home/ubuntu/autonomize_final/charts/weighted_priority.png'),
]

for src in sources:
    img = Image.open(src).convert('RGB')
    max_w = CANVAS[0] - 2 * MARGIN_X
    max_h = CANVAS[1] - 2 * MARGIN_Y
    scale = min(max_w / img.width, max_h / img.height)
    new_size = (max(1, round(img.width * scale)), max(1, round(img.height * scale)))
    resized = img.resize(new_size, Image.Resampling.LANCZOS)
    canvas = Image.new('RGB', CANVAS, BG)
    x = (CANVAS[0] - resized.width) // 2
    y = (CANVAS[1] - resized.height) // 2
    canvas.paste(resized, (x, y))
    out = src.with_name(src.stem + '_4k.png')
    canvas.save(out, 'PNG', optimize=True)
    print(f'{out}: {canvas.size}')
