How can I simplify SVG files (all the paths inside it) using a Windows command line tool? It's important that it be fast because I should use it in production.
Adobe Illustrator has a good simplifier (Object->Path->Simplify) but can't be used as CLI. https://github.com/mourner/simplify-js is another good tool but it doesn't have a CLI.
Please comment below this question if you know any non CLI tool (in any languages including C++ and Python) that works directly with SVG files.
-
1Your last sentence should be a separate question (Please don't ask two questions in one on SE sites). You can have both questions point to each other to emphasize that you want a CLI tool in one and a library in the other.– user416Oct 29, 2018 at 8:42
-
If you can code, it would be simple to write a script with AutoIt to automate Adobe Illustrator to do this for as many files as you like– Mawg says reinstate MonicaNov 29, 2018 at 13:54
4 Answers
Scour is a python tool which removes redundant and spurious data from SVG files and then optimizes them.
Install
If you are on debian you can install it by typing this command:
sudo apt install scour
On most platforms you can install with:
pip install scour
If your current permissions are not sufficient you can either use:
pip install --user scour
or
sudo pip install scour
Usage
Standard:
scour -i input.svg -o output.svg
Better (for older versions of Internet Explorer):
scour -i input.svg -o output.svg --enable-viewboxing
Maximum scrubbing:
scour -i input.svg -o output.svg --enable-viewboxing --enable-id-stripping \
--enable-comment-stripping --shorten-ids --indent=none
Maximum scrubbing and a compressed SVGZ file:
scour -i input.svg -o output.svgz --enable-viewboxing --enable-id-stripping \
--enable-comment-stripping --shorten-ids --indent=none
Note that Scour is a python library that also provides a command line tool by utilizing entry points so will require a working python (2.7 or 3.4+ installation) - it is cross platform.
-
I couldn't find any tools for simplifying SVG paths in Scour. Are you sure it does that?– J. MandoOct 29, 2018 at 19:46
-
1@J.Mando yes I am reasonably sure that it does optimize not quite the same as simplify svg files - depending on the origin of the file and the options selected the saving can be quite significant. Oct 30, 2018 at 6:13
-
-
@J.Mando Please clarify what you mean by simplify most optimizations are also simplifications as a simpler SVG will download, load and render more quickly than a complex one and fast download, load & render is the goal of optimization - the only definition of simplification that I know of that is not also optimization is attempting to make things more human readable which may run counter to optimization. Oct 31, 2018 at 6:01
-
1I think the question is clear. I want path simplification. Just like the one in Adobe Illustrator - which I mentioned.– J. MandoOct 31, 2018 at 15:46
You could install node.js and use command line JavaScript along with SVG Optimizer (SVGO) for optimizing SVG vector graphics files.
-
1I couldn't find any tools for simplifying SVG paths in SVGO. Are you sure it does that?– J. MandoOct 29, 2018 at 14:06
There is also svgcleaner.
As of the time that I am posting this, the latest release was in April of 2018, and the latest (unreleased) commit in November of 2019, so it can still be considered in active development.
I do not know how it compares feature-wise to the other utilities listed, but the main benefit I see in this utility is that it is written in a real programming language (Rust) instead of some scripting rimgarole like javascript or python.
One feature that I already know it does not have is the ability select a subset of the original svg file to export.
svgcleaner comes with builds for linux, windows, and macos.
If you already have inkscape installed, you can use it as a command-line utility.
Type inkscape --help
for instructions.
inkscape contains the python runtime and makes use of scour (mentioned in another answer) to perform these command-line operations.