Skip to content
This repository has been archived by the owner on Oct 30, 2021. It is now read-only.
/ svgcleaner Public archive

svgcleaner could help you to clean up your SVG files from the unnecessary data.

License

Notifications You must be signed in to change notification settings

RazrFalcon/svgcleaner

Repository files navigation

svgcleanerbuild status

svgcleanerhelps you clean up your SVG files, keeping them free from unnecessary data.


The main purpose ofsvgcleaneris to losslessly reduce the size of an SVG image, created in a vector editing application, before publishing.

Usually more than half of an SVG image's data is useless for rendering. For example:

  • Temporary data used by the vector editing application
  • Non-optimal SVG structure representation
  • Unused and invisible graphical elements

... Are all unnecessary in a published SVG.

  1. Correctness-svgcleanershould not break an SVG file
  2. Cleaning ratio- Higher is better
  3. Performance- An average SVG file processing time should be closer to ~1ms on a modern PC

In addition to the main advantages ofsvgcleaner— like correctness, cleaning ratio and performance, which are described below — there are some more nuances to be aware of:

  1. svgcleanercleans only one SVG file. It doesn't process SVGZ files. It doesn't process directories. It doesn't do anything else. Just one task*.
  2. svgcleaneris strictly lossless by default. There are no destructive cleaning options enabled by default.
  3. svgcleaneris portable. You can build it into a single executable without any external dependencies.

* You can get all of these features using theGUI.

SeeTesting notesfor details.

All stats were collected using the latest release version.

Less is better.

More is better.

*scourcreates bigger files (-18.78%).

Less is better.

Collection Size Before (MiB) Size After (MiB) Ratio (%)
Breeze icons theme 21.72 11.09 48.91
Ardis icons theme 11.82 5.23 55.74
Humanity icons theme 8.56 3.08 64.01
Open Icon Library 207.45 69.44 66.53
Elementary icons theme 17.72 7.09 59.95
Adwaita icons theme 2.21 0.37 83.08
Faience icon theme 22.35 11.14 50.16
GCP Icons 0.344 0.082 75.9

Documentation can be foundhere.

svgcleanershouldn't change your file unless you tell it to, but there are still things that can't be preserved. So even if you disable all cleaning options there are still things that will be changed, such as:

  • Original indent is not preserved
  • All colors will be formatted as #RRGGBB and #RGB
  • DOCTYPE, CDATA will be processed and removed
  • CSS support is minimal
  • CSS from thestyleelement will be extracted and processes. Thestyleelement will be removed.
  • Thestyleattribute will be split into attributes
  • Theclassattribute will be processed and removed
  • Paths and transformations will be reformatted
  • currentColorandinheritattributes values will be resolved
  • Referenced elements will be moved to thedefselement
  • IRI and FuncIRI attributes that reference non-existing objects will be removed
  • If theoffsetattribute value of thestopelement is represented as percentage - it will be converted into a decimal number
svgcleaner in.svg out.svg

Change default options:

svgcleaner --indent=2 --paths-coordinates-precision=5 --join-arcto-flags=yes in.svg out.svg

Use--helpfor a list of the cleaning options and see the documentationfor more details.

You can get a GUIhere.

You can get prebuilt packageshere.

Dependency:Rust

cargo build --release

If you're a Rust programmer, you can installsvgcleanerusing:

cargo install svgcleaner

SeeCONTRIBUTING.mdfor details.

SeeFAQ.mdfor details.

svgcleaneris licensed under theGPL-2.0.

About

svgcleaner could help you to clean up your SVG files from the unnecessary data.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages