# -*- coding: utf-8 -*-
"""Genereaza imagini OG 1200x630 pentru toate paginile site-ului."""
import os
from PIL import Image

BASE = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
POZE = os.path.join(BASE, "assets", "poze-blog")

JOBS = [
    ("hola-alicante-plaja.jpg", "hola-alicante-og.jpg"),
    ("alicante-familie.jpg", "noul-acasa-og.jpg"),
    ("povestea-mea.jpg", "povestea-mea-og.jpg"),
    ("eveniment13.jpg", "eveniment-og.jpg"),
    ("povestea-mea6.jpg", "og-default.jpg"),
    (os.path.join("..", "portofoliu", "manu-1.png"), "portfolio-og.jpg"),
]

W, H = 1200, 630
for src_name, dst_name in JOBS:
    src = os.path.join(POZE, src_name)
    img = Image.open(src).convert("RGB")
    ratio = max(W / img.width, H / img.height)
    resized = img.resize((round(img.width * ratio), round(img.height * ratio)), Image.LANCZOS)
    left = (resized.width - W) // 2
    top = (resized.height - H) // 2
    out = resized.crop((left, top, left + W, top + H))
    dst = os.path.join(POZE, dst_name)
    out.save(dst, "JPEG", quality=85, optimize=True)
    print(dst_name, out.size, os.path.getsize(dst) // 1024, "KB")
