Files
personal/scripts/gen-brand-images.py
T
virtheart 7744a6b420 feat: SEO 商用化 — robots/sitemap/OG/结构化数据 + 服务清单内置
- robots.txt:禁 /virtheart /api /unlock,含 sitemap 指向
- sitemap.xml:动态生成(首页 + 服务页 + 已发布作品详情)
- metadata:metadataBase/title template/keywords/canonical/OG/Twitter
  卡片/apple-icon,全部后台可改(site_title/description/keywords)
- search_verification 字段:百度站长验证 meta(后台填入即生效)
- JSON-LD:首页 Person 实体 + 服务页 ProfessionalService/ Offer
- og.png(1200×630)与 icon/apple-icon 品牌图(scripts/gen-brand-images.py)
- 页脚 ICP 备案号位(icp_beian,后台填入即显示,链工信部)
- 服务清单内置 7 项(Web/小程序、AI 应用、Flutter、Java/Go、
  产品设计、全栈交付、技术咨询),价格一律面议,DB 种子幂等

SEO 部署侧待办:百度/搜狗/360/Bing 站长平台提交与验证(填
search_verification 或放验证文件)、NEXT_PUBLIC_SITE_URL 指向正式域名。
2026-09-02 18:48:44 +08:00

139 lines
5.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.
#!/usr/bin/env python3
"""
生成品牌 OG 分享图(1200×630)与方形 icon(512×512)。
风格对齐主站:近黑底 + 点阵网格 + lime (#c0fe04) 强调块 + 文字。
无 PIL 时纯 zlib 手写 PNG。产物:public/og.png、app/icon-512.png
(icon 再用 sips 缩出 192)。
"""
import zlib
import struct
LIME = (192, 254, 4)
INK = (16, 18, 14) # 近黑
DOT = (44, 48, 42) # 点阵灰
SUB = (96, 106, 92)
def make_canvas(w, h, dot=26):
"""黑底 + 点阵网格(点位于格点,1.5px 半径近似为单像素十字)。"""
rows = []
for y in range(h):
row = bytearray()
for x in range(w):
c = INK
if x % dot == 0 and y % dot == 0:
c = DOT
row += bytes(c)
rows.append(bytes(row))
return rows
def draw_rect(rows, x0, y0, w, h, color):
for y in range(y0, min(y0 + h, len(rows))):
row = bytearray(rows[y])
for x in range(x0, min(x0 + w, len(row) // 3)):
i = x * 3
row[i:i + 3] = bytes(color)
rows[y] = bytes(row)
def draw_5x7(rows, ox, oy, ch, scale, color):
"""极简 5x7 点阵字形(大写字母/数字/汉字块用方块代替逻辑单独处理)。"""
glyphs = {
"N": ["10001", "11001", "10101", "10011", "10001", "10001", "10001"],
"O": ["01110", "10001", "10001", "10001", "10001", "10001", "01110"],
"1": ["00100", "01100", "00100", "00100", "00100", "00100", "01110"],
"2": ["01110", "10001", "00001", "00010", "00100", "01000", "11111"],
"5": ["11111", "10000", "11110", "00001", "00001", "10001", "01110"],
"0": ["01110", "10001", "10011", "10101", "11001", "10001", "01110"],
"2x": ["01110", "10001", "10001", "00010", "00100", "00000", "00100"],
"6": ["01110", "10000", "11110", "10001", "10001", "10001", "01110"],
"3": ["11110", "00001", "01110", "00001", "00001", "10001", "01110"],
"8": ["01110", "10001", "10001", "01110", "10001", "10001", "01110"],
"©": ["01110", "10001", "10111", "10101", "10111", "10001", "01110"],
"X": ["10001", "10001", "01010", "00100", "01010", "10001", "10001"],
}
g = glyphs.get(ch)
if not g:
return None
for ry, line in enumerate(g):
for rx, bit in enumerate(line):
if bit == "1":
draw_rect(rows, ox + rx * scale, oy + ry * scale, scale, scale, color)
return 5 * scale # 字宽
def png_bytes(rows):
h = len(rows)
w = len(rows[0]) // 3
raw = b"".join(b"\x00" + r for r in rows)
def chunk(tag, data):
c = struct.pack(">I", len(data)) + tag + data
return c + struct.pack(">I", zlib.crc32(tag + data) & 0xFFFFFFFF)
ihdr = struct.pack(">IIBBBBB", w, h, 8, 2, 0, 0, 0)
return (b"\x89PNG\r\n\x1a\n" + chunk(b"IHDR", ihdr)
+ chunk(b"IDAT", zlib.compress(raw, 9)) + chunk(b"IEND", b""))
def brand_block(rows, w, h):
# 左上 lime 标记块
draw_rect(rows, 60, 60, 26, 26, LIME)
# 底部 lime 长条
draw_rect(rows, 60, h - 92, 200, 10, LIME)
# 右下三枚小方块(点阵节奏)
for i, s in enumerate((16, 24, 12)):
draw_rect(rows, w - 80 - i * 52, h - 120 - (i * 17) % 40, s, s, LIME)
def og():
w, h = 1200, 630
rows = make_canvas(w, h)
brand_block(rows, w, h)
# 中文无法用点阵字形,用「块状汉字」占位区呈现笔画块——保持极简,
# 真实文字交给 title/description;图上仅保留品牌几何元素 + URL。
s = 8
# 北(象形块阵)
def blocks(cells, ox, oy, sc):
for cx, cy in cells:
draw_rect(rows, ox + cx * sc, oy + cy * sc, sc, sc, (222, 228, 214))
# 「北极新一」四字:以栅格块阵近似笔画(装饰性,读作品牌图形)
bj = [(1,0),(2,0),(3,0),(1,1),(3,1),(1,2),(2,2),(3,2),(2,3),(1,4),(2,4),(3,4),(2,5),(2,6)]
blocks(bj, 60, 150, s)
jz = [(0,0),(1,0),(2,0),(0,1),(1,1),(1,2),(0,3),(1,3),(2,3),(1,4),(1,5),(0,6),(1,6),(2,6)]
blocks(jz, 130, 150, s)
xy = [(0,0),(1,0),(2,0),(3,0),(0,1),(3,1),(0,2),(3,2),(1,3),(2,3),(0,4),(3,4),(0,5),(3,5),(1,6),(2,6)]
blocks(xy, 200, 150, s)
y1 = [(0,0),(1,0),(2,0),(0,1),(1,1),(2,1),(0,2),(1,2),(2,2),(0,3),(1,3),(2,3),(0,4),(1,4),(2,4),(0,5),(1,5),(2,5),(0,6),(1,6),(2,6)]
blocks(y1, 270, 150, s)
# 拉丁行:URL 用点阵字形拼出
x = 60
for ch in "virtheart.com":
if ch == ".":
draw_rect(rows, x + 2 * s, 400 + 6 * s, s, s, SUB)
x += 3 * s + s
continue
wdt = draw_5x7(rows, x, 400, ch.upper(), s, SUB) or 6 * s
x += wdt + s
open("public/og.png", "wb").write(png_bytes(rows))
def icon():
w = h = 512
rows = make_canvas(w, h, dot=22)
draw_rect(rows, 40, 40, 24, 24, LIME)
s = 10
def blocks(cells, ox, oy, sc):
for cx, cy in cells:
draw_rect(rows, ox + cx * sc, oy + cy * sc, sc, sc, (222, 228, 214))
bj = [(1,0),(2,0),(3,0),(1,1),(3,1),(1,2),(2,2),(3,2),(2,3),(1,4),(2,4),(3,4),(2,5),(2,6)]
blocks(bj, 166, 140, s)
jz = [(0,0),(1,0),(2,0),(0,1),(1,1),(1,2),(0,3),(1,3),(2,3),(1,4),(1,5),(0,6),(1,6),(2,6)]
blocks(jz, 216, 140, s)
draw_rect(rows, 60, 430, 120, 8, LIME)
open("app/icon-512.png", "wb").write(png_bytes(rows))
og()
icon()
print("og.png + icon-512.png written")