svg-to-raster
Use when the user wants to rasterize SVG files — convert SVG to PNG, PDF, or PostScript at a chosen resolution. Wraps CairoSVG (Python, in the plugin venv). Single file or batch. Companion to `vectorize` (other direction). Triggers - "convert this SVG to PNG", "render my icons at 2x", "I need a raster version of this logo".
- License 许可
- MIT
- 最近更新
- 2026-11-10
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- svg-to-raster
- description
- Use when the user wants to rasterize SVG files — convert SVG to PNG, PDF, or PostScript at a chosen resolution. Wraps CairoSVG (Python, in the plugin venv). Single file or batch. Companion to `vectorize` (other direction). Triggers - "convert this SVG to PNG", "render my icons at 2x", "I need a raster version of this logo".
- allowed-tools
- Bash(command *), Bash(test *), Bash(find *), Bash(mkdir *), Bash(rm *), Bash(wc *), Read, Write
03 SKILL.md 正文
SVG to Raster
Rasterize SVG files to PNG / PDF / PS via CairoSVG. Runs from the plugin's uv venv — no system Python pollution.
When to use
- Convert logo / icon / diagram SVGs to PNG for use in slides, social, or pipelines that don't accept SVG.
- Render an SVG at multiple resolutions (e.g. 1×, 2×, 3× for app assets).
- Bake an SVG into a PDF for print or archival.
Do not use this skill when:
- Source is already raster — wrong direction; use
vectorizeinstead. - You need to edit the SVG — CairoSVG is render-only.
- The SVG uses advanced filters / unsupported CSS — CairoSVG covers SVG 1.1 well but newer features may not render. Inspect output and warn the user.
Inputs
- Input — SVG file or directory. Required.
- Format —
png(default),pdf,ps. - Output dir — default:
<input-dir>/<format>/. Never overwrites originals. - Scale — multiplier on the SVG's intrinsic size. Default
1.0. Use2.0,3.0for hi-DPI. - Width / Height — explicit pixel dimensions (overrides scale). Pass one to preserve aspect; both to force.
- DPI — for PDF/PS output. Default
96. - Background — default transparent. Pass a CSS colour (
#ffffff,white) for solid fill. - Recursive —
--recursivefor directory descent.
Procedure
-
Resolve venv:
VENV_DIR="${CLAUDE_USER_DATA:-${XDG_DATA_HOME:-$HOME/.local/share}/claude-plugins}/image-ops/venv". -
Verify
cairosvgis importable in the venv:"$VENV_DIR/bin/python" -c "import cairosvg" 2>&1If missing → point at
image-ops-install-deps. If it imports but raises a libcairo error, surface the system-lib install command (sudo apt install libcairo2/brew install cairo). -
Enumerate
*.svginputs (case-insensitive). Skip non-SVG with note. -
Call CairoSVG via the venv Python (keeps the skill self-contained — no helper script needed). Pass the gathered options as arguments rather than string-substituting them into the source; the script below dispatches on format and builds the kwargs itself:
"$VENV_DIR/bin/python" - "$input" "$output" "$fmt" \ "$scale" "$width" "$height" "$dpi" "$background" <<'PYEOF' import sys, cairosvg src, dst, fmt, scale, width, height, dpi, bg = sys.argv[1:9] fn = {'png': cairosvg.svg2png, 'pdf': cairosvg.svg2pdf, 'ps': cairosvg.svg2ps}[fmt] kwargs = {'url': src, 'write_to': dst} # Empty string means "not supplied" — omit rather than passing a default # that would override CairoSVG's own. if scale: kwargs['scale'] = float(scale) if width: kwargs['output_width'] = int(width) if height: kwargs['output_height'] = int(height) if dpi: kwargs['dpi'] = int(dpi) if bg: kwargs['background_color'] = bg fn(**kwargs) PYEOFFunction map:
png → svg2png,pdf → svg2pdf,ps → svg2ps.Note that
output_width/output_heightoverridescalein CairoSVG — do not pass both unless that is what the user asked for. -
Track file sizes and any render warnings (CairoSVG prints to stderr for unsupported features). Wrap each conversion so one bad file does not kill the batch:
if ! "$VENV_DIR/bin/python" - ... <<'PYEOF' ... PYEOF then echo "FAILED: $input" >> "$failed_log" rm -f "$output" continue fiRemoving the partial
$outputmatters — a truncated PNG left on disk reads as a successful conversion to the summary.
Output
- Rasterized files at
<output-dir>/. - Summary:
- Files processed / failed, with the failed paths from
$failed_log. - Per-file: source dimensions → output dimensions, output size.
- Any render warnings (unsupported SVG features).
- Files processed / failed, with the failed paths from
Notes
- CairoSVG is LGPL-3.0; using it as a CLI dependency is fine, no licence contagion.
- For multi-resolution batch (e.g. app icon set), call this skill multiple times with different
--scalevalues, or wrap in a small loop. - If you need true SVG editing or advanced filter support, look at Inkscape CLI (
inkscape --export-type=png). CairoSVG is the lighter-weight pure-Python option. - Animated SVG (SMIL) is not supported — CairoSVG renders the initial frame only.
04 同仓库更多 Skills
no-description
暂无简介
good-skill
Fixture skill that satisfies every rule.
broken-link
Links to a reference file that does not exist.
Bad_Name
Name violates the kebab-case rule and does not match the directory.
skill-authoring
Write, review, and validate portable agent skills in SKILL.md format. Use when creating a new skill, editing an existing one, or asked whether a skill follows the Agent Skills spec.
weigh-bags
Record scale readings for each bag — empty (tare), outbound, current, final — and reconcile them against the itemised inventory to find unaccounted weight. Use when the user gives a bag weight, says how heavy something is, weighs their luggage, or asks how close to the limit they are. Appends to bags.yaml and runs scripts/reconcile.py.