nomadro/apps/miniprogram/weapp/store-assets/gen_from_xhs_shot.py
eric 3e5b7c2098 Monorepo super-optimize: src layout, workspace scripts, docs.
Collapse portal under src/, unify pnpm workspace/scripts, thin VIP topic re-exports, drop orphan vip scaffolds and one-shot scripts, ignore xhs/release, document root commands.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-01 00:34:04 +08:00

92 lines
3.1 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 -*-
"""小红书顶栏 hub-logo SVG → 三端上架图标(色取自创服截图 #f06664)。"""
from pathlib import Path
from PIL import Image, ImageDraw
import math
OUT = Path(__file__).resolve().parent
BG = (12, 12, 15)
RED = (240, 102, 100) # #f06664 · 截图主色
def draw_hub_logo(size: int = 1024) -> Image.Image:
"""viewBox 0 0 40 40 → 放大:环 r=18、弧 M12 22c4-8 12-8 16 0、点 (28,14) r=3。"""
img = Image.new("RGB", (size, size), BG)
d = ImageDraw.Draw(img)
s = size / 40.0 # scale
def xy(x, y):
return (x * s, y * s)
# ring: cx=20 cy=20 r=18 stroke-width≈2.5
cx, cy, r = 20 * s, 20 * s, 18 * s
ring_w = max(3, int(2.5 * s))
d.ellipse([cx - r, cy - r, cx + r, cy + r], outline=RED, width=ring_w)
# smile path: cubic Bezier M12,22 C16,14 28,14 28,22
# (c4-8 12-8 16 0 relative → C 16,14 24,14 28,22)
# wait: c4-8 12-8 16 0 means:
# cp1 = (12+4, 22-8)=(16,14)
# cp2 = (12+12, 22-8)=(24,14)
# end = (12+16, 22+0)=(28,22)
p0 = (12.0, 22.0)
p1 = (16.0, 14.0)
p2 = (24.0, 14.0)
p3 = (28.0, 22.0)
stroke = max(2, int(2.0 * s))
steps = max(48, size // 8)
pts = []
for i in range(steps + 1):
t = i / steps
u = 1 - t
x = u**3 * p0[0] + 3 * u**2 * t * p1[0] + 3 * u * t**2 * p2[0] + t**3 * p3[0]
y = u**3 * p0[1] + 3 * u**2 * t * p1[1] + 3 * u * t**2 * p2[1] + t**3 * p3[1]
pts.append(xy(x, y))
for i in range(len(pts) - 1):
x0, y0 = pts[i]
x1, y1 = pts[i + 1]
for k in range(8):
t = k / 7
x = x0 + (x1 - x0) * t
y = y0 + (y1 - y0) * t
rr = stroke / 2
d.ellipse([x - rr, y - rr, x + rr, y + rr], fill=RED)
# satellite dot (28,14) r=3
dx, dy = xy(28, 14)
dr = 3 * s
d.ellipse([dx - dr, dy - dr, dx + dr, dy + dr], fill=RED)
return img
def main() -> None:
icon = draw_hub_logo(1024)
icon.save(OUT / "icon-1024.png", "PNG", optimize=True)
for s in (512, 256, 144):
icon.resize((s, s), Image.Resampling.LANCZOS).save(OUT / f"icon-{s}.png", "PNG", optimize=True)
icon.save(OUT / "icon-1024.jpg", "JPEG", quality=95, optimize=True)
icon.resize((512, 512), Image.Resampling.LANCZOS).save(OUT / "icon-512.jpg", "JPEG", quality=95, optimize=True)
icon.resize((192, 192), Image.Resampling.LANCZOS).save(OUT / "icon-192.webp", "WEBP", quality=92)
(OUT / "icon-nomadro-red.svg").write_text(
"""<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024" fill="none">
<rect width="1024" height="1024" fill="#0c0c0f"/>
<g transform="scale(25.6)">
<circle cx="20" cy="20" r="18" stroke="#f06664" stroke-width="2.5"/>
<path d="M12 22c4-8 12-8 16 0" stroke="#f06664" stroke-width="2" stroke-linecap="round"/>
<circle cx="28" cy="14" r="3" fill="#f06664"/>
</g>
</svg>
""",
encoding="utf-8",
)
for p in sorted(OUT.glob("icon-*")):
if p.suffix == ".svg":
print(p.name, p.stat().st_size)
else:
print(f"{p.name}\t{Image.open(p).size}\t{p.stat().st_size}")
if __name__ == "__main__":
main()