AGENT SKILL

pillow-favicon-set-no-rasterizer

Errors like "rsvg-convert: command not found", "convert: command not found" (ImageMagick), "No module named 'cairosvg'", or no Inkscape on PATH when trying to turn an SVG mark into favicon.ico / apple-touch-icon.png / og-card.png. Use when a site needs a raster favicon set (site-og-favicon-verify's checklist) and installing a full SVG rasterizer is unavailable, heavy, or blocked, and the mark is a simple geometric shape + letter/glyph (most lettermark logos qualify).

License 许可
MIT
最近更新
2026-11-07
Stars
★ 1
Forks
1

01 前言 Front Matter

name
pillow-favicon-set-no-rasterizer
description
Errors like "rsvg-convert: command not found", "convert: command not found" (ImageMagick), "No module named 'cairosvg'", or no Inkscape on PATH when trying to turn an SVG mark into favicon.ico / apple-touch-icon.png / og-card.png. Use when a site needs a raster favicon set (site-og-favicon-verify's checklist) and installing a full SVG rasterizer is unavailable, heavy, or blocked, and the mark is a simple geometric shape + letter/glyph (most lettermark logos qualify).

03 SKILL.md 正文

Generate a raster favicon set without an SVG rasterizer

Symptom

You have an SVG logo/mark and need the raster fallback set — favicon.ico, apple-touch-icon.png, maybe og-card.png — but every standard SVG→PNG path is unavailable on the machine:

$ rsvg-convert -w 512 -h 512 logo.svg -o logo.png
zsh: command not found: rsvg-convert

$ convert logo.svg -resize 512x512 logo.png
zsh: command not found: convert

$ python -c "import cairosvg"
ModuleNotFoundError: No module named 'cairosvg'

Inkscape isn't installed either, and pulling in a full SVG renderer (system package or a heavy Python wheel) just to emit a handful of static PNGs once feels disproportionate — especially in CI or a sandboxed dev container where you can't brew install anything.

Root cause

SVG rasterization needs a real rendering engine (librsvg, ImageMagick's delegate, a cairo build, Inkscape) — none of which ship by default on macOS or a minimal Linux image, and installing one is a system-level dependency just to produce icons that, once generated, never need to change again.

But most favicon marks aren't complex vector art — they're a filled shape (rounded rect, circle) plus one or two characters of text. That's exactly what Pillow's ImageDraw primitives + ImageFont can render directly, with zero SVG parsing involved.

Fix

Don't rasterize the SVG — redraw the mark directly in Pillow at a large master size, then downscale/save every target format from that one master. This only works when the mark is geometric-shape + text; a hand-drawn or gradient-rich SVG still needs a real rasterizer.

from PIL import Image, ImageDraw, ImageFont

# 1. Draw at a large master size (512) so downscaling stays crisp.
img = Image.new("RGBA", (512, 512), (0, 0, 0, 0))
d = ImageDraw.Draw(img)
d.rounded_rectangle([0, 0, 511, 511], radius=112, fill=(180, 84, 46))

# Font path is a parameter: the default below is macOS-only. On Linux/CI pass
# any .ttf (e.g. DejaVuSans-Bold.ttf); if it can't be loaded, fall back to
# Pillow's bundled font (load_default(size=...) needs Pillow >= 10.1).
FONT_PATH = "/System/Library/Fonts/Supplemental/Georgia.ttf"
FONT_SIZE = 358
try:
    font = ImageFont.truetype(FONT_PATH, FONT_SIZE)
except OSError:
    font = ImageFont.load_default(size=FONT_SIZE)
bb = d.textbbox((0, 0), "S", font=font)
w, h = bb[2] - bb[0], bb[3] - bb[1]
d.text(((512 - w) / 2 - bb[0], (512 - h) / 2 - bb[1]), "S",
        font=font, fill=(253, 253, 251))

# 2. favicon.ico: save the 512 master directly. Pillow downscales it into each
#    requested size. Do NOT pre-resize to 32x32 first — Pillow drops any ICO
#    size larger than the source image, so the 48x48 entry would silently vanish.
img.save("favicon.ico", sizes=[(16, 16), (32, 32), (48, 48)])

# 3. apple-touch-icon.png: 180x180, FULL-BLEED + OPAQUE.
#    iOS applies its own rounded-corner mask — a transparent or
#    already-rounded source shows as a square-with-a-hole on the home screen.
touch = Image.new("RGB", (512, 512), (180, 84, 46))
touch.paste(img, (0, 0), img)  # composite over opaque background, drop alpha
touch.resize((180, 180)).save("apple-touch-icon.png")

Then wire the full set into the page head (root vs nested pages need the relative prefix adjusted):

<link rel="icon" href="/favicon.svg" type="image/svg+xml">
<link rel="icon" href="/favicon.ico" sizes="any">
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
<link rel="manifest" href="/site.webmanifest">
<meta name="theme-color" content="#b4542e">

Keep the generator as a dev-only script (uv add --dev pillow or equivalent), not a runtime dependency, and commit the generated raster files — they're build artifacts of a one-off, not something regenerated on every deploy. Re-running the script is how you handle a rebrand.

Evidence

Used on a static marketing site (a private document-scanner app's site skeleton) whose favicon was a single letter on a rounded-square tile — SVG existed, but the dev container had no rsvg-convert/ImageMagick/cairosvg/Inkscape and installing one wasn't worth it for a handful of PNGs. Same pattern applies to any lettermark or simple-geometric favicon across the portfolio's site skeletons.

Related skills

  • site-og-favicon-verify — the checklist/lint for what a correct favicon
    • og:image + CSP setup looks like (sizes, absolute URLs, opaque apple-touch-icon). This skill is the how-to for actually producing the raster files that checklist expects, specifically when no SVG rasterizer is on hand.
  • site-pages-deploy-kit — the site skeleton and verify-site.sh that checks the favicon set this skill generates; also references an idempotent "generate everything from one master image" script pattern this skill implements without a rasterizer dependency.
  • alternate-app-icons — iOS app icon (Home Screen, asset catalog, CFBundleAlternateIcons) generation and switching; unrelated to web favicons despite the naming overlap — don't conflate the two icon systems.

04 同仓库更多 Skills

abhijitbansal
abhijitbansal/claude-skills

second-wind

Orchestrate long unattended Claude Code runs across multiple repos with the wind CLI. Use when the user wants to run Claude Code overnight, resume sessions after the 5-hour usage limit, run Claude in many repos at once via tmux, or says "set up second wind", "wind up", "overnight run", "resume after limit", "usage limit orchestrator".

★ 1
abhijitbansal
abhijitbansal/claude-skills

structured-output-adaptive-thinking-token-bloat

A Claude API call using output_config.format (json_schema structured outputs) with thinking:{type:"adaptive"} burns most of its output budget on thinking (observed ~21k of ~24k tokens) without improving JSON quality, making the run up to ~5x more expensive than the same call with thinking omitted — use when calling the Messages API with a json_schema output format for extraction, ranking, classification, or summarization tasks, or when a schema-constrained call's usage.output_tokens is far larger than the returned JSON.

★ 1
abhijitbansal
abhijitbansal/claude-skills

review

Apply a code-review lens to a diff, branch, or file — find correctness bugs, security issues, and quality problems, ranked by severity, with a concrete fix for each. Use when the user says "review this", "review my diff", "check this PR", "look this over before I commit", or "is this safe". Skip when the user wants the code written, not reviewed.

★ 1
abhijitbansal
abhijitbansal/claude-skills

refresh

Rebuild the prompt-craft command registry and usage profile, and print a summary of installed commands and your personalized recommendations. Use when you install or update plugins and want the advisor to pick them up immediately, or say "refresh prompt-craft", "rebuild the command registry".

★ 1
abhijitbansal
abhijitbansal/claude-skills

refactor

Apply a refactoring lens — restructure code without changing behavior, guarded by tests that pass before and after. Use when the user says "refactor", "clean this up", "extract this", "simplify this", "reduce duplication", or "make this readable" on existing working code. Skip when the change is meant to alter behavior (that's a feature or a fix).

★ 1
abhijitbansal
abhijitbansal/claude-skills

plan

Decompose a non-trivial task into an explicit, tracked plan with goals and per-step acceptance criteria before writing code. Use when the user says "plan this", "break this down", "what's the plan", or asks for a multi-step feature/refactor that touches more than one file. Pairs with plan mode. Skip for single-edit changes that need no decomposition.

★ 1