Skip to content

Latest commit

 

History

History
46 lines (40 loc) · 2.2 KB

File metadata and controls

46 lines (40 loc) · 2.2 KB

SVG processor and minifier Build Status

similar to SVGO (most plugins are based from svgo)

const svgz = require('svgz');
const fs = require('fs');

const svgBuf = fs.readFileSync('./test.svg');
// const result = svgz(svgBuf); // call it with default options
// const result = svgz(svgBuf, {indent:'\t', decimals:3}); // call it with different global options
// and with specific plugins options:
const result = svgz(svgBuf, {
	indent: '\t', 
	decimals: 3,
	plugins: {
		addDefaultFonts: {families: ['sans-serif']},
		removeMetadata: false // disable this one
	}
});
fs.writeFileSync('./test.min.svg', result);

Plugins

name description active
removeMetadata removes <metadata> elements ✔️
cleanupIds removes unused id's attributes ✔️
cleanupViewBox moves the viewBox origin to 0 0 (and adjust transform on children)
moveElemsAttrsToGroup moves up attributes (except transform) to a group wrapper ✔️
moveGroupAttrsToElems moves some group attributes to the content elements ✔️
collapseGroups collapses/unwrap useless groups ✔️
convertPathData optimizes path data: writes in shorter form, applies transformations ✔️
convertTransform collapses multiple transformations and optimizes it ✔️
cleanupNumericValues rounds numeric values to the fixed precision, removes default ‘px’ units, and empty attributes ✔️
addDefaultFonts ensure fallbacks font-family, useful when using web-fonts

Todos:

  • improve jsdom's getComputedSyle to work with presentational attributes (<path stroke="blue") and inherited attributes) or directly use nwsapi on top of sax
  • minifyStyles
  • removeUselessStrokeAndFills
  • removeEmptyTexts
  • pathData
  • merge tranform in shapes too (circle, rect, line..) when possible and shorter
  • ... most svgo plugins and tests