Datasets:
File size: 1,699 Bytes
ff62a89 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | # -*- coding: utf-8 -*-
"""P.AI Extension: Multi-Image Studio (Plain Python, MIT License)."""
from __future__ import annotations
from pathlib import Path
from typing import Iterable, Tuple
from PIL import Image, ImageDraw, ImageOps
EXTENSION_META = {
"id": "multi_image_studio",
"name": "Multi-Image Studio",
"version": "1.0.0",
"category": "Workflow",
"workflow_id": "multi_image_studio",
}
def build_multi_reference_board(
image_paths: Iterable[str | Path],
*,
tile_size: int = 512,
padding: int = 16,
bg_color: Tuple[int, int, int] = (18, 22, 30),
) -> Image.Image:
"""Combine 1-4 reference images into a clean numbered reference board (① ② ③ ④)."""
imgs = []
for p in list(image_paths)[:4]:
with Image.open(p) as im:
imgs.append(ImageOps.fit(ImageOps.exif_transpose(im).convert("RGB"), (tile_size, tile_size), Image.Resampling.LANCZOS))
if not imgs:
raise ValueError("At least one image is required.")
cols = min(len(imgs), 2)
rows = (len(imgs) + cols - 1) // cols
board_w = cols * tile_size + (cols + 1) * padding
board_h = rows * tile_size + (rows + 1) * padding
board = Image.new("RGB", (board_w, board_h), bg_color)
draw = ImageDraw.Draw(board)
badges = ("1", "2", "3", "4")
for idx, im in enumerate(imgs):
r, c = divmod(idx, cols)
x0 = padding + c * (tile_size + padding)
y0 = padding + r * (tile_size + padding)
board.paste(im, (x0, y0))
draw.rounded_rectangle((x0 + 10, y0 + 10, x0 + 44, y0 + 44), radius=10, fill=(59, 118, 246))
draw.text((x0 + 23, y0 + 20), badges[idx], fill=(255, 255, 255))
return board
|