topfans/frontend/scripts/generate_app_icons.py
2026-05-14 22:18:25 +08:00

56 lines
1.4 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.

"""One-off: generate PNGs under unpackage/res/icons for manifest.json paths."""
from pathlib import Path
from PIL import Image, ImageDraw
ROOT = Path(__file__).resolve().parents[1]
# 勿放 unpackage/.gitignore否则云端/他人拉代码后 HBuilder 仍报图标不存在
OUT = ROOT / "static" / "app-icons"
BG = (0x4A, 0x6B, 0xCF)
ACCENT = (0xFF, 0xFF, 0xFF)
SIZES = {
"72x72.png": 72,
"96x96.png": 96,
"144x144.png": 144,
"192x192.png": 192,
"1024x1024.png": 1024,
"76x76.png": 76,
"152x152.png": 152,
"20x20.png": 20,
"40x40.png": 40,
"167x167.png": 167,
"29x29.png": 29,
"58x58.png": 58,
"80x80.png": 80,
"120x120.png": 120,
"180x180.png": 180,
"60x60.png": 60,
"87x87.png": 87,
}
def main() -> None:
OUT.mkdir(parents=True, exist_ok=True)
for fname, w in SIZES.items():
h = w
im = Image.new("RGB", (w, h), BG)
draw = ImageDraw.Draw(im)
margin = max(1, w // 8)
draw.ellipse(
[margin, margin, w - margin, h - margin],
outline=ACCENT,
width=max(1, w // 32),
)
if w >= 48:
r = w // 5
cx, cy = w // 2, h // 2
draw.ellipse([cx - r, cy - r, cx + r, cy + r], fill=ACCENT)
im.save(OUT / fname, format="PNG", optimize=True)
print("wrote", len(SIZES), "icons to", OUT)
if __name__ == "__main__":
main()