#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""把 12 组「作者原图 vs 即梦复现」拼成一张联络表，便于一次性目视核对。"""
import glob, json, os
from PIL import Image, ImageDraw

B = "/home/zyw/Downloads/dl-hub/85-AI生图提示词知识库-桀克AIShotLab"
batch = json.load(open(B + "/07-即梦复现对比/prompts/batch.json", encoding="utf-8"))
pair = json.load(open(B + "/_data/repro_pair.json", encoding="utf-8"))
rmap = json.load(open(B + "/_data/repro_map.json", encoding="utf-8"))
TH = B + "/08-插图版HTML/thumbs"
RP = B + "/08-插图版HTML/repro"

CW, CH = 420, 300
cols, rows = 4, 6           # 4 列 × (作者/即梦) 6 行
sheet = Image.new("RGB", (CW * cols, (CH + 22) * rows), (18, 19, 26))
d = ImageDraw.Draw(sheet)

def fit(p, w, h):
    im = Image.open(p).convert("RGB")
    r = min(w / im.width, h / im.height)
    im = im.resize((max(1, int(im.width * r)), max(1, int(im.height * r))), Image.LANCZOS)
    bg = Image.new("RGB", (w, h), (8, 8, 12))
    bg.paste(im, ((w - im.width) // 2, (h - im.height) // 2))
    return bg

for k, b in enumerate(batch):
    iid = b["iid"]
    r, c = divmod(k, cols)
    y = r * (CH + 22)
    a = pair.get(iid, {}).get("thumb")
    m = rmap.get(iid, {}).get("web")
    if a: sheet.paste(fit(os.path.join(TH, a), CW // 2 - 2, CH), (c * CW, y + 22))
    if m: sheet.paste(fit(os.path.join(RP, m), CW // 2 - 2, CH), (c * CW + CW // 2 + 2, y + 22))
    d.text((c * CW + 4, y + 5), "%s  %s" % (iid, b["cat"].split("-")[1]), fill=(255, 209, 102))
    d.text((c * CW + CW // 2 + 4, y + 5), "即梦5.0 (2K, %s)" % b["ratio"], fill=(120, 200, 240))

out = B + "/07-即梦复现对比/联络表-作者原图vs即梦复现.png"
sheet.save(out, "PNG")
print("→", out, sheet.size)
