Skip to content

sauvainr/svg2png

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SVG-to-PNG Converter Using PhantomJS

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

svg2png("source.svg", "dest.png", function (err) {
    // PNGs for everyone!
});

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

svg2png("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.

We can also convert animation to multiple images:

svg2pngs("source.svg", "dest.png", 3, 2, function (err) {
    // take 3 images in 2 seconds
});

The first image is always the first frame, and the last one is always the last frame after the given time. An incrementing number will be added to output images name.

svg2png 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.

About

A SVG to PNG converter, using PhantomJS.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%