1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
| #!/usr/bin/env python3
"""DSH Web app icon: official DeepSeek Harness whale (from favicon.svg)
on a deep-blue gradient rounded square. 4x supersampled; self-checks at end."""
from PIL import Image, ImageDraw, ImageFilter
import os, re, subprocess, sys
OUT = os.path.dirname(os.path.abspath(__file__))
S = 4096 # supersample canvas
R = 1024 # final master
def lerp(a, b, t):
return tuple(int(a[i] + (b[i] - a[i]) * t) for i in range(3))
# ---------- minimal SVG path parser (official favicon uses M/C only) ----------
def parse_svg_path(d):
tokens = re.findall(r'([MmLlCcQqZzHhVvSsTtAa])|(-?\d*\.?\d+(?:e-?\d+)?)', d)
tokens = [t[0] or float(t[1]) for t in tokens]
i = 0
def num():
nonlocal i
v = float(tokens[i]); i += 1
return v
def cubic(p0, p1, p2, p3, n=40):
return [( (1-t)**3*p0[0]+3*(1-t)**2*t*p1[0]+3*(1-t)*t*t*p2[0]+t**3*p3[0],
(1-t)**3*p0[1]+3*(1-t)**2*t*p1[1]+3*(1-t)*t*t*p2[1]+t**3*p3[1] )
for t in (k/n for k in range(1, n+1))]
def quad(p0, p1, p2, n=30):
return [( (1-t)**2*p0[0]+2*(1-t)*t*p1[0]+t*t*p2[0],
(1-t)**2*p0[1]+2*(1-t)*t*p1[1]+t*t*p2[1] )
for t in (k/n for k in range(1, n+1))]
subpaths, cur = [], []
pos = start = (0, 0); last_c = None; last_letter = 'M'
while i < len(tokens):
if isinstance(tokens[i], str):
c = tokens[i]; i += 1
if c in 'Zz':
if cur and cur[-1] != start: cur.append(start)
if cur: subpaths.append(cur)
cur = []; pos = start; last_c = None
continue
else:
c = last_letter # implicit repeat (M -> L)
rel = c.islower(); C = c.upper()
last_letter = 'L' if C == 'M' else C
if C == 'M':
x, y = num(), num()
pos = (pos[0]+x, pos[1]+y) if rel else (x, y)
if cur: subpaths.append(cur)
cur = [pos]; start = pos; last_c = None
elif C == 'L':
x, y = num(), num()
pos = (pos[0]+x, pos[1]+y) if rel else (x, y)
cur.append(pos); last_c = None
elif C == 'H':
x = num(); pos = ((pos[0]+x) if rel else x, pos[1]); cur.append(pos); last_c = None
elif C == 'V':
y = num(); pos = (pos[0], (pos[1]+y) if rel else y); cur.append(pos); last_c = None
elif C == 'C':
x1, y1, x2, y2, x, y = num(), num(), num(), num(), num(), num()
p1 = (pos[0]+x1, pos[1]+y1) if rel else (x1, y1)
p2 = (pos[0]+x2, pos[1]+y2) if rel else (x2, y2)
p3 = (pos[0]+x, pos[1]+y) if rel else (x, y)
cur += cubic(pos, p1, p2, p3); pos = p3; last_c = p2
elif C == 'S':
x2, y2, x, y = num(), num(), num(), num()
p1 = (2*pos[0]-last_c[0], 2*pos[1]-last_c[1]) if last_c else pos
p2 = (pos[0]+x2, pos[1]+y2) if rel else (x2, y2)
p3 = (pos[0]+x, pos[1]+y) if rel else (x, y)
cur += cubic(pos, p1, p2, p3); pos = p3; last_c = p2
elif C == 'Q':
x1, y1, x, y = num(), num(), num(), num()
p1 = (pos[0]+x1, pos[1]+y1) if rel else (x1, y1)
p2 = (pos[0]+x, pos[1]+y) if rel else (x, y)
cur += quad(pos, p1, p2); pos = p2; last_c = None
else:
raise ValueError("unhandled command " + c)
if cur: subpaths.append(cur)
return subpaths
def build_official_whale(canvas, span=0.62):
"""Render the official DSH whale (favicon.svg) white, centered, spanning `span` of canvas."""
src = open(os.path.join(OUT, "favicon.svg")).read()
d = re.search(r'\bd="([^"]+)"', src).group(1)
subpaths = parse_svg_path(d)
xs = [p[0] for sp in subpaths for p in sp]
ys = [p[1] for sp in subpaths for p in sp]
bw, bh = max(xs) - min(xs), max(ys) - min(ys)
scale = canvas * span / max(bw, bh)
ox = canvas / 2 - (min(xs) + max(xs)) / 2 * scale
oy = canvas / 2 - (min(ys) + max(ys)) / 2 * scale - canvas * 0.015
mask = Image.new("L", (canvas, canvas), 0)
dr = ImageDraw.Draw(mask)
for sp in subpaths:
dr.polygon([(p[0]*scale + ox, p[1]*scale + oy) for p in sp], fill=255)
# white -> ice-blue vertical gradient inside the whale mask
g1 = Image.new("RGBA", (1, canvas))
for y in range(canvas):
g1.putpixel((0, y), lerp((255, 255, 255), (190, 224, 255), y / canvas) + (255,))
grad = g1.resize((canvas, canvas))
return Image.composite(grad, Image.new("RGBA", (canvas, canvas), (0, 0, 0, 0)), mask)
def main():
# background: diagonal navy -> blue -> teal
bg = Image.new("RGBA", (R, R))
px = bg.load()
c1, c2, c3 = (7, 14, 40), (18, 56, 124), (9, 118, 168)
for y in range(R):
for x in range(R):
t = (x + y) / (2 * R)
c = lerp(c1, c2, t * 2) if t < 0.5 else lerp(c2, c3, (t - 0.5) * 2)
px[x, y] = c + (255,)
# rounded-rect mask
mask = Image.new("L", (R, R), 0)
ImageDraw.Draw(mask).rounded_rectangle([0, 0, R - 1, R - 1], radius=int(R * 0.2237), fill=255)
bg.putalpha(mask)
# whale: 4x supersample -> glow -> composite
whale_small = build_official_whale(S).resize((R, R), Image.LANCZOS)
glow = Image.new("RGBA", (S, S), (0, 0, 0, 0))
ImageDraw.Draw(glow).ellipse([S*0.15, S*0.20, S*0.85, S*0.85], fill=(70, 190, 255, 150))
glow = glow.filter(ImageFilter.GaussianBlur(S * 0.09)).resize((R, R), Image.LANCZOS)
glow = Image.composite(glow, Image.new("RGBA", (R, R), (0, 0, 0, 0)), whale_small.split()[3])
bg = Image.alpha_composite(bg, glow)
bg = Image.alpha_composite(bg, whale_small)
bg.save(os.path.join(OUT, "icon_1024.png"))
# ---- Windows .ico ----
bg.save(os.path.join(OUT, "AppIcon.ico"),
sizes=[(16, 16), (32, 32), (48, 48), (64, 64), (128, 128), (256, 256)])
# ---- macOS .icns(仅 macOS 有 iconutil)----
if sys.platform == "darwin":
iconset = os.path.join(OUT, "AppIcon.iconset")
os.makedirs(iconset, exist_ok=True)
for name, size in {"icon_16x16.png": 16, "icon_16x16@2x.png": 32, "icon_32x32.png": 32,
"icon_32x32@2x.png": 64, "icon_128x128.png": 128, "icon_128x128@2x.png": 256,
"icon_256x256.png": 256, "icon_256x256@2x.png": 512, "icon_512x512.png": 512,
"icon_512x512@2x.png": 1024}.items():
bg.resize((size, size), Image.LANCZOS).save(os.path.join(iconset, name))
subprocess.run(["iconutil", "-c", "icns", iconset, "-o",
os.path.join(OUT, "AppIcon.icns")], check=True)
# self-check
px = bg.load()
bright = [(x, y) for y in range(R) for x in range(R)
if px[x, y][3] > 200 and px[x, y][0] > 200 and px[x, y][1] > 200]
assert len(bright) > 30000, f"whale too small: {len(bright)} bright pixels"
xs = [p[0] for p in bright]; ys = [p[1] for p in bright]
print(f"bright pixels: {len(bright)} whale bbox: x[{min(xs)}..{max(xs)}] y[{min(ys)}..{max(ys)}]")
print("OK icon_1024.png + AppIcon.ico" + (" + AppIcon.icns" if sys.platform == "darwin" else ""))
if __name__ == "__main__":
main()
|