cssmagic/agent-skills/fix-svg-aspect-ratio

Claude Code and agent skill by cssmagic/agent-skills

Trust tier 2
  • community
LLM review pending
Source check pending

Checking that the SKILL.md file is still in the repository.

Use when SVG files render with a distorted aspect ratio, especially vector SVG assets exported by Figma Desktop MCP.

Install

npx vskill@latest install cssmagic/agent-skills/fix-svg-aspect-ratio

SKILL.md

The same SKILL.md was published earlier as cssmagic/agent-skills/fix-svg-aspect-ratio.

Fix SVG Aspect Ratio

Purpose

Fix SVG files whose root <svg> attributes can make the artwork stretch instead of preserving its natural aspect ratio.

This skill is intentionally small and script-backed so other skills can call it as an atomic utility.

Required Input

Each run needs one path:

  • A single SVG file.
  • A directory tree containing SVG files.

If the path is missing or ambiguous, ask the user for it before running commands.

Normalize ~ and relative paths to absolute paths before reporting or running the script.

Defaults

When given a directory, scan .svg files recursively and case-insensitively.

Modify files in place.

Output a non-interactive report every run. This is safe for atomic calls because the script never prompts for input.

Do not infer dimensions from paths, CSS, rendered output, or child elements. If a file has no valid viewBox, report it as unsupported.

Fixes Applied

For each valid SVG root with a valid viewBox, set these root <svg> attributes:

  • preserveAspectRatio="xMidYMid meet"
  • width from the third viewBox number
  • height from the fourth viewBox number

Also remove display: block from the root style attribute. If the style attribute has other declarations, keep them.

Do not modify internal SVG content such as <g>, <path>, <defs>, gradients, ids, or fill values.

Workflow

Set the path from the user's provided input:

bash
target="/absolute/path/to/file-or-directory"

Run the bundled script from this skill directory:

bash
python3 scripts/fix_svg_aspect_ratio.py "$target"

The script validates each SVG before writing, writes to a temporary file beside the source, then atomically replaces the original file.

Reporting

The script outputs every SVG file grouped by result type:

  • Fixed - processing succeeded and the file was changed.
  • Already Correct - the SVG already matched the expected root attributes.
  • Unsupported - the SVG was readable but not safe to process, such as a missing or invalid viewBox.
  • Failed - the script could not read, parse, or write the file.

Example output:

text
- Fixed (1):
- /absolute/path/to/file-1.svg
- Already Correct (2):
- /absolute/path/to/file-2.svg
- /absolute/path/to/file-3.svg
- Unsupported (1):
- /absolute/path/to/file-4.svg: missing or invalid viewBox
- Failed (4):
- /absolute/path/to/file-5.svg: not valid UTF-8: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
- /absolute/path/to/file-6.svg: XML parse failed: mismatched tag: line 1, column 10
- /absolute/path/to/file-7.svg: root SVG start tag was not found
- /absolute/path/to/file-8.svg: write failed: [Errno 13] Permission denied

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewNot runA model review is scheduled for the next rescan.

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/cssmagic/agent-skills/fix-svg-aspect-ratio/badge)](https://verified-skill.com/skills/cssmagic/agent-skills/fix-svg-aspect-ratio)

Something wrong with this skill or its page? Tell us.