UNPKG

8.51 kBMarkdownView Raw
1**english** | [русский](https://github.com/svg/svgo/blob/master/README.ru.md)
2- - -
3
4<img src="https://svg.github.io/svgo-logo.svg" width="200" height="200" alt="logo"/>
5
6## SVGO [![NPM version](https://badge.fury.io/js/svgo.svg)](https://npmjs.org/package/svgo) [![Dependency Status](https://gemnasium.com/svg/svgo.png)](https://gemnasium.com/svg/svgo) [![Build Status](https://secure.travis-ci.org/svg/svgo.svg)](https://travis-ci.org/svg/svgo) [![Coverage Status](https://img.shields.io/coveralls/svg/svgo.svg)](https://coveralls.io/r/svg/svgo?branch=master)
7
8**SVG O**ptimizer is a Nodejs-based tool for optimizing SVG vector graphics files.
9![](https://mc.yandex.ru/watch/18431326)
10
11## Why?
12
13SVG files, especially exported from various editors, usually contains 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.
14
15## What it can do
16
17SVGO has a plugin-based architecture, so almost every optimization is a separate plugin.
18
19Today we have:
20
21* [ [ cleanupAttrs](https://github.com/svg/svgo/blob/master/plugins/cleanupAttrs.js) ] cleanup attributes from newlines, trailing and repeating spaces
22* [ [ removeDoctype](https://github.com/svg/svgo/blob/master/plugins/removeDoctype.js) ] remove doctype declaration
23* [ [ removeXMLProcInst](https://github.com/svg/svgo/blob/master/plugins/removeXMLProcInst.js) ] remove XML processing instructions
24* [ [ removeComments](https://github.com/svg/svgo/blob/master/plugins/removeComments.js) ] remove comments
25* [ [ removeMetaData](https://github.com/svg/svgo/blob/master/plugins/removeMetadata.js) ] remove `<metadata>`
26* [ [ removeTitle](https://github.com/svg/svgo/blob/master/plugins/removeTitle.js) ] remove `<title>` (disabled by default)
27* [ [ removeDesc](https://github.com/svg/svgo/blob/master/plugins/removeDesc.js) ] remove `<desc>` (only non-meaningful by default)
28* [ [ removeUselessDefs](https://github.com/svg/svgo/blob/master/plugins/removeUselessDefs.js) ] remove elements of `<defs>` without `id`
29* [ [ removeEditorsNSData](https://github.com/svg/svgo/blob/master/plugins/removeEditorsNSData.js) ] remove editors namespaces, elements and attributes
30* [ [ removeEmptyAttrs](https://github.com/svg/svgo/blob/master/plugins/removeEmptyAttrs.js) ] remove empty attributes
31* [ [ removeHiddenElems](https://github.com/svg/svgo/blob/master/plugins/removeHiddenElems.js) ] remove hidden elements
32* [ [ removeEmptyText](https://github.com/svg/svgo/blob/master/plugins/removeEmptyText.js) ] remove empty Text elements
33* [ [ removeEmptyContainers](https://github.com/svg/svgo/blob/master/plugins/removeEmptyContainers.js) ] remove empty Container elements
34* [ [ removeViewBox](https://github.com/svg/svgo/blob/master/plugins/removeViewBox.js) ] remove `viewBox` attribute when possible (disabled by default)
35* [ [ cleanUpEnableBackground](https://github.com/svg/svgo/blob/master/plugins/cleanupEnableBackground.js) ] remove or cleanup `enable-background` attribute when possible
36* [ [ convertTyleToAttrs](https://github.com/svg/svgo/blob/master/plugins/convertStyleToAttrs.js) ] convert styles into attributes
37* [ [ convertColors](https://github.com/svg/svgo/blob/master/plugins/convertColors.js) ] convert colors (from `rgb()` to `#rrggbb`, from `#rrggbb` to `#rgb`)
38* [ [ convertPathData](https://github.com/svg/svgo/blob/master/plugins/convertPathData.js) ] convert Path data to relative or absolute whichever is shorter, convert one segment to another, trim useless delimiters, smart rounding and much more
39* [ [ convertTransform](https://github.com/svg/svgo/blob/master/plugins/convertTransform.js) ] collapse multiple transforms into one, convert matrices to the short aliases and much more
40* [ [ removeUnknownsAndDefaults](https://github.com/svg/svgo/blob/master/plugins/removeUnknownsAndDefaults.js) ] remove unknown elements content and attributes, remove attrs with default values
41* [ [ removeNonInheritableGroupAttrs](https://github.com/svg/svgo/blob/master/plugins/removeNonInheritableGroupAttrs.js) ] remove non-inheritable group's "presentation" attributes
42* [ [ removeUselessStrokeAndFill](https://github.com/svg/svgo/blob/master/plugins/removeUselessStrokeAndFill.js) ] remove useless stroke and fill attrs
43* [ [ removeUnusedNS](https://github.com/svg/svgo/blob/master/plugins/removeUnusedNS.js) ] remove unused namespaces declaration
44* [ [ cleanupIDs](https://github.com/svg/svgo/blob/master/plugins/cleanupIDs.js) ] remove unused and minify used IDs
45* [ [ cleanupNumericValues](https://github.com/svg/svgo/blob/master/plugins/cleanupNumericValues.js) ] round numeric values to the fixed precision, remove default 'px' units
46* [ [ moveElemsAttrsToGroup](https://github.com/svg/svgo/blob/master/plugins/moveElemsAttrsToGroup.js) ] move elements attributes to the existing group wrapper
47* [ [ moveGroupAttrsToElems](https://github.com/svg/svgo/blob/master/plugins/moveGroupAttrsToElems.js) ] move some group attributes to the content elements
48* [ [ collapseGroups](https://github.com/svg/svgo/blob/master/plugins/collapseGroups.js) ] collapse useless groups
49* [ [ removeRasterImages](https://github.com/svg/svgo/blob/master/plugins/removeRasterImages.js) ] remove raster images (disabled by default)
50* [ [ mergePaths](https://github.com/svg/svgo/blob/master/plugins/mergePaths.js) ] merge multiple Paths into one
51* [ [ convertShapeToPath](https://github.com/svg/svgo/blob/master/plugins/convertShapeToPath.js) ] convert some basic shapes to path
52* [ [ sortAttrs](https://github.com/svg/svgo/blob/master/plugins/sortAttrs.js) ] sort element attributes for epic readability (disabled by default)
53* [ [ transformsWithOnePath](https://github.com/svg/svgo/blob/master/plugins/transformsWithOnePath.js) ] apply transforms, crop by real width, center vertical alignment and resize SVG with one Path inside (disabled by default)
54
55Want to know how it works and how to write your own plugin? [Of course you want to](https://github.com/svg/svgo/blob/master/docs/how-it-works/en.md).
56
57
58## How to use
59
60```sh
61$ [sudo] npm install -g svgo
62```
63
64```
65Usage:
66 svgo [OPTIONS] [ARGS]
67
68Options:
69 -h, --help : Help
70 -v, --version : Version
71 -i INPUT, --input=INPUT : Input file, "-" for STDIN
72 -s STRING, --string=STRING : Input SVG data string
73 -f FOLDER, --folder=FOLDER : Input folder, optimize and rewrite all *.svg files
74 -o OUTPUT, --output=OUTPUT : Output file or folder (by default the same as the input), "-" for STDOUT
75 -p PRECISION, --precision=PRECISION : Set number of digits in the fractional part, overrides plugins params
76 --config=CONFIG : Config file to extend or replace default
77 --disable=DISABLE : Disable plugin by name
78 --enable=ENABLE : Enable plugin by name
79 --datauri=DATAURI : Output as Data URI string (base64, URI encoded or unencoded)
80 --pretty : Make SVG pretty printed
81
82Arguments:
83 INPUT : Alias to --input
84 OUTPUT : Alias to --output
85```
86
87* with files:
88
89 $ svgo test.svg
90
91 or:
92
93 $ svgo test.svg test.min.svg
94
95* with STDIN / STDOUT:
96
97 $ cat test.svg | svgo -i - -o - > test.min.svg
98
99* with folder
100
101 $ svgo -f ../path/to/folder/with/svg/files
102
103 or:
104
105 $ svgo -f ../path/to/folder/with/svg/files -o ../path/to/folder/with/svg/output
106
107* with strings:
108
109 $ svgo -s '<svg version="1.1">test</svg>' -o test.min.svg
110
111 or even with Data URI base64:
112
113 $ svgo -s 'data:image/svg+xml;base64,…' -o test.min.svg
114
115* with SVGZ:
116
117 from `.svgz` to `.svg`:
118
119 $ gunzip -c test.svgz | svgo -i - -o test.min.svg
120
121 from `.svg` to `.svgz`:
122
123 $ svgo test.svg -o - | gzip -cfq9 > test.svgz
124
125* with GUI – [svgo-gui](https://github.com/svg/svgo-gui)
126* as a web app - [SVGOMG](https://jakearchibald.github.io/svgomg/)
127* as a Nodejs module – [examples](https://github.com/svg/svgo/tree/master/examples)
128* as a Grunt task – [grunt-svgmin](https://github.com/sindresorhus/grunt-svgmin)
129* as a Gulp task – [gulp-svgmin](https://github.com/ben-eb/gulp-svgmin)
130* as a Mimosa module – [mimosa-minify-svg](https://github.com/dbashford/mimosa-minify-svg)
131* as an OSX Folder Action – [svgo-osx-folder-action](https://github.com/svg/svgo-osx-folder-action)
132
133## Donate
134
135BTC `1zVZYqRSzQ4aaL27rp3PLwFFSXpfs5H8r`
136
137## License and copyrights
138
139This software is released under the terms of the [MIT license](https://github.com/svg/svgo/blob/master/LICENSE).
140
141Logo by [Yegor Bolshakov](http://xizzzy.ru/).