Skip to content

madLinux7/svg-strip

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

svg-strip

Built with Rust License: MIT Platform

Fast and aggressive SVG minification CLI tool built in Rust, tailored specifically for shrinking SVGs for inline HTML use (like Blade templates) and standalone files.

demo

Features

  • Extreme Minification (automatic): Removes title, desc, metadata, comments, unused ids, hidden elements (display="none", opacity="0"), empty groups, and the <?xml...?> declaration, collapsing all whitespace and linebreaks into a single-line string.
  • Color Shrink (automatic): Identifies 6-digit hex color codes with identical byte pairs (e.g., #FF0000, #aabbcc) across all styling attributes (fill, stroke, etc.) and losslessly converts them into their 3-digit shorthands (e.g., #f00, #abc). Leaves non-matching hex codes safely untouched.
  • Inline Optimization (-i / --inline): Strips the xmlns attributes which are unnecessary overhead for browsers when embedding SVGs directly into HTML5 code.
  • Decimal Precision (-dp / --decimal-precision): Aggressively rounds all path coordinates and attributes (like viewBox, x, y, transform) down to a user-specified number of decimal places (0-4), stripping trailing zeros.

Usage

svg-strip [OPTIONS] <input.svg> [output.svg]

If no output.svg is specified, the tool will automatically save the minified file in the same directory as [ORIGINAL_NAME]_stripped.svg.

Options

Flag Name Description
-i, --inline Inline Mode Strips xmlns attributes for optimal inline HTML usage.
-o, --output Stdout Mode Prints the minified SVG directly to the terminal (stdout) instead of writing to a file.
-dp, --decimal-precision <0-4> Decimal Precision Rounds all floating point numbers inside paths and attributes to the specified number of decimal places to save bytes.

Example

Minify an icon for use in a web template, stripping all namespace overhead and rounding coordinates to 2 decimal places:

svg-strip -i -dp 2 raw_icon.svg

Output:

Stripped SVG written to raw_icon_stripped.svg
• Inline SVG with zero overhead
• Decimal Precision for paths rounded down to 2 decimals
• Color Shrink to convert 6-digit hex codes to 3-digit shorthands

Installation

You must have Rust and Cargo installed. Clone the repository and build the project:

git clone git@github.com:madLinux7/svg-strip.git
cd svg-strip
cargo build --release

The compiled binary will be available in target/release/svg-strip.

About

Strip SVG overhead and metadata. Dead-simple, cross-platform, no dependencies.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages