A command-line tool for upscaling SVG icons embedded in source files (.tsx, .jsx, .svg, etc.). It automatically detects the current dimensions and scales path coordinates, viewBox, width/height attributes, and stroke widths proportionally.
The script performs these transformations:
- Detects dimensions — reads
viewBox,width/heightattributes, or JSX default params to determine the original size - Scales path data — multiplies all numbers inside
d="..."path attributes by the scale factor - Updates viewBox — adjusts the
viewBoxattribute to the new dimensions - Updates width/height — scales both attribute values and JSX default parameter values
- Scales stroke widths — proportionally adjusts
strokeWidth/stroke-widthvalues
Note: This tool modifies files in place. Use
--dry-runfirst to preview changes, and make sure your files are committed to version control before running.
node upscale-icons.js <target> [options]| Argument | Description |
|---|---|
<target> |
Path to a file or directory containing SVG icon files (required) |
| Option | Short | Default | Description |
|---|---|---|---|
--size |
-s |
64 |
Target width in pixels |
--extensions |
-e |
tsx,jsx,svg |
Comma-separated file extensions to process |
--recursive |
-r |
false |
Recursively process subdirectories |
--stroke-only |
— | false |
Only scale stroke widths, skip coordinate scaling |
--stroke-scale |
— | same as scale | Custom stroke width multiplier |
--dry-run |
— | false |
Preview changes without modifying files |
--help |
-h |
— | Show help message |
node upscale-icons.js ./src/icons --size 64node upscale-icons.js ./logo.svg -s 128node upscale-icons.js ./assets -e svg,jsx -rnode upscale-icons.js ./src/icons --stroke-only --stroke-scale 2node upscale-icons.js ./src/icons --dry-runnode upscale-icons.js ./icons -s 48 --stroke-scale 3SVG Upscaler
──────────────────────────────────────────────────
Target size : 64px (width)
Files found : 13
Mode : full scale
──────────────────────────────────────────────────
✓ src/icons/kid.tsx: 20×20 → 64×64 (×3.20)
✓ src/icons/home.tsx: 24×25 → 64×67 (×2.67)
skip src/icons/logo.tsx (already 64px wide)
skip src/icons/readme.md (could not detect dimensions)
──────────────────────────────────────────────────
Done! 2 processed, 2 skipped, 0 errors.
The dimension auto-detection works with:
- Plain SVG —
<svg viewBox="0 0 24 24" width="24" height="24"> - React/JSX —
function Icon({ width = 24, height = 24 }) { ... } - Any file containing standard SVG
viewBox,width, orheightattributes
- Always use
--dry-runfirst to verify the detected dimensions and scale factor before modifying files. - Aspect ratio is preserved — height is scaled proportionally based on the width scale factor.
- Non-square icons (e.g., 24×25) are handled correctly — the height scales proportionally.
- If
--stroke-scaleis not specified, stroke widths scale by the same factor as coordinates. - The script skips files that are already at the target width.