svgop
(SVG Optimizer Pipeable) is a standalone binary executable that combines the excellent svgo
Nodejs-based tool for optimizing SVG vector graphics files.
QuickJS works! The macOS binary is now 97% smaller! (svgop-qjs-macos
has 2 MB, svgop-pkg-macos
has 83 MB).
It’s also possible to compile for Windows and Linux, should be equally small, but I don’t offer precompiled versions for these platforms yet.
Older versions also bundled pdf.js
but this was not working well.
SVG files, especially exported from various editors, usually contain a lot of redundant and useless information such as editor metadata, comments, hidden elements, default or non-optimal values and other stuff that can be safely removed or converted without affecting SVG rendering result.
While svgo
requires a Nodejs environment to run, svgop
is a standalone binary executable tool for macOS (64-bit) and Windows (x64, potentially also x86). svgop
accepts SVG in stdin and outputs an optimized SVG to stdout.
It uses the default svgo
config.
This repo contains a process to create svgop
from svgo
in two ways:
- (new) using the QuickJS compiler by Fabrice Bellard and Charlie Gordon; I can build for macOS only, the executable is 2 MB. QuickJS is a JS interpreter and compiler optimized for size.
- (old) using the
pkg
compiler; prebuilt binaries are provided for macOS, Windows x64 and Linux, but they’re large (the macOS one is 83 MB). pkg includes the entire Node.js runtime in the executable.
DOWNLOAD the latest release
- for macOS (
svgop-qjs-macos.zip
), made withqjsc
, small - for Windows 64-bit (
svgop-pkg-win64.zip
), made withpkg
, large
svgop
uses stdin for input, stdout for output, and has no commandline options. It runs a predefined set of svgo
plugins.
Use piping (redirection) to read from files (<
) and to write to files (>
).
In macOS or Linux:
svgop < test.svg > test.min.svg
In Windows command prompt:
svgop.exe < test.svg > test.min.svg
In Windows PowerShell, the equivalent should be:
Get-Content test.svg | ./svgop.exe > test.min.svg
In macOS or Linux:
gunzip -c test.svgz | svgop > test.min.svg
In macOS or Linux:
svgop < test.svg | gzip -cfq9 > test.min.svgz
- Clone the repo on macOS.
- Double-click or run
install-mac.command
to install the necessary dev tools. - Run
cd src && make all
- The executables will be found in
./bin
I’m not building on Windows or Linux. You can build, but you’ll need to adapt my Makefile, which is macOS-centric.
build/svgop-qjs contains the intermediate results of my hackery: webpacked svgo that you can run with qjs and the generated .c that you can compile against the QuickJS headers to get the binary.
To make pkg
work, a customized version of config.js
will replace svgo
’s own config.js
. The customized version will need to be updated manually from time to time.
- svgo https://github.com/svg/svgo
- libsvgo https://github.com/dr-js/libsvgo
- usvg https://github.com/RazrFalcon/resvg/blob/master/README.md
- nanosvg https://github.com/rsheeter/nanosvg
- https://maker.js.org/docs/advanced-drawing/#Simplifying%20paths
- https://github.com/scour-project/scour
- https://pypi.org/project/SVGCompress/
- https://github.com/manisandro/svg2svgt
- pdftocairo https://poppler.freedesktop.org/
Portions of this software are licensed under the terms of the Apache 2 license. Portions of this software are licensed under the terms of the MIT license. Please consult LICENSE.
svgop
: Copyright © 2017 Adam Twardochsvgo
: Copyright © 2012–2017 Kir Belevich and Contributors