28 lines
1.2 KiB
Python
28 lines
1.2 KiB
Python
from PIL import Image, ImageDraw, ImageFont
|
|
seats = [("丞相","e35483b1"),("中书","4e278758"),("尚书","2e65d691"),("门下","78223c4a"),("吏部","cf800860"),
|
|
("户部","82262be8"),("礼部","1f2aeec7"),("兵部","2ce3587b"),("刑部","57f94de8"),("工部","857831f9")]
|
|
crop = (772, 0, 1440, 900)
|
|
tw, th = 300, 397
|
|
cols, rows, pad, labelh = 5, 2, 10, 24
|
|
tiles = []
|
|
for i in range(1, 11):
|
|
im = Image.open(f"preview/seat-{i:02d}.png").convert("RGB").crop(crop).resize((tw, th))
|
|
tiles.append(im)
|
|
W = cols * tw + (cols + 1) * pad
|
|
H = rows * (th + labelh) + (rows + 1) * pad
|
|
canvas = Image.new("RGB", (W, H), "white")
|
|
d = ImageDraw.Draw(canvas)
|
|
try:
|
|
font = ImageFont.truetype("C:/Windows/Fonts/msyh.ttc", 15)
|
|
except Exception:
|
|
font = ImageFont.load_default()
|
|
for idx, (name, sid) in enumerate(seats):
|
|
r, c = idx // cols, idx % cols
|
|
x = pad + c * (tw + pad)
|
|
y = pad + r * (th + labelh + pad)
|
|
canvas.paste(tiles[idx], (x, y))
|
|
d.rectangle([x, y + th, x + tw, y + th + labelh], fill="#eef4ff")
|
|
d.text((x + 6, y + th + 4), f"{name} {sid}", fill="#1f2a3a", font=font)
|
|
canvas.save("preview/seats-contact.png")
|
|
print("saved", canvas.size)
|