#svg #cleaner #optimization #cleanup

bin+lib svgcleaner

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

10 releases

Uses old Rust 2015

0.9.5 Jul 30, 2018
0.9.4 Mar 22, 2018
0.9.3 Jan 17, 2018
0.9.2 Dec 16, 2017
0.7.1 Nov 4, 2016

#16 in #optimizer

Download history 136/week @ 2024-08-25 80/week @ 2024-09-01 72/week @ 2024-09-08 67/week @ 2024-09-15 96/week @ 2024-09-22 88/week @ 2024-09-29 84/week @ 2024-10-06 59/week @ 2024-10-13 68/week @ 2024-10-20 65/week @ 2024-10-27 64/week @ 2024-11-03 103/week @ 2024-11-10 122/week @ 2024-11-17 79/week @ 2024-11-24 188/week @ 2024-12-01 189/week @ 2024-12-08

581 downloads per month

GPL-2.0 license

340KB
9K SLoC

svgcleaner build status

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


Table of Contents

Purpose

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.

Goals

  1. Correctness - svgcleaner should 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

Alternatives

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

  1. svgcleaner cleans 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. svgcleaner is strictly lossless by default. There are no destructive cleaning options enabled by default.
  3. svgcleaner is portable. You can build it into a single executable without any external dependencies.

* You can get all of these features using the GUI.

Charts

See Testing notes for details.

All stats were collected using the latest release version.

Correctness

Less is better.

docs/images/correctness_chart_W3C_SVG_11_TestSuite.svg docs/images/correctness_chart_oxygen.svg

Cleaning ratio

More is better.

docs/images/ratio_chart_W3C_SVG_11_TestSuite.svg

* scour creates bigger files (-18.78%).

docs/images/ratio_chart_oxygen.svg

Cleaning time

Less is better.

docs/images/performance_chart_W3C_SVG_11_TestSuite.svg docs/images/performance_chart_oxygen.svg

Other

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

Documentation can be found here.

Limitations

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:

  • 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 the style element will be extracted and processes. The style element will be removed.
  • The style attribute will be split into attributes
  • The class attribute will be processed and removed
  • Paths and transformations will be reformatted
  • currentColor and inherit attributes values will be resolved
  • Referenced elements will be moved to the defs element
  • IRI and FuncIRI attributes that reference non-existing objects will be removed
  • If the offset attribute value of the stop element is represented as percentage - it will be converted into a decimal number

Usage

CLI

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 documentation for more details.

GUI

You can get a GUI here.

Downloads

You can get prebuilt packages here.

Building

Dependency: Rust >= 1.20

cargo build --release

If you're a Rust programmer, you can install svgcleaner using:

cargo install svgcleaner

Contributing and Issues

See CONTRIBUTING.md for details.

FAQ

See FAQ.md for details.

License

svgcleaner is licensed under the GPL-2.0.

Dependencies

~2.5MB
~41K SLoC