72 lines
2.4 KiB
Python
72 lines
2.4 KiB
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
from PIL import Image, ImageDraw, ImageFont
|
|
|
|
|
|
REPO_ROOT = Path(__file__).resolve().parents[1]
|
|
OUTPUT_DIR = REPO_ROOT / "public" / "branding" / "taonier-logo-clay-mascot-concepts"
|
|
CONTACT_SHEET_PATH = OUTPUT_DIR / "taonier-logo-clay-mascot-contact-sheet.png"
|
|
|
|
ITEMS = [
|
|
("01 陶泥小人", "taonier-clay-mascot-little-maker.png"),
|
|
("02 陶泥手办", "taonier-clay-mascot-figurine-token.png"),
|
|
("03 软陶团子", "taonier-clay-mascot-soft-doll.png"),
|
|
("04 造物泥偶", "taonier-clay-mascot-creator-totem.png"),
|
|
("05 陶泥面偶", "taonier-clay-mascot-idol-mask.png"),
|
|
("06 口袋泥人", "taonier-clay-mascot-pocket-figure.png"),
|
|
]
|
|
|
|
|
|
def load_font(size: int) -> ImageFont.FreeTypeFont | ImageFont.ImageFont:
|
|
candidates = [
|
|
Path("C:/Windows/Fonts/msyh.ttc"),
|
|
Path("C:/Windows/Fonts/simhei.ttf"),
|
|
Path("C:/Windows/Fonts/simsun.ttc"),
|
|
]
|
|
for candidate in candidates:
|
|
if candidate.exists():
|
|
return ImageFont.truetype(str(candidate), size)
|
|
return ImageFont.load_default()
|
|
|
|
|
|
def main() -> None:
|
|
cell_size = 330
|
|
label_height = 58
|
|
gap = 28
|
|
columns = 3
|
|
rows = 2
|
|
width = columns * cell_size + (columns + 1) * gap
|
|
height = rows * (cell_size + label_height) + (rows + 1) * gap
|
|
|
|
sheet = Image.new("RGB", (width, height), "#eee9df")
|
|
draw = ImageDraw.Draw(sheet)
|
|
font = load_font(24)
|
|
|
|
for index, (label, filename) in enumerate(ITEMS):
|
|
row = index // columns
|
|
column = index % columns
|
|
x = gap + column * (cell_size + gap)
|
|
y = gap + row * (cell_size + label_height + gap)
|
|
|
|
source = Image.open(OUTPUT_DIR / filename).convert("RGB")
|
|
thumbnail = source.resize((cell_size, cell_size), Image.Resampling.LANCZOS)
|
|
sheet.paste(thumbnail, (x, y))
|
|
draw.rounded_rectangle(
|
|
(x, y + cell_size, x + cell_size, y + cell_size + label_height),
|
|
radius=10,
|
|
fill="#fffdf8",
|
|
)
|
|
text_box = draw.textbbox((0, 0), label, font=font)
|
|
text_x = x + (cell_size - (text_box[2] - text_box[0])) / 2
|
|
text_y = y + cell_size + (label_height - (text_box[3] - text_box[1])) / 2 - 2
|
|
draw.text((text_x, text_y), label, fill="#302a25", font=font)
|
|
|
|
sheet.save(CONTACT_SHEET_PATH, quality=95)
|
|
print(CONTACT_SHEET_PATH)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|