"""Side-by-side comparison panel: full views on top, 1:1 crops of one region below. usage: panel.py OUT.png "x,y,w,h" LABEL=IMG [LABEL=IMG ...] The crop box is in the coordinates of the first image; others are scaled to its size for the full view and cropped at the same relative position for the 1:1 row. """ import sys from PIL import Image, ImageDraw, ImageFont out, box = sys.argv[1], [int(v) for v in sys.argv[2].split(",")] items = [a.split("=", 1) for a in sys.argv[3:]] ims = [(label, Image.open(path).convert("RGB")) for label, path in items] W0, H0 = ims[0][1].size thumb_w = 600 font = ImageFont.load_default() x, y, w, h = box rows = [] for label, im in ims: sx, sy = im.size[0] / W0, im.size[1] / H0 crop = im.crop((int(x * sx), int(y * sy), int((x + w) * sx), int((y + h) * sy))) crop = crop.resize((w, h), Image.LANCZOS) if crop.size != (w, h) else crop full = im.resize((thumb_w, int(thumb_w * H0 / W0)), Image.LANCZOS) d = ImageDraw.Draw(full) d.rectangle([x / W0 * thumb_w, y / H0 * full.size[1], (x + w) / W0 * thumb_w, (y + h) / H0 * full.size[1]], outline=(255, 60, 0), width=2) rows.append((label + f" ({im.size[0]}x{im.size[1]})", full, crop)) col_w = max(thumb_w, w) H = max(r[1].size[1] for r in rows) + h + 40 panel = Image.new("RGB", (col_w * len(rows) + 8 * (len(rows) - 1), H), (20, 20, 20)) for i, (label, full, crop) in enumerate(rows): ox = i * (col_w + 8) ImageDraw.Draw(panel).text((ox + 4, 4), label, fill=(240, 240, 240), font=font) panel.paste(full, (ox, 20)) panel.paste(crop, (ox, 20 + full.size[1] + 16)) panel.save(out) print("saved", out, panel.size)