svg-tool
A SVG to PNG converter, using PhantomJS
Last updated 2 years ago by dxprog .
WTFPL · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install svg-tool 
SYNC missed versions from official npm registry.

SVG-to-PNG Converter Using PhantomJS

Forked from svg2png

You have a SVG file. For whatever reason, you need a PNG. svg2png can help.

var svgTool = require('svg-tool');
svgTool("source.svg", "dest.png", function (err) {
    // PNGs for everyone!
});

Maybe you need to scale the image while converting? We can do that too:

svgTool("source.svg", "dest.png", 1.2, function (err) {
    // 1.2×-sized PNGs for everyone!
});

The scale factor is relative to the SVG's viewbox or width/height attributes, for the record.

Do you want to render many SVGs in one go? Totally possible!

// Render to two specific targets
svgTool([ 'source1.svg', 'source2.svg' ], [ 'source1.png', 'source2.png' ], 2, function(err) {
  // Both files got rendered and scaled 2x
});

// Render to a directory
svgTool([ 'my.svg', 'other.svg' ], 'images/', function(err) {
  // We now have images/my.png and images/other.png
});

svg-tool is built on the latest in PhantomJS technology to render your SVGs using a headless WebKit instance. I have found this to produce much more accurate renderings than other solutions like GraphicsMagick or Inkscape. Plus, it's easy to install cross-platform due to the excellent phantomjs npm package—you don't even need to have PhantomJS in your PATH.

CLI

@skyzyx made a CLI version of this; you should go check it out if you're into using the command line.

Current Tags

  • 1.1.0                                ...           latest (2 years ago)

2 Versions

  • 1.1.0                                ...           2 years ago
  • 1.0.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 2
Dependencies (3)
Dev Dependencies (3)
Dependents (2)

Copyright 2014 - 2017 © taobao.org |