You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

215 lines
13 KiB

4 years ago
  1. **english** | [русский](https://github.com/svg/svgo/blob/master/README.ru.md)
  2. - - -
  3. <img src="https://svg.github.io/svgo-logo.svg" width="200" height="200" alt="logo"/>
  4. ## SVGO [![NPM version](https://badge.fury.io/js/svgo.svg)](https://npmjs.org/package/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)
  5. **SVG O**ptimizer is a Nodejs-based tool for optimizing SVG vector graphics files.
  6. ![](https://mc.yandex.ru/watch/18431326)
  7. ## Why?
  8. SVG files, especially those exported from various editors, usually contain a lot of redundant and useless information. This can include editor metadata, comments, hidden elements, default or non-optimal values and other stuff that can be safely removed or converted without affecting the SVG rendering result.
  9. ## What it can do
  10. SVGO has a plugin-based architecture, so almost every optimization is a separate plugin.
  11. Today we have:
  12. | Plugin | Description | Default |
  13. | ------ | ----------- | ------- |
  14. | [cleanupAttrs](https://github.com/svg/svgo/blob/master/plugins/cleanupAttrs.js) | cleanup attributes from newlines, trailing, and repeating spaces | `enabled` |
  15. | [inlineStyles](https://github.com/svg/svgo/blob/master/plugins/inlineStyles.js) | move and merge styles from `<style>` elements to element `style` attributes | `enabled` |
  16. | [removeDoctype](https://github.com/svg/svgo/blob/master/plugins/removeDoctype.js) | remove doctype declaration | `enabled` |
  17. | [removeXMLProcInst](https://github.com/svg/svgo/blob/master/plugins/removeXMLProcInst.js) | remove XML processing instructions | `enabled` |
  18. | [removeComments](https://github.com/svg/svgo/blob/master/plugins/removeComments.js) | remove comments | `enabled` |
  19. | [removeMetadata](https://github.com/svg/svgo/blob/master/plugins/removeMetadata.js) | remove `<metadata>` | `enabled` |
  20. | [removeTitle](https://github.com/svg/svgo/blob/master/plugins/removeTitle.js) | remove `<title>` | `enabled` |
  21. | [removeDesc](https://github.com/svg/svgo/blob/master/plugins/removeDesc.js) | remove `<desc>` | `enabled` |
  22. | [removeUselessDefs](https://github.com/svg/svgo/blob/master/plugins/removeUselessDefs.js) | remove elements of `<defs>` without `id` | `enabled` |
  23. | [removeXMLNS](https://github.com/svg/svgo/blob/master/plugins/removeXMLNS.js) | removes `xmlns` attribute (for inline svg) | `disabled` |
  24. | [removeEditorsNSData](https://github.com/svg/svgo/blob/master/plugins/removeEditorsNSData.js) | remove editors namespaces, elements, and attributes | `enabled` |
  25. | [removeEmptyAttrs](https://github.com/svg/svgo/blob/master/plugins/removeEmptyAttrs.js) | remove empty attributes | `enabled` |
  26. | [removeHiddenElems](https://github.com/svg/svgo/blob/master/plugins/removeHiddenElems.js) | remove hidden elements | `enabled` |
  27. | [removeEmptyText](https://github.com/svg/svgo/blob/master/plugins/removeEmptyText.js) | remove empty Text elements | `enabled` |
  28. | [removeEmptyContainers](https://github.com/svg/svgo/blob/master/plugins/removeEmptyContainers.js) | remove empty Container elements | `enabled` |
  29. | [removeViewBox](https://github.com/svg/svgo/blob/master/plugins/removeViewBox.js) | remove `viewBox` attribute when possible | `enabled` |
  30. | [cleanupEnableBackground](https://github.com/svg/svgo/blob/master/plugins/cleanupEnableBackground.js) | remove or cleanup `enable-background` attribute when possible | `enabled` |
  31. | [minifyStyles](https://github.com/svg/svgo/blob/master/plugins/minifyStyles.js) | minify `<style>` elements content with [CSSO](https://github.com/css/csso) | `enabled` |
  32. | [convertStyleToAttrs](https://github.com/svg/svgo/blob/master/plugins/convertStyleToAttrs.js) | convert styles into attributes | `enabled` |
  33. | [convertColors](https://github.com/svg/svgo/blob/master/plugins/convertColors.js) | convert colors (from `rgb()` to `#rrggbb`, from `#rrggbb` to `#rgb`) | `enabled` |
  34. | [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 | `enabled` |
  35. | [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 | `enabled` |
  36. | [removeUnknownsAndDefaults](https://github.com/svg/svgo/blob/master/plugins/removeUnknownsAndDefaults.js) | remove unknown elements content and attributes, remove attrs with default values | `enabled` |
  37. | [removeNonInheritableGroupAttrs](https://github.com/svg/svgo/blob/master/plugins/removeNonInheritableGroupAttrs.js) | remove non-inheritable group's "presentation" attributes | `enabled` |
  38. | [removeUselessStrokeAndFill](https://github.com/svg/svgo/blob/master/plugins/removeUselessStrokeAndFill.js) | remove useless `stroke` and `fill` attrs | `enabled` |
  39. | [removeUnusedNS](https://github.com/svg/svgo/blob/master/plugins/removeUnusedNS.js) | remove unused namespaces declaration | `enabled` |
  40. | [prefixIds](https://github.com/svg/svgo/blob/master/plugins/prefixIds.js) | prefix IDs and classes with the SVG filename or an arbitrary string | `disabled` |
  41. | [cleanupIDs](https://github.com/svg/svgo/blob/master/plugins/cleanupIDs.js) | remove unused and minify used IDs | `enabled` |
  42. | [cleanupNumericValues](https://github.com/svg/svgo/blob/master/plugins/cleanupNumericValues.js) | round numeric values to the fixed precision, remove default `px` units | `enabled` |
  43. | [cleanupListOfValues](https://github.com/svg/svgo/blob/master/plugins/cleanupListOfValues.js) | round numeric values in attributes that take a list of numbers (like `viewBox` or `enable-background`) | `disabled` |
  44. | [moveElemsAttrsToGroup](https://github.com/svg/svgo/blob/master/plugins/moveElemsAttrsToGroup.js) | move elements' attributes to their enclosing group | `enabled` |
  45. | [moveGroupAttrsToElems](https://github.com/svg/svgo/blob/master/plugins/moveGroupAttrsToElems.js) | move some group attributes to the contained elements | `enabled` |
  46. | [collapseGroups](https://github.com/svg/svgo/blob/master/plugins/collapseGroups.js) | collapse useless groups | `enabled` |
  47. | [removeRasterImages](https://github.com/svg/svgo/blob/master/plugins/removeRasterImages.js) | remove raster images | `disabled` |
  48. | [mergePaths](https://github.com/svg/svgo/blob/master/plugins/mergePaths.js) | merge multiple Paths into one | `enabled` |
  49. | [convertShapeToPath](https://github.com/svg/svgo/blob/master/plugins/convertShapeToPath.js) | convert some basic shapes to `<path>` | `enabled` |
  50. | [convertEllipseToCircle](https://github.com/svg/svgo/blob/master/plugins/convertEllipseToCircle.js) | convert non-eccentric `<ellipse>` to `<circle>` | `enabled` |
  51. | [sortAttrs](https://github.com/svg/svgo/blob/master/plugins/sortAttrs.js) | sort element attributes for epic readability | `disabled` |
  52. | [sortDefsChildren](https://github.com/svg/svgo/blob/master/plugins/sortDefsChildren.js) | sort children of `<defs>` in order to improve compression | `enabled` |
  53. | [removeDimensions](https://github.com/svg/svgo/blob/master/plugins/removeDimensions.js) | remove `width`/`height` and add `viewBox` if it's missing (opposite to removeViewBox, disable it first) | `disabled` |
  54. | [removeAttrs](https://github.com/svg/svgo/blob/master/plugins/removeAttrs.js) | remove attributes by pattern | `disabled` |
  55. | [removeAttributesBySelector](https://github.com/svg/svgo/blob/master/plugins/removeAttributesBySelector.js) | removes attributes of elements that match a css selector | `disabled` |
  56. | [removeElementsByAttr](https://github.com/svg/svgo/blob/master/plugins/removeElementsByAttr.js) | remove arbitrary elements by ID or className | `disabled` |
  57. | [addClassesToSVGElement](https://github.com/svg/svgo/blob/master/plugins/addClassesToSVGElement.js) | add classnames to an outer `<svg>` element | `disabled` |
  58. | [addAttributesToSVGElement](https://github.com/svg/svgo/blob/master/plugins/addAttributesToSVGElement.js) | adds attributes to an outer `<svg>` element | `disabled` |
  59. | [removeOffCanvasPaths](https://github.com/svg/svgo/blob/master/plugins/removeOffCanvasPaths.js) | removes elements that are drawn outside of the viewbox | `disabled` |
  60. | [removeStyleElement](https://github.com/svg/svgo/blob/master/plugins/removeStyleElement.js) | remove `<style>` elements | `disabled` |
  61. | [removeScriptElement](https://github.com/svg/svgo/blob/master/plugins/removeScriptElement.js) | remove `<script>` elements | `disabled` |
  62. | [reusePaths](https://github.com/svg/svgo/blob/master/plugins/reusePaths.js) | Find duplicated <path> elements and replace them with <use> links | `disabled` |
  63. Want 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). ([동작방법](https://github.com/svg/svgo/blob/master/docs/how-it-works/ko.md))
  64. ## Installation
  65. ```sh
  66. $ [sudo] npm install -g svgo
  67. ```
  68. ## Usage
  69. ### <abbr title="Command Line Interface">CLI</abbr>
  70. ```
  71. Usage:
  72. svgo [OPTIONS] [ARGS]
  73. Options:
  74. -h, --help : Help
  75. -v, --version : Version
  76. -i INPUT, --input=INPUT : Input file, "-" for STDIN
  77. -s STRING, --string=STRING : Input SVG data string
  78. -f FOLDER, --folder=FOLDER : Input folder, optimize and rewrite all *.svg files
  79. -o OUTPUT, --output=OUTPUT : Output file or folder (by default the same as the input), "-" for STDOUT
  80. -p PRECISION, --precision=PRECISION : Set number of digits in the fractional part, overrides plugins params
  81. --config=CONFIG : Config file or JSON string to extend or replace default
  82. --disable=PLUGIN : Disable plugin by name, "--disable=PLUGIN1,PLUGIN2" for multiple plugins
  83. --enable=PLUGIN : Enable plugin by name, "--enable=PLUGIN3,PLUGIN4" for multiple plugins
  84. --datauri=DATAURI : Output as Data URI string (base64, URI encoded or unencoded)
  85. --multipass : Pass over SVGs multiple times to ensure all optimizations are applied
  86. --pretty : Make SVG pretty printed
  87. --indent=INDENT : Indent number when pretty printing SVGs
  88. -r, --recursive : Use with '-f'. Optimizes *.svg files in folders recursively.
  89. -q, --quiet : Only output error messages, not regular status messages
  90. --show-plugins : Show available plugins and exit
  91. Arguments:
  92. INPUT : Alias to --input
  93. ```
  94. * with files:
  95. ```sh
  96. $ svgo test.svg
  97. ```
  98. or:
  99. ```sh
  100. $ svgo *.svg
  101. ```
  102. ```sh
  103. $ svgo test.svg -o test.min.svg
  104. ```
  105. ```sh
  106. $ svgo test.svg other.svg third.svg
  107. ```
  108. ```sh
  109. $ svgo test.svg other.svg third.svg -o test.min.svg -o other.min.svg -o third.min.svg
  110. ```
  111. * with STDIN / STDOUT:
  112. ```sh
  113. $ cat test.svg | svgo -i - -o - > test.min.svg
  114. ```
  115. * with folder
  116. ```sh
  117. $ svgo -f ../path/to/folder/with/svg/files
  118. ```
  119. or:
  120. ```sh
  121. $ svgo -f ../path/to/folder/with/svg/files -o ../path/to/folder/with/svg/output
  122. ```
  123. ```sh
  124. $ svgo *.svg -o ../path/to/folder/with/svg/output
  125. ```
  126. * with strings:
  127. ```sh
  128. $ svgo -s '<svg version="1.1">test</svg>' -o test.min.svg
  129. ```
  130. or even with Data URI base64:
  131. ```sh
  132. $ svgo -s 'data:image/svg+xml;base64,...' -o test.min.svg
  133. ```
  134. * with SVGZ:
  135. from `.svgz` to `.svg`:
  136. ```sh
  137. $ gunzip -c test.svgz | svgo -i - -o test.min.svg
  138. ```
  139. from `.svg` to `.svgz`:
  140. ```sh
  141. $ svgo test.svg -o - | gzip -cfq9 > test.svgz
  142. ```
  143. ### Other Ways to Use SVGO
  144. * as a web app – [SVGOMG](https://jakearchibald.github.io/svgomg/)
  145. * as a Nodejs module – [examples](https://github.com/svg/svgo/tree/master/examples)
  146. * as a Grunt task – [grunt-svgmin](https://github.com/sindresorhus/grunt-svgmin)
  147. * as a Gulp task – [gulp-svgmin](https://github.com/ben-eb/gulp-svgmin)
  148. * as a Mimosa module – [mimosa-minify-svg](https://github.com/dbashford/mimosa-minify-svg)
  149. * as an OSX Folder Action – [svgo-osx-folder-action](https://github.com/svg/svgo-osx-folder-action)
  150. * as a webpack loader – [image-webpack-loader](https://github.com/tcoopman/image-webpack-loader)
  151. * as a Telegram Bot – [svgo_bot](https://github.com/maksugr/svgo_bot)
  152. * as a PostCSS plugin – [postcss-svgo](https://github.com/ben-eb/postcss-svgo)
  153. * as an Inkscape plugin – [inkscape-svgo](https://github.com/konsumer/inkscape-svgo)
  154. * as a Sketch plugin - [svgo-compressor](https://github.com/BohemianCoding/svgo-compressor)
  155. * as macOS app - [Image Shrinker](https://image-shrinker.com)
  156. * as a Rollup plugin - [rollup-plugin-svgo](https://github.com/porsager/rollup-plugin-svgo)
  157. ## Backers
  158. | [<img src="https://sheetjs.com/sketch128.png" width="80">](https://sheetjs.com/) | [<img src="https://rawgithub.com/fontello/fontello/master/fontello-image.svg" width="80">](http://fontello.com/) |
  159. |:-:|:-:|
  160. | [SheetJS LLC](https://sheetjs.com/) | [Fontello](http://fontello.com/) |
  161. ## Donations
  162. - PayPal: https://www.paypal.me/deepsweet
  163. ## License and Copyright
  164. This software is released under the terms of the [MIT license](https://github.com/svg/svgo/blob/master/LICENSE).
  165. Logo by [Yegor Bolshakov](http://xizzzy.ru/).