from pathlib import Path from PIL import Image, ImageDraw, ImageFont ROOT = Path(r"C:\milimoe\osm-game") ASSET_ROOT = ROOT / "assets/images/2d-game-characters/02-xinyin" TURNAROUND = ASSET_ROOT / "previews/xinyin-4dir-turnaround-v1.png" MASTER = ASSET_ROOT / "source/front-left/xinyin-front-left-neutral-master-v2.png" OUTPUT = ASSET_ROOT / "previews/xinyin-front-left-master-validation-v1.png" FONT = Path(r"C:\Windows\Fonts\msyh.ttc") def font(size: int) -> ImageFont.FreeTypeFont: return ImageFont.truetype(str(FONT), size) def checker(size: tuple[int, int], cell: int = 24) -> Image.Image: image = Image.new("RGBA", size, (240, 244, 248, 255)) draw = ImageDraw.Draw(image) for y in range(0, size[1], cell): for x in range(0, size[0], cell): if (x // cell + y // cell) % 2: draw.rectangle((x, y, x + cell - 1, y + cell - 1), fill=(220, 226, 233, 255)) return image def contain(image: Image.Image, box: tuple[int, int], margin: int = 0) -> Image.Image: available = (max(1, box[0] - margin * 2), max(1, box[1] - margin * 2)) result = image.copy() result.thumbnail(available, Image.Resampling.LANCZOS) return result def paste_center(canvas: Image.Image, image: Image.Image, rect: tuple[int, int, int, int]) -> tuple[int, int, int, int]: x0, y0, x1, y1 = rect x = x0 + (x1 - x0 - image.width) // 2 y = y0 + (y1 - y0 - image.height) // 2 canvas.alpha_composite(image, (x, y)) return x, y, x + image.width, y + image.height def main() -> None: turnaround = Image.open(TURNAROUND).convert("RGBA") master = Image.open(MASTER).convert("RGBA") # The second of four equally spaced figures is the established front-left reference. panel_width = turnaround.width // 4 direction_reference = turnaround.crop((panel_width, 0, panel_width * 2, turnaround.height)) canvas = Image.new("RGBA", (1800, 1100), (25, 31, 43, 255)) draw = ImageDraw.Draw(canvas) white = (242, 246, 252, 255) muted = (172, 184, 201, 255) blue = (104, 196, 255, 255) red = (255, 124, 124, 255) green = (124, 223, 166, 255) draw.text((70, 42), "心音|前左方向母版校验 v1", font=font(42), fill=white) draw.text((72, 98), "以四方向转面表第二姿和固定左右不对称关系为方向基准", font=font(22), fill=muted) panels = [(60, 160, 535, 890), (570, 160, 1110, 890), (1145, 160, 1740, 890)] titles = ["A 转面表方向参考", "B 前左高分辨率母版 v2", "C 游戏尺寸轮廓检查"] for rect, title in zip(panels, titles): draw.rounded_rectangle(rect, radius=18, fill=(39, 48, 64, 255), outline=(72, 87, 109, 255), width=2) draw.text((rect[0] + 24, rect[1] + 20), title, font=font(24), fill=white) ref_box = (84, 218, 511, 850) ref = contain(direction_reference, (ref_box[2] - ref_box[0], ref_box[3] - ref_box[1]), margin=8) paste_center(canvas, ref, ref_box) master_box = (594, 218, 1086, 850) master_bg = checker((master_box[2] - master_box[0], master_box[3] - master_box[1])) canvas.alpha_composite(master_bg, (master_box[0], master_box[1])) master_large = contain(master, (master_box[2] - master_box[0], master_box[3] - master_box[1]), margin=18) paste_center(canvas, master_large, master_box) scale_specs = [(352, "工作缩放 352 px"), (176, "游戏基准 176 px"), (88, "50% 检查 88 px")] y_positions = [250, 525, 712] for (height, label), y in zip(scale_specs, y_positions): ratio = height / master.height resized = master.resize((max(1, round(master.width * ratio)), height), Image.Resampling.LANCZOS) bg_rect = (1180, y - 18, 1710, y + height + 28) draw.rounded_rectangle(bg_rect, radius=12, fill=(31, 39, 53, 255)) canvas.alpha_composite(resized, (1210, y)) draw.text((1390, y + max(4, height // 2 - 16)), label, font=font(21), fill=white) draw.rounded_rectangle((60, 925, 1740, 1045), radius=16, fill=(34, 42, 57, 255)) draw.text((88, 946), "固定画面侧:", font=font(24), fill=white) draw.text((260, 946), "羽扇/持械手在右", font=font(24), fill=blue) draw.text((520, 946), "腰包与长银饰在左", font=font(24), fill=red) draw.text((812, 946), "高马尾主体向左后方", font=font(24), fill=green) draw.text((88, 992), "说明:‘左侧掩体探身’是动作与遮挡关系参考,不用于覆盖中性转面方向。", font=font(20), fill=muted) OUTPUT.parent.mkdir(parents=True, exist_ok=True) canvas.convert("RGB").save(OUTPUT, quality=95) print(OUTPUT) if __name__ == "__main__": main()