feat: HDMI-Tool 与 I2C-Inject 首版工具集

This commit is contained in:
2026-09-03 17:24:33 +08:00
parent 6243b8c262
commit d0cefeebf3
38 changed files with 2778 additions and 1 deletions
+58
View File
@@ -0,0 +1,58 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
把 logo_i2c_orange.svg 同款设计栅格化为多尺寸 .ico(供 I2C-Inject exe 图标)
================================================================
设计参数与 logo_ph_orange 同风格: 黑底 512, 橙色圆角矩形 x38 y64 w436 h186 rx34,
框内 "I2C" 146px Arial Bold 黑字(居中), 下方 "Inject" 白字(基线 421)。
"Inject" 比原版 "Tool" 长, 自动缩放到内容宽度 <= 85% 画布(436px)。
输出: logos/logo_i2c_orange.png(512, 预览/复用)
logos/logo_i2c_orange.ico(16~256 七档, exe 图标用)
用法: python make_ico_i2c.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 标配
MAX_W = 436 # 内容宽度上限(85% 画布)
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}, 无法栅格化')
px = max(8, round(146 * s))
f = ImageFont.truetype(FONT, px)
cx = size / 2
# I2C: 居中于橙色框(146px 下宽度远小于 436, 无需缩放)
d.text((cx, 64 * s + 186 * s / 2), 'I2C', font=f, fill=(0, 0, 0), anchor='mm')
# Inject: 基线 421 对齐(中心 ~= 368), 超宽则缩字号
bottom_px = px
while bottom_px > 8:
w = d.textlength('Inject', font=ImageFont.truetype(FONT, bottom_px))
if w <= MAX_W * s:
break
bottom_px -= 2
f_bottom = ImageFont.truetype(FONT, bottom_px)
d.text((cx, 368 * s), 'Inject', font=f_bottom, fill=(255, 255, 255), anchor='mm')
return img
if __name__ == '__main__':
img = render(512)
png = os.path.join(BASE, 'logo_i2c_orange.png')
ico = os.path.join(BASE, 'logo_i2c_orange.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}')