#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ DLPilot 图标栅格化: 黑底 512, 橙色圆角矩形, 第一行 DLP(框内黑字), 第二行 Pilot(白字) ================================================================ 设计参数: 黑底 512, 橙色圆角矩形 x38 y64 w436 h186 rx34, DLP 146px Arial Bold 黑字(框内居中), Pilot 146px Arial Bold 白字(基线 421)。 输出: logos/logo_dlpilot.png(512, 预览/复用) logos/logo_dlpilot.ico(16~256 七档, exe 图标用) 用法: python make_ico.py """ import os from PIL import Image, ImageDraw, ImageFont BASE = os.path.dirname(os.path.abspath(__file__)) FONT = r'C:\Windows\Fonts\arialbd.ttf' # Arial Bold, Windows 标配 def render(size=512): s = size / 512.0 img = Image.new('RGB', (size, size), (0, 0, 0)) d = ImageDraw.Draw(img) d.rounded_rectangle([38 * s, 64 * s, (38 + 436) * s, (64 + 186) * s], radius=34 * s, fill=(255, 153, 0)) if not os.path.exists(FONT): raise SystemExit(f'未找到字体 {FONT}, 无法栅格化') f = ImageFont.truetype(FONT, max(8, round(146 * s))) cx = size / 2 # DLP: 居中于橙色框 d.text((cx, 64 * s + 186 * s / 2), 'DLP', font=f, fill=(0, 0, 0), anchor='mm') # Pilot: 与原设计基线 421 对齐(无下伸字母, 中心 = 421 - cap/2 ~= 368) d.text((cx, 368 * s), 'Pilot', font=f, fill=(255, 255, 255), anchor='mm') return img if __name__ == '__main__': img = render(512) png = os.path.join(BASE, 'logo_dlpilot.png') ico = os.path.join(BASE, 'logo_dlpilot.ico') img.save(png) img.save(ico, sizes=[(16, 16), (24, 24), (32, 32), (48, 48), (64, 64), (128, 128), (256, 256)]) print(f'写出 {png}') print(f'写出 {ico}')