These scripts use SVGO which is the tech behind the famous SVGOMG SVG optimization website.
Why run these scripts instead of the SVGO CLI?
- You dont have to point at a config file.
- Inline styles are removed via regex.
Why would you need a config file?
The default preset removes the viewBox, which is required to easily scale the image via CSS.
Why would you need inline styles removed?
SVGs prepped for the web are outlines and fills, we generally dont need any inline styles. Most vector drawing apps add styles and SVGO cannot remove them for us.
Requirements:
- Windows (you can make it work elsewhere)
- Python
- NPM
Installation:
- Install SVGO globally:
npm i -g svgo
- Place the py and bat files in a folder that is part of your PATH dirs so you can call the bats everywhere.
- Set
config_path
to the path you chose.
Usage:
# optimize one SVG
svgomg hello.svg
# optimize all SVGs
svgomgall