Files
lingniu-vehicle-ingest/tmp/mileage-appeal-20260810/make_contact_sheet.py

29 lines
1.1 KiB
Python

import sys
from pathlib import Path
from PIL import Image, ImageDraw, ImageFont
source = Path(sys.argv[1]) if len(sys.argv) > 1 else Path("/Users/lingniu/project/ai-coding/lingniu-vehicle-ingest/outputs/019fe9b9-eb60-7d22-8c0a-c70851a48083/preview")
output = source / "contact-sheet.jpg"
files = sorted(source.glob("*.png"))
thumb_w, thumb_h = 620, 360
label_h = 34
cols = 2
rows = (len(files) + cols - 1) // cols
canvas = Image.new("RGB", (cols * thumb_w, rows * (thumb_h + label_h)), "white")
draw = ImageDraw.Draw(canvas)
font = ImageFont.load_default()
for index, file in enumerate(files):
image = Image.open(file).convert("RGB")
image.thumbnail((thumb_w - 12, thumb_h - 12))
x0 = (index % cols) * thumb_w
y0 = (index // cols) * (thumb_h + label_h)
x = x0 + (thumb_w - image.width) // 2
y = y0 + 6
canvas.paste(image, (x, y))
draw.rectangle((x0, y0, x0 + thumb_w - 1, y0 + thumb_h + label_h - 1), outline="#B7C9D6", width=1)
draw.text((x0 + 8, y0 + thumb_h + 8), file.stem, fill="#1F2937", font=font)
canvas.save(output, quality=88)
print(output)