web-asset-generator
Generate web assets including favicons, app icons (PWA), and social media meta images (Open Graph) for Facebook, Twitter, WhatsApp, and LinkedIn. Use when users need icons, favicons, social sharing images, or Open Graph images from logos or text slogans. Handles image resizing, text-to-image generation, and provides proper HTML meta tags.
1实现原理 · 为什么它能做到
能力全部落在两个本地 Python 脚本上(Pillow 画图/缩放),skill 正文的作用是把『问什么、跑哪个脚本、怎么交付』编排成固定流程。
3. **Run the appropriate script(s)**: - Favicons/icons: `scripts/generate_favicons.py` - Social media images: `scripts/generate_og_images.py`
交互纪律被写成硬要求:所有需求澄清必须走 AskUserQuestion(可视选项),并给出 8 套标准问题模板覆盖资产类型、源材料、平台、配色、图标语义、代码集成与验证。
**IMPORTANT**: Always use the AskUserQuestion tool to gather requirements instead of plain text questions. This provides a better user experience with visual selection UI.
图标生成的实质是 Pillow 缩放链:源图转 RGBA 保留透明、LANCZOS 重采样逐尺寸落 PNG,另生成含 16/32 两档的多分辨率 .ico。
icon_16.save(ico_path, format='ICO', sizes=[(16, 16), (32, 32)])
emoji 路线是本地渲染 + 本地词库推荐:60+ 条带关键词的 emoji 库做打分推荐,选中后用 Pilmoji 把 emoji 画进画布。
# Curated emoji database with keywords for better matching
文字类 OG 图靠字符数决定字号(短 144 / 中 120 / 长 102 / 超长 84)、按宽度换行、logo 限高 20%——即用参数化排版代替做图。
# Medium text: use base size return base_size # 120px elif text_length <= 60: # Long text: reduce slightly return int(base_size * 0.85) # 102px
质量校验是本地纯计算:按平台要求表检查体积/尺寸/比例/格式,文本图另算 WCAG 对比度分级。
PLATFORM_REQUIREMENTS = { 'facebook': { 'max_file_size': 8 * 1024 * 1024, # 8MB 'recommended_size': (1200, 630), 'min_size': (600, 315), 'aspect_ratio': 1.91, 'formats': ['png', 'jpg', 'jpeg'], },
交付环节包含『代改代码』:按用户选择自动探测框架(Next/Astro/SvelteKit/Vue-Nuxt/Gatsby/纯 HTML)→ 找目标文件 → 展示 diff → 用户确认后用 Edit 工具插入 meta/link 标签。
**If user selects "Yes, auto-detect":** 1. Search for framework config files (next.config.js, astro.config.mjs, etc.) 2. Detect framework type
平台规格知识单独成册(references/specifications.md),skill 正文只引用不内嵌,避免把尺寸表塞进每次上下文。
For detailed platform specifications, size requirements, and implementation guidelines, read: - `references/specifications.md`: Comprehensive specs for all platforms
2核心能力
3外部依赖
| Kind | Dependency / Endpoint |
|---|---|
| package | Pillow(PIL,必需) |
| package | pilmoji(emoji 渲染,可选) |
| package | emoji(emoji 关键词/版本检测,可选且被检查器要求 <2.0.0) |
| network | 无代码级网络出口;仅在 SKILL.md/references 里给出外部验证工具链接供用户自行访问 |
4管控建议与判定依据
- scripts/: 执行本地脚本或命令: python scripts/generate_favicons.py <source_image> <output_dir> [favicon|ap
- scripts/ 或 SKILL.md: 声明动态安装外部语言包依赖
- 本地工作目录: 文件读写与工件输出: 输出目录下生成 PNG/ICO:favicon-16x16/32x32/96x96.png、favicon.ico、apple-touch-icon.
5第二遍独立确认
- [ok] 『无网络外发』结论 — 5 个脚本逐文件扫描:import 仅 PIL/pilmoji/emoji/colorsys/textwrap/argparse/pathlib/io/sys/os/re;无 requests/urllib/socket/http.client/subprocess/os.system/eval/exec;全目录 URL 仅出现在 SKILL.md 与 references/specifications.md 的文档说明中。
- [ok] 『无凭证读取』结论 — 无 os.environ/getenv;check_dependencies.py 只做 try-import 探测并打印 pip 安装建议;仓库无 .env 示例、无 key 常量。
- [ok] 尺寸与字号常量与文档一致 — generate_favicons.py ICON_SIZES(16/32/96)+APP_ICON_SIZES(180/192/512)、generate_og_images.py OG_SIZES(1200x630/1200x675/1200x1200)、calculate_font_size 的 1.2/1.0/0.85 倍率(144/120/102/84)与 SKILL.md Best Practices 的文本长度表逐字吻合。
- [ok] 校验能力真实落地(非仅文档) — validators.py 定义 PLATFORM_REQUIREMENTS(facebook 8MB/1200x630/1.91、twitter 5MB/1200x675/16:9 等)与 ValidationResult;SKILL.md 给出 --validate 用法与 ✓/⚠/❌ 输出示例,两侧一致。
- [ok] emoji 依赖的版本约束 — check_dependencies.py 对 emoji 主版本 <2 判定兼容,否则提示 "Install compatible version: pip install 'emoji<2.0.0'";CLAUDE.md 重复该约束('must use version <2.0.0 for pilmoji compatibility')。属真实存在的第三方兼容性坑,非文档臆造。
- [discrepancy] 『会修改用户代码库』的定性与护栏 — 第一遍只按『本地生成图片』记录,第二遍确认 SKILL.md Question Pattern 7 与交付流程明确要求 agent 探测框架(next.config.js/astro.config.mjs/…)并在用户确认后用 Edit 插入标签——这是对用户源码的写入能力。已据此把 file_writes 拆成『脚本产物』与『经确认的宿主编辑』两类,并在 injection_surface/risks 单列;档位维持 blue(写入仍属本地、且有 diff+确认门)。
- [ok] 字体路径依赖(跨平台可用性) — CLAUDE.md 记录字体 '/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf'(回退默认字体);generate_og_images.py 用 ImageFont 加载,属 Linux 假设,已作为可用性注记写入 verdict.fits/not_for 之外的分析(traits 未夸大跨平台能力)。
- [ok] 外部依赖清单完整性 — 依赖仅 Pillow(必需)与 pilmoji/emoji(可选 emoji 路线),全部为 PyPI 官方包;无 CLI 依赖、无镜像源、无远程服务(对比同类 skill 常见的 ffmpeg/imagemagick 依赖,本 skill 无外部二进制)。
6结论
a6da82bc927a95b8…