svgcleaner helps you clean up your SVG files, keeping them free from unnecessary data.
The main purpose of svgcleaner is 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.
In addition to the obvious advantages of svgcleaner — like correctness, cleaning ratio and performance, which are described below — there are some more nuances to be aware of:
* You can get all of these features using the GUI.
See 'Testing notes' for details.
All stats were collected using the latest release version.
Less is better.
* Most of the errors were due to incorrect font-face
processing. Without including font-based errors, scores were:
- svgo
: 100
- scour
: 78
* Errors produced by numeric rounding were ignored.
More is better.
* Note that svgo
and scour
break most of the files.
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 |
You can find more tests, with detailed explanations of errors, here.
svgcleaner shouldn'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:
style
element will be extracted and processes. The style
element will be removed.style
attribute will be split into attributesclass
attribute will be processed and removedcurrentColor
and inherit
attributes values will be resolveddefs
elementoffset
attribute value of the stop
element 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 --help
for a list of the cleaning options and see the doc for more details.
You can get a GUI here.
You can get prebuilt packages here.
Dependency: Rust >= 1.13
bash
cargo build --release
If you're a Rust programmer, you can install svgcleaner using:
bash
cargo install svgcleaner
See CONTRIBUTING.md for details.
svgcleaner is licensed under the GPL-2.0.