oms/frontend/scripts/make-favicon.py
liufumingren 49fec97526 feat(frontend): 新增 OMS 站点图标 favicon(矢量 + 多尺寸 ICO)
- 设计:深蓝圆角底 + 等轴测立方体,语义对应包裹 / 仓储 / 订单履约
- public/favicon.svg(矢量源,现代浏览器优先用)、public/favicon.ico(16/24/32/48/64/128/256 七档)、
  public/apple-touch-icon.png(180)
- index.html 增加 icon / apple-touch-icon 链接与 theme-color
- scripts/make-favicon.py 保留生成脚本,改配色或形状后可一键重出

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-02 01:25:14 +08:00

66 lines
2.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- coding: utf-8 -*-
"""OMS 站点图标生成器(Pillow):深蓝圆角底 + 等轴测立方体(包裹 / 仓储 / 订单语义)。
渲染时 16 倍超采样再缩采样,导出多尺寸 ICO(Windows / 浏览器通用)+ apple-touch-icon。
改配色或形状后重跑本脚本即可;矢量同源版本见 favicon.svg。"""
import os
from PIL import Image, ImageDraw
OUT_DIR = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'public'))
S = 256
BG_TOP = (16, 58, 150) # #103A96
BG_BOTTOM = (6, 20, 46) # #06142E
FACE_TOP = (255, 255, 255)
FACE_LEFT = (222, 234, 255) # #DEEAFF
FACE_RIGHT = (176, 203, 250) # #B0CBFA
def lerp(a, b, t):
return tuple(int(round(a[i] + (b[i] - a[i]) * t)) for i in range(3))
def render(size, ss=16):
w = size * ss
tile = Image.new('RGB', (w, w))
d = ImageDraw.Draw(tile)
for y in range(w):
d.line([(0, y), (w, y)], fill=lerp(BG_TOP, BG_BOTTOM, y / (w - 1)))
# 圆角遮罩(Pillow 7 无 rounded_rectangle:矩形 + 四角圆)
mask = Image.new('L', (w, w), 0)
md = ImageDraw.Draw(mask)
r = int(w * 0.225)
md.rectangle([r, 0, w - r - 1, w - 1], fill=255)
md.rectangle([0, r, w - 1, w - r - 1], fill=255)
md.ellipse([0, 0, 2 * r, 2 * r], fill=255)
md.ellipse([w - 1 - 2 * r, 0, w - 1, 2 * r], fill=255)
md.ellipse([0, w - 1 - 2 * r, 2 * r, w - 1], fill=255)
md.ellipse([w - 1 - 2 * r, w - 1 - 2 * r, w - 1, w - 1], fill=255)
img = tile.convert('RGBA')
img.putalpha(mask)
d2 = ImageDraw.Draw(img)
def p(x, y):
return (x / 256.0 * (w - 1), y / 256.0 * (w - 1))
top = p(128, 28)
up_right = p(224, 82)
low_right = p(224, 186)
bottom = p(128, 240)
low_left = p(34, 186)
up_left = p(34, 82)
center = p(128, 134)
d2.polygon([up_left, center, bottom, low_left], fill=FACE_LEFT)
d2.polygon([up_right, center, bottom, low_right], fill=FACE_RIGHT)
d2.polygon([top, up_right, center, up_left], fill=FACE_TOP)
return img.resize((size, size), Image.LANCZOS)
master = render(S)
master.save(os.path.join(OUT_DIR, 'favicon.ico'), format='ICO',
sizes=[(s, s) for s in (16, 24, 32, 48, 64, 128, 256)])
master.resize((180, 180), Image.LANCZOS).save(os.path.join(OUT_DIR, 'apple-touch-icon.png'), format='PNG')
print('ok:', sorted(os.listdir(OUT_DIR)))