docs(acceptance): 两轮全站验收读数 + 复现脚本 + 企微资产包入库(OPEN-12)

按「这条结论怎么来的必须入库,排查当时的截图只服务当时」的既有口径,
把此前一直悬在 git status 里、归属未定的产物逐组落定:

入库(7.2MB):
- docs/acceptance/2026-10-21-full-qa/、2026-10-24-full-qa/ 的文字与结构化读数
  (README / defects*.json / sweep/summary.json / axe evidence / lighthouse /
  report.json 逐 run 原始读数 / tools 复现脚本)
- docs/acceptance/2026-11-26-axe/ 本轮 axe 复跑证据(35 路由 × 4 组合 140 rows 全 0)
- scripts/acceptance/{sweep-routes,contact-sheet}.mjs —— 两轮 README 里被引用的
  复现脚本,不提交则结论不可复算
- deliverables/.../wecom-pack.cjs + check-wecom.py + WECOM-MANIFEST.md +
  assets-wecom/pack-report.json(生成器/校验器/清单;18 张 PNG 可由脚本从已入库
  SVG 重新栅格化,故仍按既有规则忽略)

忽略(不提交,已写进 .gitignore 并注明归属):
- 两轮验收的逐页截图(172MB):只在排查当时有用
- infra/cicd/gitea{,-custom}/ + 2026-10-22-gitea-branding/(340KB):
  归 feature/gitea-branding,逐文件 sha256 与该分支 50/50 完全一致,
  在本分支提交会造成同一批文件的两份历史

判据:提交后 git status -uall 只剩被忽略项;每条 ?? 都能回答「归谁、为什么在这里」。
This commit is contained in:
zhangxiang committed 2026-11-26 20:03:46 +08:00
1 parent 938af25030
commit 763e159ac4
45 files changed
+257540

No files matched your search

@@ -0,0 +1,48 @@
# 企业微信资产包 · 清单(第五十二刀)
生成:`wecom-pack.cjs`(18 张 PNG + `pack-report.json`)
门禁:`check-wecom.py` → **判红 0 / 通过 64 / 预期红 2 / EXIT=0**
对照页:`wecom.html`(手写件,非生成 —— 所以不配标签配平闸,改由浏览器实验 20 张图 0 破图)
## 一、两类载体,两套判据
| 用途 | 文件 | 关键判据(实测,非声明) |
|---|---|---|
| 企业微信头像·标准 | `wecom-avatar-full-512.png` `…-144.png` | 圆即底板(内切圆外 0 像素);中心 (196,30,58)=朱砂;源 `avatar-standard.svg`,face 0.80 |
| 企业微信头像·仪式 | `wecom-avatar-ring2-512.png` `…-144.png` | 同上;粗白环 4.5% + 字面 0.68,源 `avatar-ceremonial.svg` |
| 企业logo·名+号 | `wecom-logo-stacked-702x180-{white,transparent,reversed}.png` | 墨 462×180、左右各空 120、居中差 ≤1px;朱砂 0.47%(含红的 A) |
| 企业logo·只走名 | `wecom-logo-name-702x180-{white,transparent,reversed}.png` | 墨 702×154、上下各空 13、居中差 0;朱砂恰 0(源不含号 ⇒ 无 A 可加彩) |
| 留白备版 | 上两组的 `-pad-` 三件套 | 板内四周内缩 13px 后重装;stacked 墨 395×154、name 墨 676×148 |
| @2x 高清备份 | `wecom-logo-{stacked,name}-2x-1404x360-white.png` | 只出白底板;上传框按 702×180 用 |
## 二、这一刀量出来的三条,推翻了我自己先前的说法
1. **「方印塞圆裁会咬字」不成立。** 实测两版白字最远极径都在内切圆内:方版余量 10.3%、圆版 8.0%;40px 下逐格差异只有 9.4%。
真正的差别是语义 —— 方版被裁后那道圆边是**被裁出来的**,「印是方的」这层意思当场没了;圆版那道圆按 `face ≤ 0.866`(真迹最远极径 0.5773×max)设计。
判据 B 因此改述为「圆即底板」,不再宣称保护可读性。
2. **字标 SVG 的 viewBox 上下带空盒,按画布排必偏心。** 实测 `public/logo.svg` 墨只占画布高 **72.8%**、`name-alone.svg` 只占 **51.1%**;
上一版按画布顶天立地排,门禁当场报出上下差 9–30px。改成**先裁墨盒再定标**后才归零。
⚠ 这与记忆里那条「承载尺寸的空盒会污染一切由它换算出来的数」是同一个 bug 的第三次现身(前两次:主锁定 viewBox 写死 460、名墨右 255.6)。
3. **`name` 的墨宽高比实测 4.557,比 702×180 的板(3.900)还扁** ⇒ 它只能按宽限死。
记忆里「新横排名 2.663」是**画布**比不是**墨**比;`name-alone.svg` 那个 96 单位高的画布是空盒。
## 三、装配层踩过的三个坑(都靠门禁或实测拦住,没进交付)
- `assertPurePaths` 把注释里的「现网那份用 `<text>`」判成违规 —— 判据先剥 XML 注释才对。
- `sharp.resize(宽, 高)` 参数顺序写反,墨块被排成 180×384,合成时才报「比底板大」。
- **负对照的预期红被计进失败数** ⇒ 闸越准、EXIT 越红。已按「退出码分档 + 预期红登记」改掉,并加条数下限(<2 条即宣布负对照没跑成、上面所有 ok 不作数)。
## 四、两条必须随文件交接的存疑
1. **702×180 是半核实。** 口径来自转述官方后台提示的二手文(CSDN 教程、建站问答),官方帮助中心正文为 JS 渲染、抓不到正文。
上传前以管理后台【我的企业 → 企业信息 → 企业logo】的提示框为准;若比例不同,改 `wecom-pack.cjs` 顶部 `PLATE` 一个常量即可重出全套。
2. **没做的部分**:自建应用图标、群机器人头像、对外名片 —— 官方尺寸没有可信来源,不拿猜的数当交付。
## 五、待拍(对照页第四节)
- **W1** 头像 full / ring2 → 推荐 **full**(企业微信是最小、压最狠、重复最多的载体,ring2 那道环正是实测会碎成 38 块的那一档)
- **W2** 企业logo 名+号 / 只走名 → 推荐 **名+号**(与 2026-10-20「导航必须带英文」同口径;代价量化:书法实高 102px vs 154px,号占 61px、缝 17px)
- **W3** 底板 满版 / 留白版 → 推荐 **满版**(启动页那块系统本就留边,再自缩 14.5% 会显小)
拍完:选定版去掉后缀转正式件,未选版进 `alt/`,本文件补裁定段。
本包属站外载体,**不进 `public/`**、不改站点代码。
@@ -0,0 +1,279 @@
{
"plate": {
"w": 702,
"h": 180
},
"pad": 0.86,
"files": {
"wecom-avatar-full-512.png": {
"source": "assets-delivery/avatar-standard.svg",
"size": "512x512",
"kind": "avatar"
},
"wecom-avatar-full-144.png": {
"source": "assets-delivery/avatar-standard.svg",
"size": "144x144",
"kind": "avatar"
},
"wecom-avatar-ring2-512.png": {
"source": "assets-delivery/avatar-ceremonial.svg",
"size": "512x512",
"kind": "avatar"
},
"wecom-avatar-ring2-144.png": {
"source": "assets-delivery/avatar-ceremonial.svg",
"size": "144x144",
"kind": "avatar"
},
"wecom-logo-stacked-702x180-white.png": {
"source": "../../public/logo.svg",
"size": "702x180",
"kind": "plate",
"ink": {
"w": 462,
"h": 180
},
"pad": {
"l": 120,
"r": 120,
"t": 0,
"b": 0
},
"limit": "height",
"inkAspect": 2.565,
"inkOverCanvas": 0.728
},
"wecom-logo-stacked-702x180-transparent.png": {
"source": "../../public/logo.svg",
"size": "702x180",
"kind": "plate",
"ink": {
"w": 462,
"h": 180
},
"pad": {
"l": 120,
"r": 120,
"t": 0,
"b": 0
},
"limit": "height",
"inkAspect": 2.565,
"inkOverCanvas": 0.728
},
"wecom-logo-stacked-702x180-reversed.png": {
"source": "../../public/logo-white.svg",
"size": "702x180",
"kind": "plate",
"ink": {
"w": 462,
"h": 180
},
"pad": {
"l": 120,
"r": 120,
"t": 0,
"b": 0
},
"limit": "height",
"inkAspect": 2.565,
"inkOverCanvas": 0.728
},
"wecom-logo-stacked-2x-1404x360-white.png": {
"source": "../../public/logo.svg",
"size": "1404x360",
"kind": "plate",
"ink": {
"w": 923,
"h": 360
},
"pad": {
"l": 240,
"r": 241,
"t": 0,
"b": 0
}
},
"wecom-logo-stacked-pad-702x180-white.png": {
"source": "../../public/logo.svg",
"size": "702x180",
"kind": "plate",
"ink": {
"w": 395,
"h": 154
},
"pad": {
"l": 154,
"r": 153,
"t": 13,
"b": 13
},
"limit": "height",
"inkAspect": 2.565,
"inkOverCanvas": 0.728
},
"wecom-logo-stacked-pad-702x180-transparent.png": {
"source": "../../public/logo.svg",
"size": "702x180",
"kind": "plate",
"ink": {
"w": 395,
"h": 154
},
"pad": {
"l": 154,
"r": 153,
"t": 13,
"b": 13
},
"limit": "height",
"inkAspect": 2.565,
"inkOverCanvas": 0.728
},
"wecom-logo-stacked-pad-702x180-reversed.png": {
"source": "../../public/logo-white.svg",
"size": "702x180",
"kind": "plate",
"ink": {
"w": 395,
"h": 154
},
"pad": {
"l": 154,
"r": 153,
"t": 13,
"b": 13
},
"limit": "height",
"inkAspect": 2.565,
"inkOverCanvas": 0.728
},
"wecom-logo-name-702x180-white.png": {
"source": "assets-delivery/name-alone.svg",
"size": "702x180",
"kind": "plate",
"ink": {
"w": 702,
"h": 154
},
"pad": {
"l": 0,
"r": 0,
"t": 13,
"b": 13
},
"limit": "width",
"inkAspect": 4.557,
"inkOverCanvas": 0.511
},
"wecom-logo-name-702x180-transparent.png": {
"source": "assets-delivery/name-alone.svg",
"size": "702x180",
"kind": "plate",
"ink": {
"w": 702,
"h": 154
},
"pad": {
"l": 0,
"r": 0,
"t": 13,
"b": 13
},
"limit": "width",
"inkAspect": 4.557,
"inkOverCanvas": 0.511
},
"wecom-logo-name-702x180-reversed.png": {
"source": "assets-delivery/name-alone-reversed.svg",
"size": "702x180",
"kind": "plate",
"ink": {
"w": 702,
"h": 154
},
"pad": {
"l": 0,
"r": 0,
"t": 13,
"b": 13
},
"limit": "width",
"inkAspect": 4.557,
"inkOverCanvas": 0.511
},
"wecom-logo-name-2x-1404x360-white.png": {
"source": "assets-delivery/name-alone.svg",
"size": "1404x360",
"kind": "plate",
"ink": {
"w": 1404,
"h": 308
},
"pad": {
"l": 0,
"r": 0,
"t": 26,
"b": 26
}
},
"wecom-logo-name-pad-702x180-white.png": {
"source": "assets-delivery/name-alone.svg",
"size": "702x180",
"kind": "plate",
"ink": {
"w": 676,
"h": 148
},
"pad": {
"l": 13,
"r": 13,
"t": 16,
"b": 16
},
"limit": "width",
"inkAspect": 4.557,
"inkOverCanvas": 0.511
},
"wecom-logo-name-pad-702x180-transparent.png": {
"source": "assets-delivery/name-alone.svg",
"size": "702x180",
"kind": "plate",
"ink": {
"w": 676,
"h": 148
},
"pad": {
"l": 13,
"r": 13,
"t": 16,
"b": 16
},
"limit": "width",
"inkAspect": 4.557,
"inkOverCanvas": 0.511
},
"wecom-logo-name-pad-702x180-reversed.png": {
"source": "assets-delivery/name-alone-reversed.svg",
"size": "702x180",
"kind": "plate",
"ink": {
"w": 676,
"h": 148
},
"pad": {
"l": 13,
"r": 13,
"t": 16,
"b": 16
},
"limit": "width",
"inkAspect": 4.557,
"inkOverCanvas": 0.511
}
},
"avatars": [
"full",
"ring2"
]
}
@@ -0,0 +1,318 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
企业微信资产包门禁(第五十二刀)
跑法:/usr/bin/python3 check-wecom.py
退出码分档(不是"红=1"一把梭):0 全绿 / 1 判红 / 2 门禁自身崩溃或夹具缺失
四条判据都配了**负对照**,负对照不判红就等于这条判据没有约束力:
B 圆即底板 ← 现网 assets-delivery/icon-512x512.png(圆角方版)必须被判红
D 板内居中 ← 故意平移 6px 的副本必须被判红
E 朱砂面积带 ← 把红涂满整板的副本必须被判红
F 反白无彩 ← 给反白版塞一枚朱砂 A 的副本必须被判红
"""
import os
import re
import sys
import tempfile
try:
from PIL import Image
except Exception as e: # 解释器选错会读成"依赖缺失",见记忆 reference-python-pillow-path
print("FATAL 需要 Pillow,且必须用 /usr/bin/python3 跑:", e)
sys.exit(2)
HERE = os.path.dirname(os.path.abspath(__file__))
PKG = os.path.join(HERE, "assets-wecom")
RED = (196, 30, 58) # #C41E3A
ALPHA_EDGE = 8 # 视为"全透明"的上限
fails, oks, expected = [], [], []
def ok(msg):
oks.append(msg)
print(f" ok {msg}")
def bad(msg):
fails.append(msg)
print(f" RED {msg}")
def name_size(fn):
m = re.search(r"(\d+)x(\d+)", fn)
if m:
return int(m.group(1)), int(m.group(2))
m = re.search(r"-(\d+)\.png$", fn)
return (int(m.group(1)), int(m.group(1))) if m else (None, None)
def is_red(px):
return abs(px[0] - RED[0]) + abs(px[1] - RED[1]) + abs(px[2] - RED[2]) <= 30
def red_ratio(im):
"""朱砂像素占全板比例(%)。透明像素不算红。"""
im = im.convert("RGBA")
w, h = im.size
px = im.load()
n = 0
for y in range(h):
for x in range(w):
p = px[x, y]
if p[3] > 128 and is_red(p):
n += 1
return 100.0 * n / (w * h)
def ink_mask(im):
"""返回 (mask, w, h)。mask[y][x]=1 表示该像素是"墨"。
白底板:非白即墨;透明底:不透明即墨。"""
im = im.convert("RGBA")
w, h = im.size
px = im.load()
opaque_white = 0
total = 0
mask = []
for y in range(h):
row = []
for x in range(w):
r, g, b, a = px[x, y]
total += 1
if a <= ALPHA_EDGE:
row.append(0)
continue
if r >= 245 and g >= 245 and b >= 245 and a >= 250:
row.append(0)
continue
row.append(1)
mask.append(row)
return mask, w, h, px
def bbox(mask, w, h):
xs = [x for row in mask for x, v in enumerate(row) if v]
ys = [y for y, row in enumerate(mask) if any(row)]
if not xs or not ys:
return None
return min(xs), min(ys), max(xs), max(ys)
def check_circle_lossless(path, label, must_fail=False):
"""内切圆**之外**的像素必须全透明 —— 头像版是"圆即底板",方版被圆裁掉的是底板四角。
⚠ 这条**不是**"咬字"判据:实测两版白字最远极径都在内切圆内(余量 8.0% / 10.3%),
它判的是"这枚圆是被设计的,还是被裁出来的"。"""
im = Image.open(path).convert("RGBA")
w, h = im.size
cx = cy = (w - 1) / 2.0
r = w / 2.0
px = im.load()
viol = 0
for y in range(h):
dy = y - cy
for x in range(w):
dx = x - cx
if dx * dx + dy * dy > (r + 1.0) ** 2 and px[x, y][3] > ALPHA_EDGE:
viol += 1
total = w * h
if viol:
msg = f"{label}: 内切圆外残留 {viol} 个不透明像素({100.0*viol/total:.2f}%)⇒ 圆裁会切掉底板四角,方版语义丢失"
if must_fail:
expected.append("B 圆角方版负对照: " + msg)
ok("预期红(负对照被抓):" + msg)
else:
bad(msg)
else:
msg = f"{label}: 圆外零残留,圆即底板"
(bad if must_fail else ok)(f"负对照未被抓 ⇒ B 条无约束力:{msg}" if must_fail else msg)
def check_plate(path, label, must_fail=False):
"""must_fail=True 用于负对照:判红是**预期红**,登记进 expected 而不是计进失败数
(否则"闸抓得越准,退出码越红",正是记忆里那条退出码分档的反例)。"""
mask, w, h, px = ink_mask(Image.open(path))
bb = bbox(mask, w, h)
if not bb:
(bad if not must_fail else ok)(f"{label}: 一个墨像素都没有")
return
x0, y0, x1, y1 = bb
l, r, t, b = x0, w - 1 - x1, y0, h - 1 - y1
msg = f"{label}: 墨 {x1-x0+1}x{y1-y0+1} 左右差 {l-r}、上下差 {t-b}"
if max(l, r) >= w or max(t, b) >= h:
(ok if must_fail else bad)("预期红:墨越出板外 —— " + msg if must_fail else "墨越出板外 —— " + msg)
return
if abs(l - r) > 1 or abs(t - b) > 1:
if must_fail:
expected.append("E 平移负对照: " + msg)
ok("预期红(负对照被抓):" + msg)
else:
bad("未居中 —— " + msg)
else:
if must_fail:
bad(f"负对照未被抓 ⇒ E 条无约束力:{msg}")
else:
ok("居中 —— " + msg)
def main():
if not os.path.isdir(PKG):
print(f"FATAL 资产包缺失:{PKG}")
return 2
import json
rp = os.path.join(PKG, "pack-report.json")
if not os.path.exists(rp):
print(f"FATAL 装配报告缺失:{rp} ⇒ 先跑 wecom-pack.cjs,别拿半套包过闸")
return 2
report = json.load(open(rp, encoding="utf-8"))
files = sorted(f for f in os.listdir(PKG) if f.endswith(".png"))
if len(files) < 14:
print(f"FATAL 只找到 {len(files)} 张 PNG,少于 14 ⇒ 判据覆盖面不足")
return 2
print(f"[A] IHDR 尺寸必须等于文件名声明({len(files)} 张)")
for f in files:
want = name_size(f)
got = Image.open(os.path.join(PKG, f)).size
(ok if got == want else bad)(f"{f}: 声明 {want[0]}x{want[1]} 实测 {got[0]}x{got[1]}")
print("\n[A2] 装配报告登记的每张必须真在盘上(防「备好但从未跑成」)")
declared, present = set(report.get("files", {})), set(files)
missing, extra = sorted(declared - present), sorted(present - declared)
(ok if not missing else bad)(f"登记 {len(declared)} 张,盘上缺 {len(missing)} 张" + "".join(f" [{m}]" for m in missing))
(ok if not extra else bad)(f"盘上未登记 {len(extra)} 张" + "".join(f" [{e}]" for e in extra))
print("\n[B] 头像:圆即底板(内切圆外不许有任何不透明像素)")
for f in files:
if f.startswith("wecom-avatar-"):
check_circle_lossless(os.path.join(PKG, f), f)
print(" —— 负对照(现网圆角方版,必须被判红)")
check_circle_lossless(os.path.join(HERE, "assets-delivery", "icon-512x512.png"), "icon-512x512.png", must_fail=True)
print("\n[C] 头像:中心是朱砂地(白文印的底不能丢)")
for f in files:
if f.startswith("wecom-avatar-"):
im = Image.open(os.path.join(PKG, f)).convert("RGBA")
c = im.load()[im.size[0] // 2, im.size[1] // 2]
(ok if is_red(c) else bad)(f"{f}: 中心像素 {c[:3]}")
print("\n[D] 头像:512 与 144 两档的朱砂占比必须同格(容差按抗锯齿的 1/尺寸律给,不假装它是 0)")
for kind in ("full", "ring2"):
ratios = {}
for px_ in (512, 144):
p = os.path.join(PKG, f"wecom-avatar-{kind}-{px_}.png")
if os.path.exists(p):
ratios[px_] = red_ratio(Image.open(p))
if len(ratios) == 2:
d = abs(ratios[512] - ratios[144])
(ok if d <= 3.0 else bad)(f"{kind}: 512 占 {ratios[512]:.2f}% / 144 占 {ratios[144]:.2f}% 差 {d:.2f}pt(闸 3.0)")
print(" —— 负对照(把圆面缩 30%,模拟被咬/缩水,必须被抓)")
with tempfile.TemporaryDirectory() as td:
im = Image.open(os.path.join(PKG, "wecom-avatar-full-512.png")).convert("RGBA")
small = im.resize((358, 358), Image.LANCZOS)
canvas = Image.new("RGBA", (512, 512), (0, 0, 0, 0))
canvas.paste(small, (77, 77), small)
p2 = os.path.join(td, "wecom-avatar-shrunk-512.png")
canvas.save(p2)
base = red_ratio(Image.open(os.path.join(PKG, "wecom-avatar-full-512.png")))
shrunk = red_ratio(Image.open(p2))
d = abs(base - shrunk)
(ok if d > 3.0 else bad)(f"负对照缩水后占比 {base:.2f}%→{shrunk:.2f}% 差 {d:.2f}pt ⇒ " + ("被抓" if d > 3.0 else "未被抓 ⇒ D 条对'面变小'不敏感"))
print("\n[E] 企业logo 板:居中 + 尺寸")
for f in files:
if f.startswith("wecom-logo-"):
check_plate(os.path.join(PKG, f), f)
print(" —— 负对照(故意平移 6px,必须被判红)")
with tempfile.TemporaryDirectory() as td:
src = os.path.join(PKG, "wecom-logo-stacked-702x180-white.png")
im = Image.open(src).convert("RGBA")
canvas = Image.new("RGBA", im.size, (255, 255, 255, 255))
canvas.paste(im.crop((6, 0, im.size[0], im.size[1])), (0, 0))
shifted = os.path.join(td, "wecom-logo-shifted-702x180-white.png")
canvas.save(shifted)
check_plate(shifted, "shifted-6px(负对照)", must_fail=True)
print("\n[F] 白底板:朱砂面积 —— 有红的版必须落在 0.1%–10%(R6 面积律,两端都要断);"
"\n 源字标本身不含红的版(name 只走名、不含号 ⇒ 无 A 可加彩)断言恰为 0,不硬要它出红")
src_red = {}
for f, meta in report.get("files", {}).items():
s = os.path.join(HERE, meta.get("source", ""))
src_red[f] = os.path.exists(s) and 'fill="#C41E3A"' in open(s, encoding="utf-8").read()
for f in files:
if f.endswith("-white.png"):
ratio = red_ratio(Image.open(os.path.join(PKG, f)))
if src_red.get(f):
(ok if 0.1 <= ratio <= 10.0 else bad)(f"{f}: 朱砂 {ratio:.2f}%(源含红)")
else:
(ok if ratio == 0.0 else bad)(f"{f}: 朱砂 {ratio:.2f}%(源不含红 ⇒ 期望恰 0)")
print(" —— 负对照(把红涂满整板,必须被判红)")
with tempfile.TemporaryDirectory() as td:
im = Image.open(os.path.join(PKG, "wecom-logo-stacked-702x180-white.png")).convert("RGBA")
px = im.load()
for y in range(im.size[1]):
for x in range(im.size[0]):
if px[x, y][3] > ALPHA_EDGE and not is_red(px[x, y]):
px[x, y] = (RED[0], RED[1], RED[2], 255)
p2 = os.path.join(td, "wecom-logo-allred-702x180-white.png")
im.save(p2)
ratio = red_ratio(Image.open(p2))
caught = not (0.1 <= ratio <= 10.0)
(ok if caught else bad)(f"负对照全红 {ratio:.2f}% ⇒ " + ("被抓" if caught else "未被抓 ⇒ F 条无约束力"))
print("\n[G] 反白版:0 朱砂(裁定「反白不加彩也不加粗」)")
for f in files:
if f.endswith("-reversed.png"):
ratio = red_ratio(Image.open(os.path.join(PKG, f)))
(ok if ratio == 0.0 else bad)(f"{f}: 朱砂 {ratio:.2f}%")
print(" —— 负对照(给反白版塞一枚朱砂 A,必须被判红)")
with tempfile.TemporaryDirectory() as td:
im = Image.open(os.path.join(PKG, "wecom-logo-stacked-702x180-reversed.png")).convert("RGBA")
px = im.load()
n = 0
for y in range(im.size[1]):
for x in range(im.size[0]):
if px[x, y][3] > 128 and n < 400:
px[x, y] = (RED[0], RED[1], RED[2], 255)
n += 1
p2 = os.path.join(td, "wecom-logo-redstain-702x180-reversed.png")
im.save(p2)
ratio = red_ratio(Image.open(p2))
(ok if ratio > 0 else bad)(f"负对照染色 {ratio:.3f}% ⇒ " + ("被抓" if ratio > 0 else "未被抓 ⇒ G 条无约束力"))
print("\n[H] 透明墨色版:不许出现纯白像素(底板没剥干净会留白块)")
for f in files:
if f.endswith("-transparent.png"):
im = Image.open(os.path.join(PKG, f)).convert("RGBA")
px = im.load()
w, h = im.size
n = sum(
1
for y in range(h)
for x in range(w)
if px[x, y][3] > 250 and px[x, y][0] >= 250 and px[x, y][1] >= 250 and px[x, y][2] >= 250
)
(ok if n == 0 else bad)(f"{f}: 纯白不透明像素 {n}")
# 预期红必须有条数下限:一条都没有 = 负对照根本没跑成,那上面所有"ok"都失去自证
(ok if len(expected) >= 2 else bad)(f"预期红登记 {len(expected)} 条(负对照至少 2 条:B 圆角方版、E 平移)")
print("\n预期红明细(负对照,不计失败):")
for m in expected:
print(" 预期红:", m)
print(f"\n{'='*58}\n判红 {len(fails)} 项 / 通过 {len(oks)} 项")
for m in fails:
print(" RED:", m)
return 1 if fails else 0
if __name__ == "__main__":
try:
sys.exit(main())
except SystemExit:
raise
except Exception:
import traceback
traceback.print_exc()
print("EXIT=2 门禁自身崩溃(与判红不是同一件事,别混)")
sys.exit(2)
@@ -0,0 +1,184 @@
// 企业微信资产包(第五十二刀)
// 两类载体,两套判据:
// 头像 —— 企业微信显示为圆形裁切 ⇒ 必须为圆设计(avatar-standard / avatar-ceremonial 已是圆面)
// 企业logo —— 管理后台固定板 702×180(口径为二手转述,见 WECOM-MANIFEST.md 的存疑条)
// 栅格化用仓库自带的 sharp;尺寸一律由 viewBox 反推 density,不靠"看着调"。
const fs = require("fs");
const path = require("path");
const sharp = require("sharp");
const HERE = __dirname;
const REPO = path.dirname(path.dirname(HERE));
const D = path.join(HERE, "assets-delivery");
const OUT = path.join(HERE, "assets-wecom");
const AVATARS = {
full: path.join(D, "avatar-standard.svg"),
ring2: path.join(D, "avatar-ceremonial.svg"),
};
const LOGOS = {
stacked: { ink: path.join(REPO, "public/logo.svg"), reversed: path.join(REPO, "public/logo-white.svg") },
name: { ink: path.join(D, "name-alone.svg"), reversed: path.join(D, "name-alone-reversed.svg") },
};
const PLATE = { w: 702, h: 180 };
const PAD = 0.86; // 留白版:板内四周各内缩 7% 板高(13px)后再装墨
function viewBox(file) {
const m = /viewBox="([^"]+)"/.exec(fs.readFileSync(file, "utf8"));
if (!m) throw new Error(`${path.basename(file)} 没有 viewBox`);
const [, , w, h] = m[1].split(/\s+/).map(Number);
if (!(w > 0 && h > 0)) throw new Error(`${path.basename(file)} viewBox 非法: ${m[1]}`);
return { w, h };
}
// 纯路径校验:交付件不许有 <text>,不许引外部字体
// ⚠ 先剥 XML 注释 —— 这些文件的来源注释里就写着「现网那份用 <text>」,不剥会把判据读成自伤
function assertPurePaths(file) {
const s = fs.readFileSync(file, "utf8").replace(/<!--[\s\S]*?-->/g, "");
if (/<text/.test(s)) throw new Error(`${path.basename(file)} 含 <text>`);
if (/https?:\/\//.test(s.replace(/xmlns="[^"]*"/g, ""))) throw new Error(`${path.basename(file)} 含外链`);
}
async function raster(svg, targetH) {
const vb = viewBox(svg);
const density = (72 * targetH) / vb.h; // 1 用户单位 = targetH/vb.h 设备像素
// ⚠ sharp.resize(宽, 高):targetH 是**高**,别把它当宽传进去(上一版就是这么把墨块排成 180×384 的)
return sharp(svg, { density }).resize(Math.round((targetH * vb.w) / vb.h), targetH, { fit: "fill" }).png().toBuffer();
}
// 按**墨盒**居中,不按画布盒。实测这些字标的 viewBox 上下留了空盒:
// name-alone 画布高 96 而墨只 66 单位,stacked 画布 119.82 而墨 100 上下各空 —— 不裁就直接偏心。
async function trimInk(buf) {
const { data, info } = await sharp(buf).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
const { width: w, height: h } = info;
let x0 = w, y0 = h, x1 = -1, y1 = -1;
for (let y = 0; y < h; y++) {
for (let x = 0; x < w; x++) {
if (data[(y * w + x) * 4 + 3] > 8) {
if (x < x0) x0 = x;
if (x > x1) x1 = x;
if (y < y0) y0 = y;
if (y > y1) y1 = y;
}
}
}
if (x1 < x0) throw new Error("一个不透明像素都没有");
const meta = await sharp(buf).metadata();
const slack = { top: y0, bottom: meta.height - 1 - y1, left: x0, right: meta.width - 1 - x1 };
const cropped = await sharp(buf).extract({ left: x0, top: y0, width: x1 - x0 + 1, height: y1 - y0 + 1 }).png().toBuffer();
return { buf: cropped, slack };
}
// 先高倍栅格 + 裁墨,再把**墨盒**装进板内最大缩放 —— 两个理由:
// ① 这些字标的 viewBox 上下带空盒(实测 stacked 墨只占画布高 73%、name 52%),按画布排等于缩得不够;
// ② name 的墨宽高比实测 4.50,比 702×180 的板(3.90)还扁 ⇒ 它只能按**宽**限死,按高排必溢出。
async function inkFit(svg, boxW, boxH) {
const probe = 720;
const { buf: trimmed } = await trimInk(await raster(svg, probe));
const m = await sharp(trimmed).metadata();
const sW = boxW / m.width;
const sH = boxH / m.height;
const s = Math.min(sW, sH);
const w = Math.round(m.width * s);
const h = Math.round(m.height * s);
const buf = await sharp(trimmed).resize(w, h, { fit: "fill" }).png().toBuffer();
return { buf, limit: sW < sH ? "width" : "height", inkOverCanvas: m.height / probe, aspect: m.width / m.height };
}
async function plate(inkBuf, bg) {
const m = await sharp(inkBuf).metadata();
const left = Math.round((PLATE.w - m.width) / 2);
const top = Math.round((PLATE.h - m.height) / 2);
const buf = await sharp({ create: { width: PLATE.w, height: PLATE.h, channels: 4, background: bg } })
.composite([{ input: inkBuf, left, top }])
.png()
.toBuffer();
return { buf, ink: { w: m.width, h: m.height }, pad: { l: left, r: PLATE.w - m.width - left, t: top, b: PLATE.h - m.height - top } };
}
const WHITE_BG = { r: 255, g: 255, b: 255, alpha: 1 };
const CLEAR = { r: 0, g: 0, b: 0, alpha: 0 };
(async () => {
fs.mkdirSync(OUT, { recursive: true });
const report = { plate: PLATE, pad: PAD, files: {} };
for (const [kind, svg] of Object.entries(AVATARS)) {
assertPurePaths(svg);
for (const px of [512, 144]) {
const name = `wecom-avatar-${kind}-${px}.png`;
const buf = await raster(svg, px);
await sharp(buf).resize(px, px, { fit: "fill" }).png().toFile(path.join(OUT, name));
report.files[name] = { source: path.relative(HERE, svg), size: `${px}x${px}`, kind: "avatar" };
}
}
for (const [variant, src] of Object.entries(LOGOS)) {
assertPurePaths(src.ink);
assertPurePaths(src.reversed);
const padPx = Math.round(PLATE.h * ((1 - PAD) / 2));
const boxes = { full: { w: PLATE.w, h: PLATE.h }, pad: { w: PLATE.w - 2 * padPx, h: PLATE.h - 2 * padPx } };
for (const [fit, box] of Object.entries(boxes)) {
const suffix = fit === "full" ? "" : "-pad";
const jobs = [
[`wecom-logo-${variant}${suffix}-${PLATE.w}x${PLATE.h}-white.png`, src.ink, WHITE_BG],
[`wecom-logo-${variant}${suffix}-${PLATE.w}x${PLATE.h}-transparent.png`, src.ink, CLEAR],
[`wecom-logo-${variant}${suffix}-${PLATE.w}x${PLATE.h}-reversed.png`, src.reversed, CLEAR],
];
for (const [name, svg, bg] of jobs) {
const { buf: inkBuf, limit, aspect, inkOverCanvas } = await inkFit(svg, box.w, box.h);
const { buf, ink, pad } = await plate(inkBuf, bg);
await fs.writeFileSync(path.join(OUT, name), buf);
report.files[name] = {
source: path.relative(HERE, svg),
size: `${PLATE.w}x${PLATE.h}`,
kind: "plate",
ink,
pad,
limit,
inkAspect: Number(aspect.toFixed(3)),
inkOverCanvas: Number(inkOverCanvas.toFixed(3)),
};
}
if (fit === "full") {
// @2x 高清备份(只出白底板,上传框按 702×180 用)
const big = { w: PLATE.w * 2, h: PLATE.h * 2 };
const { buf: trimmed } = await inkFit(src.ink, big.w, big.h);
const m = await sharp(trimmed).metadata();
const name = `wecom-logo-${variant}-2x-${big.w}x${big.h}-white.png`;
const left = Math.floor((big.w - m.width) / 2);
const top = Math.floor((big.h - m.height) / 2);
const buf = await sharp({ create: { width: big.w, height: big.h, channels: 4, background: WHITE_BG } })
.composite([{ input: trimmed, left, top }])
.png()
.toBuffer();
await fs.writeFileSync(path.join(OUT, name), buf);
report.files[name] = {
source: path.relative(HERE, src.ink),
size: `${big.w}x${big.h}`,
kind: "plate",
ink: { w: m.width, h: m.height },
pad: { l: left, r: big.w - m.width - left, t: top, b: big.h - m.height - top },
};
}
}
}
report.avatars = Object.keys(AVATARS);
fs.writeFileSync(path.join(OUT, "pack-report.json"), JSON.stringify(report, null, 2));
const names = Object.keys(report.files).sort();
console.log(`生成 ${names.length} 张 → assets-wecom/`);
for (const n of names) {
const f = report.files[n];
const kb = (fs.statSync(path.join(OUT, n)).size / 1024).toFixed(1);
console.log(
` ${n} ${f.size} ${kb}KB` +
(f.ink ? ` 墨${f.ink.w}x${f.ink.h} 留白 l${f.pad.l}/${f.pad.r} t${f.pad.t}/${f.pad.b}` : "") +
(f.inkOverCanvas ? ` 墨/画布 ${f.inkOverCanvas} 墨宽高比 ${f.inkAspect}` : "")+(f.limit ? ` 限${f.limit}` : "")
);
}
})().catch((e) => {
console.error("FAIL", e.message);
process.exit(1);
});