63 lines
2.1 KiB
Python
63 lines
2.1 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
生成微信小程序 tabBar 图标 (81x81 PNG, normal + selected 共 2 套)
|
|
- 5 个 tab: home, hospital, appointment, self-test, phone
|
|
- normal 色 #94a3b8 (gray), selected 色 #1f7ae0 (blue)
|
|
"""
|
|
from PIL import Image, ImageDraw
|
|
import os
|
|
|
|
OUT_DIR = "src/assets/tabbar"
|
|
os.makedirs(OUT_DIR, exist_ok=True)
|
|
|
|
SIZE = 81
|
|
GRAY = (148, 163, 184, 255)
|
|
BLUE = (31, 122, 224, 255)
|
|
WHITE = (255, 255, 255, 255)
|
|
|
|
|
|
def draw_icon(name, color):
|
|
img = Image.new("RGBA", (SIZE, SIZE), (0, 0, 0, 0))
|
|
d = ImageDraw.Draw(img)
|
|
|
|
if name == "home":
|
|
# 屋顶 + 房身
|
|
d.polygon([(40, 12), (12, 36), (68, 36)], fill=color)
|
|
d.rectangle([18, 36, 62, 68], fill=color)
|
|
d.rectangle([34, 46, 46, 68], fill=WHITE)
|
|
elif name == "hospital":
|
|
# 圆角矩形 + 十字
|
|
d.rounded_rectangle([10, 14, 70, 74], radius=10, fill=color)
|
|
d.rectangle([34, 24, 46, 64], fill=WHITE)
|
|
d.rectangle([24, 36, 56, 48], fill=WHITE)
|
|
elif name == "appointment":
|
|
# 日历 + 勾
|
|
d.rounded_rectangle([10, 16, 70, 72], radius=6, fill=color)
|
|
d.rectangle([18, 16, 24, 26], fill=color)
|
|
d.rectangle([56, 16, 62, 26], fill=color)
|
|
d.line([(24, 44), (36, 54), (56, 36)], fill=WHITE, width=5)
|
|
elif name == "self-test":
|
|
# 圆 + 问号
|
|
d.ellipse([10, 10, 70, 70], fill=color)
|
|
# 问号白色: 用两个矩形 (竖 + 横) + 圆点
|
|
d.rectangle([36, 22, 44, 42], fill=WHITE)
|
|
d.rectangle([36, 38, 50, 46], fill=WHITE)
|
|
d.rectangle([36, 50, 44, 58], fill=WHITE)
|
|
elif name == "phone":
|
|
# 话筒
|
|
d.rounded_rectangle([30, 10, 50, 50], radius=10, fill=color)
|
|
d.arc([18, 28, 62, 72], start=0, end=180, fill=color, width=6)
|
|
d.line([40, 50, 40, 68], fill=color, width=6)
|
|
|
|
return img
|
|
|
|
|
|
for name in ["home", "hospital", "appointment", "self-test", "phone"]:
|
|
img_gray = draw_icon(name, GRAY)
|
|
img_blue = draw_icon(name, BLUE)
|
|
img_gray.save(os.path.join(OUT_DIR, name + ".png"))
|
|
img_blue.save(os.path.join(OUT_DIR, name + "_selected.png"))
|
|
print(" + " + name + ".png, " + name + "_selected.png")
|
|
|
|
print("DONE")
|