LinuxCommandLibrary

svgo

Optimize SVG vector graphics files

TLDR

Optimize a file using the default plugins (overwrites the original file)

$ svgo [test.svg]
copy

Optimize a file and save the result to another file
$ svgo [test.svg] [[-o|--output]] [test.min.svg]
copy

Optimize all SVG files within a directory (overwrites the original files)
$ svgo [[-f|--folder]] [path/to/directory/with/svg/files]
copy

Optimize all SVG files within a directory and save the resulting files to another directory
$ svgo [[-f|--folder]] [path/to/input/directory] [[-o|--output]] [path/to/output/directory]
copy

Optimize SVG content passed from another command, and save the result to a file
$ [cat test.svg] | svgo [[-i|--input]] - [[-o|--output]] [test.min.svg]
copy

Optimize a file and print out the result
$ svgo [test.svg] [[-o|--output]] -
copy

Show available plugins
$ svgo --show-plugins
copy

SYNOPSIS

svgo [options] [input.svg ...]

PARAMETERS

-f, --folder
    Process all SVG files in a given folder.

-i, --input
    Specify the input SVG file to process.

-o, --output
    Specify the output file for the optimized SVG. If not specified, the input file will be overwritten.

--config
    Path to a configuration file. Overrides default settings.

-p, --pretty
    Pretty print the output SVG.

-v, --verbose
    Enable verbose output, showing more details about the optimization process.

--version
    Display the version number.

-h, --help
    Display help information.

--disable
    Disable a specific plugin. Useful for troubleshooting.

--enable
    Enable a specific plugin. Useful for testing.

DESCRIPTION

svgo is a command-line tool and Node.js library for optimizing SVG (Scalable Vector Graphics) files. It reduces file size by removing unnecessary metadata, comments, hidden elements, and other non-essential information without affecting the visual appearance of the SVG. This optimization can significantly improve website loading times and reduce bandwidth consumption.

svgo offers various configuration options to control the level and type of optimization applied. It can remove editor-specific metadata, minify attributes, and even convert basic shapes to more efficient path representations.

It's a powerful tool for web developers, designers, and anyone working with SVG files who wants to ensure that their graphics are as small and efficient as possible.

CAVEATS

Overwriting input files can lead to data loss if the optimization process introduces unintended changes. Always back up your SVG files before using svgo.

CONFIGURATION

svgo can be configured with a configuration file (usually `svgo.config.js` or `.svgo.yml`) to fine-tune the optimization process. This allows you to specify which plugins to use, their order, and their individual settings. Configuration files allow for more granular control than command line arguments.

PLUGINS

svgo uses a plugin-based architecture. Each plugin performs a specific optimization task, such as removing attributes or converting shapes. The order in which plugins are applied can affect the final result.

HISTORY

svgo was created to provide a robust and configurable SVG optimization solution. It has evolved through contributions from a large open-source community and is actively maintained. Initially developed as a Node.js library, it has expanded to include a command-line interface, making it accessible to a broader range of users. The tool is used to reduce the file size of SVG on websites and applications, thus improving performance and bandwidth utilization.

Copied to clipboard