Files
xbcr/generate_icons.py
zzy 8fa8847384 chore: 行尾统一为 LF
- 新增 .gitattributes:* text=auto eol=lf,二进制类型显式标 binary
- 24 个 CRLF 文件归一为 LF(内容零变化,忽略行尾后 diff 只有本文件与 .gitignore)
- .gitignore 补 temp/、.pytest_cache/、token_config.txt.old-bak、scripts/.pack_baseline.json 等
2026-11-14 19:40:53 +08:00

56 lines
1.6 KiB
Python

#!/usr/bin/env python3
"""生成车辆标记图标"""
from PIL import Image, ImageDraw, ImageFont
import os
STATIC_DIR = os.path.join(os.path.dirname(__file__), "static")
os.makedirs(STATIC_DIR, exist_ok=True)
# 状态颜色 (R, G, B)
COLORS = {
"green": "#4CAF50",
"pink": "#E91E8C",
"orange": "#FF9800",
"gray": "#9E9E9E",
"red": "#F44336",
}
def make_icon(color_hex, label="", size=36):
"""生成圆形标记图标,label=文字(如百分比或状态符)"""
img = Image.new("RGBA", (size, size), (0, 0, 0, 0))
draw = ImageDraw.Draw(img)
r = size // 2
cx, cy = r, r
# 填充圆
draw.ellipse([2, 2, size-3, size-3], fill=color_hex + "E0") # 带透明度
# 边框
draw.ellipse([2, 2, size-3, size-3], outline=color_hex, width=2)
if label:
# 文字居中
try:
font_size = 11 if len(label) <= 2 else 9
font = ImageFont.truetype("arial.ttf", font_size)
except Exception:
font = ImageFont.load_default()
bbox = draw.textbbox((0, 0), label, font=font)
tw = bbox[2] - bbox[0]
th = bbox[3] - bbox[1]
tx = cx - tw // 2 - bbox[0]
ty = cy - th // 2 - bbox[1]
# 白色文字
draw.text((tx, ty), label, fill="#FFFFFF", font=font)
path = os.path.join(STATIC_DIR, f"marker_{color_hex[1:]}.png")
img.save(path, "PNG")
print(f" {path}")
return path
if __name__ == "__main__":
print("生成标记图标...")
for name, color in COLORS.items():
make_icon(color)
print("完成!")