nanosvg
SVG files compression tool for Nano. More information in [Nano](https://vecta.io/nano)
Last updated a month ago by fahmi.radica .
Bugs · Original npm · Tarball · package.json
$ cnpm install nanosvg 
SYNC missed versions from official npm registry.

Nano

NanoSVG uses lossless techniques to compress your SVG and save up to 80% bandwidth.

  • Compress 22% better than the competition, resulting in smaller SVG images
  • Selectively embed fonts to ensure your SVG images works everywhere without loss of fonts irrespective of how you embed them.
  • Cleans out malicious codes and scripts
  • For more information, visit Nano

This package requires a paid license from Nano

For free usage, visit Nano.

Installation

npm install -g nanosvg

Usages

Nanosvg can be used on the command line (CLI), or as a module in any node.js compatible build system.

Usages on CLI

Activation

Please purchase a license from Nano. That would help us improve and keep us going. A one time activation is required.

nanosvg --activate=YOUR_SERIAL_KEY

Command line syntax

nanosvg src_glob dest_folder [--options=value]+

Examples

//Compress a single file and output to folder with default options
nanosvg ./test.svg ./compressed 

//Compress all svg files and output to folder with default options
nanosvg ./images/*.svg ./compressed

//Compress all dxf files and output to folder with default options
nanosvg ./images/*.dxf ./compressed

//Compress all svg files and output to folder
//with no font embedding and precision = 4
nanosvg ./images/*.svg ./compressed --fonts=false --precision=4 

Usage as a module

var nanofy = require('nanosvg');

//Compress a single file and output to folder with default options
nanofy('./test.svg', './compressed').then(function () { 
    console.log('Completed'); 
});

//Compress all svg files and output to folder with default options
nanofy('./images/*.svg', './compressed').then(function () { 
    console.log('Completed'); 
});

//Compress all svg files and output to folder 
//with no font embedding and precision = 4
nanofy('./images/*.svg', './compressed', {
    fonts: false,
    precision: 4
}).then(function () { console.log('Completed'); });

//Gulp task to watch for SVG changes
gulp.task('Watch SVG', function() {
    gulp.watch('watch/this/folder/*.svg')
    .on('change', function(file) {
        nanofy(file, './destination/folder');
    });
});

Options

  • precision=3 <number>

Set the number of decimal places to compress for numerical values, defaults to 3. Applies only to values with decimal places larger than precision.

<!-- original -->
<path d="M 0 0 C 123.75 50 117.1875 11.5625 140.93753 11.56251"/>

<!-- precision = 3 (default) -->
<path d="M0 0c123.75 50 117.188 11.563 140.938 11.563"/>

<!-- precision = 4 -->
<path d="M0 0c123.75 50 117.1875 11.5625 140.9375 11.5625"/>
  • fonts=true <boolean>

Enable the embedding of fonts, defaults to true. If enabled, will embed fonts into the SVG, if text and fonts are detected. Fonts must be available on Google fonts.

  • classes=false

Do not modify your classes in the SVG, defaults to false.

<!-- Original -->
<rect class="MyClass" x="0" y="0" width="50" height="50"/>

<!-- classes = false -->
<path class="A" fill="none" d="M0 0h50v50H.5z"/>

<!-- classes = true -->
<path class="MyClass" fill="none" d="M0 0h50v50H.5z"/>
  • ids=false

Do not modify your id(s) in the SVG, defaults to false.

<!-- Original -->
<rect id="MyID" x="0" y="0" width="50" height="50"/>

<!-- ids = false -->
<path ids="A" fill="none" d="M0 0h50v50H.5z"/>

<!-- ids = true -->
<path ids="MyID" fill="none" d="M0 0h50v50H.5z"/>
  • structure=false

Do not modify your structure in the SVG, defaults to false. Useful when used on object tags, when you want to maintain original structure for interactivity.

  • events=false

Do not modify your events in the SVG, defaults to false. Useful when used on object tags, when you want to maintain these events for interactivity.

  • wordpress=false

Export as WordPress-compatible SVG, defaults to false.

  • react=false

Export as React SVG component in JSX file format, defaults to false.

Current Tags

  • 1.4.1                                ...           latest (a month ago)

50 Versions

  • 1.4.1                                ...           a month ago
  • 1.4.0                                ...           a month ago
  • 1.3.9                                ...           a month ago
  • 1.3.8                                ...           a month ago
  • 1.3.7                                ...           a month ago
  • 1.3.6                                ...           a month ago
  • 1.3.5                                ...           2 months ago
  • 1.3.4                                ...           2 months ago
  • 1.3.3                                ...           3 months ago
  • 1.3.2                                ...           3 months ago
  • 1.3.1                                ...           3 months ago
  • 1.3.0                                ...           3 months ago
  • 1.2.499 [deprecated]           ...           3 months ago
  • 1.2.498 [deprecated]           ...           3 months ago
  • 1.2.497 [deprecated]           ...           3 months ago
  • 1.2.496 [deprecated]           ...           3 months ago
  • 1.2.495 [deprecated]           ...           3 months ago
  • 1.2.494 [deprecated]           ...           3 months ago
  • 1.2.493 [deprecated]           ...           3 months ago
  • 1.2.492 [deprecated]           ...           3 months ago
  • 1.2.491 [deprecated]           ...           3 months ago
  • 1.2.49 [deprecated]           ...           3 months ago
  • 1.2.48 [deprecated]           ...           3 months ago
  • 1.2.47 [deprecated]           ...           3 months ago
  • 1.2.46 [deprecated]           ...           3 months ago
  • 1.2.43 [deprecated]           ...           3 months ago
  • 1.2.42 [deprecated]           ...           3 months ago
  • 1.2.41 [deprecated]           ...           3 months ago
  • 1.2.4 [deprecated]           ...           3 months ago
  • 1.2.3 [deprecated]           ...           3 months ago
  • 1.2.2 [deprecated]           ...           8 months ago
  • 1.2.1 [deprecated]           ...           8 months ago
  • 1.2.0 [deprecated]           ...           8 months ago
  • 1.1.6 [deprecated]           ...           a year ago
  • 1.1.5 [deprecated]           ...           a year ago
  • 1.1.4 [deprecated]           ...           a year ago
  • 1.1.3 [deprecated]           ...           a year ago
  • 1.1.2 [deprecated]           ...           a year ago
  • 1.1.1 [deprecated]           ...           a year ago
  • 1.1.0 [deprecated]           ...           a year ago
  • 1.0.9 [deprecated]           ...           a year ago
  • 1.0.8 [deprecated]           ...           a year ago
  • 1.0.7 [deprecated]           ...           a year ago
  • 1.0.6 [deprecated]           ...           a year ago
  • 1.0.5 [deprecated]           ...           a year ago
  • 1.0.4 [deprecated]           ...           a year ago
  • 1.0.3 [deprecated]           ...           a year ago
  • 1.0.2 [deprecated]           ...           a year ago
  • 1.0.1 [deprecated]           ...           a year ago
  • 1.0.0 [deprecated]           ...           a year ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 38
Dependencies (16)
Dev Dependencies (0)
None
Dependents (1)

Copyright 2014 - 2016 © taobao.org |