# Copie delle immagini degli eventi per le varianti eventi2-a/b/c, eventi3 e tornei3 (lane MOCKUP-EVENTI-2, 30/10). Mockup.
# Regola IMMAGINI-MINIATURE01 (Owner 30/10): ogni immagine in una carta e una copia ~2x della misura mostrata, fatta UNA volta con Lanczos,
# stesso ritaglio centrato (object-fit cover); se la fonte e piu piccola del 2x si tiene la misura della fonte (mai ingrandire).
# Fonti in src/ (copiate da eventi-l3-img/src): arte larga ufficiale Steam (library_hero_2x 3840x1240) e foto Unsplash 3840 = simulazione
# dell'immagine che il gestore mette sull'evento (event.image / background, sempre UNA immagine larga).
import os
from PIL import Image
HERE = os.path.dirname(os.path.abspath(__file__)); SRC = os.path.join(HERE, 'src')
KEYS = ['chill', 'doom', 'gta', 'mhw', 'pubg', 'dbd', 'retro', 'rl', 'cs2', 'lol', 'valo', 'apex', 'dota']
# misure MOSTRATE a 2560x1440: A grande e fila, B evidenziato e righe, C biglietto e portafoglio, scheda comune
SIZES = [('hero', 2358, 640), ('card', 432, 243), ('wide', 2038, 320), ('row', 228, 128), ('tk', 552, 480), ('tks', 552, 132), ('sheet', 1160, 652), ('c3', 552, 310), ('t3', 2358, 360)]   # c3 = carta di eventi3, t3 = riga di tornei3
def cover(im, w, h):
    r = w / h; W, H = im.size
    if W / H > r: cw, ch = round(H * r), H
    else: cw, ch = W, round(W / r)
    x, y = (W - cw) // 2, (H - ch) // 2
    crop = im.crop((x, y, x + cw, y + ch))
    tw, th = (w * 2, h * 2) if cw >= w * 2 else (cw, ch)   # mai ingrandire
    return crop.resize((tw, th), Image.LANCZOS)
for key in KEYS:
    land = Image.open(os.path.join(SRC, f'{key}-land.jpg')).convert('RGB')
    for name, w, h in SIZES:
        out = cover(land, w, h)
        out.save(os.path.join(HERE, f'{key}-{name}.jpg'), quality=84, optimize=True, progressive=True)
        print(key, name, f'{w}x{h}', '->', out.size, f'{out.size[0] / w:.2f}x')
