项目原始demo,不改动
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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) [![Dependency Status](https://gemnasium.com/svg/svgo.svg)](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)
  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 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.
  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 |
  13. | ------ | ----------- |
  14. | [cleanupAttrs](https://github.com/svg/svgo/blob/master/plugins/cleanupAttrs.js) | cleanup attributes from newlines, trailing, and repeating spaces |
  15. | [removeDoctype](https://github.com/svg/svgo/blob/master/plugins/removeDoctype.js) | remove doctype declaration |
  16. | [removeXMLProcInst](https://github.com/svg/svgo/blob/master/plugins/removeXMLProcInst.js) | remove XML processing instructions |
  17. | [removeComments](https://github.com/svg/svgo/blob/master/plugins/removeComments.js) | remove comments |
  18. | [removeMetadata](https://github.com/svg/svgo/blob/master/plugins/removeMetadata.js) | remove `<metadata>` |
  19. | [removeTitle](https://github.com/svg/svgo/blob/master/plugins/removeTitle.js) | remove `<title>` (disabled by default) |
  20. | [removeDesc](https://github.com/svg/svgo/blob/master/plugins/removeDesc.js) | remove `<desc>` (only non-meaningful by default) |
  21. | [removeUselessDefs](https://github.com/svg/svgo/blob/master/plugins/removeUselessDefs.js) | remove elements of `<defs>` without `id` |
  22. | [removeXMLNS](https://github.com/svg/svgo/blob/master/plugins/removeXMLNS.js) | removes `xmlns` attribute (for inline svg, disabled by default) |
  23. | [removeEditorsNSData](https://github.com/svg/svgo/blob/master/plugins/removeEditorsNSData.js) | remove editors namespaces, elements, and attributes |
  24. | [removeEmptyAttrs](https://github.com/svg/svgo/blob/master/plugins/removeEmptyAttrs.js) | remove empty attributes |
  25. | [removeHiddenElems](https://github.com/svg/svgo/blob/master/plugins/removeHiddenElems.js) | remove hidden elements |
  26. | [removeEmptyText](https://github.com/svg/svgo/blob/master/plugins/removeEmptyText.js) | remove empty Text elements |
  27. | [removeEmptyContainers](https://github.com/svg/svgo/blob/master/plugins/removeEmptyContainers.js) | remove empty Container elements |
  28. | [removeViewBox](https://github.com/svg/svgo/blob/master/plugins/removeViewBox.js) | remove `viewBox` attribute when possible (disabled by default) |
  29. | [cleanupEnableBackground](https://github.com/svg/svgo/blob/master/plugins/cleanupEnableBackground.js) | remove or cleanup `enable-background` attribute when possible |
  30. | [minifyStyles](https://github.com/svg/svgo/blob/master/plugins/minifyStyles.js) | minify `<style>` elements content with [CSSO](https://github.com/css/csso) |
  31. | [convertStyleToAttrs](https://github.com/svg/svgo/blob/master/plugins/convertStyleToAttrs.js) | convert styles into attributes |
  32. | [convertColors](https://github.com/svg/svgo/blob/master/plugins/convertColors.js) | convert colors (from `rgb()` to `#rrggbb`, from `#rrggbb` to `#rgb`) |
  33. | [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 |
  34. | [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 |
  35. | [removeUnknownsAndDefaults](https://github.com/svg/svgo/blob/master/plugins/removeUnknownsAndDefaults.js) | remove unknown elements content and attributes, remove attrs with default values |
  36. | [removeNonInheritableGroupAttrs](https://github.com/svg/svgo/blob/master/plugins/removeNonInheritableGroupAttrs.js) | remove non-inheritable group's "presentation" attributes |
  37. | [removeUselessStrokeAndFill](https://github.com/svg/svgo/blob/master/plugins/removeUselessStrokeAndFill.js) | remove useless `stroke` and `fill` attrs |
  38. | [removeUnusedNS](https://github.com/svg/svgo/blob/master/plugins/removeUnusedNS.js) | remove unused namespaces declaration |
  39. | [cleanupIDs](https://github.com/svg/svgo/blob/master/plugins/cleanupIDs.js) | remove unused and minify used IDs |
  40. | [cleanupNumericValues](https://github.com/svg/svgo/blob/master/plugins/cleanupNumericValues.js) | round numeric values to the fixed precision, remove default `px` units |
  41. | [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 `enableBackground`) |
  42. | [moveElemsAttrsToGroup](https://github.com/svg/svgo/blob/master/plugins/moveElemsAttrsToGroup.js) | move elements' attributes to their enclosing group |
  43. | [moveGroupAttrsToElems](https://github.com/svg/svgo/blob/master/plugins/moveGroupAttrsToElems.js) | move some group attributes to the contained elements |
  44. | [collapseGroups](https://github.com/svg/svgo/blob/master/plugins/collapseGroups.js) | collapse useless groups |
  45. | [removeRasterImages](https://github.com/svg/svgo/blob/master/plugins/removeRasterImages.js) | remove raster images (disabled by default) |
  46. | [mergePaths](https://github.com/svg/svgo/blob/master/plugins/mergePaths.js) | merge multiple Paths into one |
  47. | [convertShapeToPath](https://github.com/svg/svgo/blob/master/plugins/convertShapeToPath.js) | convert some basic shapes to `<path>` |
  48. | [sortAttrs](https://github.com/svg/svgo/blob/master/plugins/sortAttrs.js) | sort element attributes for epic readability (disabled by default) |
  49. | [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) |
  50. | [removeDimensions](https://github.com/svg/svgo/blob/master/plugins/removeDimensions.js) | remove `width`/`height` attributes if `viewBox` is present (disabled by default) |
  51. | [removeAttrs](https://github.com/svg/svgo/blob/master/plugins/removeAttrs.js) | remove attributes by pattern (disabled by default) |
  52. | [removeElementsByAttr](https://github.com/svg/svgo/blob/master/plugins/removeElementsByAttr.js) | remove arbitrary elements by ID or className (disabled by default) |
  53. | [addClassesToSVGElement](https://github.com/svg/svgo/blob/master/plugins/addClassesToSVGElement.js) | add classnames to an outer `<svg>` element (disabled by default) |
  54. | [addAttributesToSVGElement](https://github.com/svg/svgo/blob/master/plugins/addAttributesToSVGElement.js) | adds attributes to an outer `<svg>` element (disabled by default) |
  55. | [removeStyleElement](https://github.com/svg/svgo/blob/master/plugins/removeStyleElement.js) | remove `<style>` elements (disabled by default) |
  56. 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))
  57. ## How to use
  58. ```sh
  59. $ [sudo] npm install -g svgo
  60. ```
  61. ```
  62. Usage:
  63. svgo [OPTIONS] [ARGS]
  64. Options:
  65. -h, --help : Help
  66. -v, --version : Version
  67. -i INPUT, --input=INPUT : Input file, "-" for STDIN
  68. -s STRING, --string=STRING : Input SVG data string
  69. -f FOLDER, --folder=FOLDER : Input folder, optimize and rewrite all *.svg files
  70. -o OUTPUT, --output=OUTPUT : Output file or folder (by default the same as the input), "-" for STDOUT
  71. -p PRECISION, --precision=PRECISION : Set number of digits in the fractional part, overrides plugins params
  72. --config=CONFIG : Config file or JSON string to extend or replace default
  73. --disable=DISABLE : Disable plugin by name
  74. --enable=ENABLE : Enable plugin by name
  75. --datauri=DATAURI : Output as Data URI string (base64, URI encoded or unencoded)
  76. --multipass : Enable multipass
  77. --pretty : Make SVG pretty printed
  78. --indent=INDENT : Indent number when pretty printing SVGs
  79. -q, --quiet : Only output error messages, not regular status messages
  80. --show-plugins : Show available plugins and exit
  81. Arguments:
  82. INPUT : Alias to --input
  83. OUTPUT : Alias to --output
  84. ```
  85. * with files:
  86. $ svgo test.svg
  87. or:
  88. $ svgo test.svg test.min.svg
  89. * with STDIN / STDOUT:
  90. $ cat test.svg | svgo -i - -o - > test.min.svg
  91. * with folder
  92. $ svgo -f ../path/to/folder/with/svg/files
  93. or:
  94. $ svgo -f ../path/to/folder/with/svg/files -o ../path/to/folder/with/svg/output
  95. * with strings:
  96. $ svgo -s '<svg version="1.1">test</svg>' -o test.min.svg
  97. or even with Data URI base64:
  98. $ svgo -s 'data:image/svg+xml;base64,…' -o test.min.svg
  99. * with SVGZ:
  100. from `.svgz` to `.svg`:
  101. $ gunzip -c test.svgz | svgo -i - -o test.min.svg
  102. from `.svg` to `.svgz`:
  103. $ svgo test.svg -o - | gzip -cfq9 > test.svgz
  104. * with GUI – [svgo-gui](https://github.com/svg/svgo-gui)
  105. * as a web app - [SVGOMG](https://jakearchibald.github.io/svgomg/)
  106. * as a Nodejs module – [examples](https://github.com/svg/svgo/tree/master/examples)
  107. * as a Grunt task – [grunt-svgmin](https://github.com/sindresorhus/grunt-svgmin)
  108. * as a Gulp task – [gulp-svgmin](https://github.com/ben-eb/gulp-svgmin)
  109. * as a Mimosa module – [mimosa-minify-svg](https://github.com/dbashford/mimosa-minify-svg)
  110. * as an OSX Folder Action – [svgo-osx-folder-action](https://github.com/svg/svgo-osx-folder-action)
  111. * as a webpack loader – [image-webpack-loader](https://github.com/tcoopman/image-webpack-loader)
  112. * as a Telegram Bot – [svgo_bot](https://github.com/maksugr/svgo_bot)
  113. * as a PostCSS plugin - [postcss-svgo](https://github.com/ben-eb/postcss-svgo)
  114. ## License and copyrights
  115. This software is released under the terms of the [MIT license](https://github.com/svg/svgo/blob/master/LICENSE).
  116. Logo by [Yegor Bolshakov](http://xizzzy.ru/).