npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

svg2png-many

v0.0.7

Published

Fast svg to png converter for many files based on PhantomJS

Downloads

8

Readme

svg2png-many

NodeJS module and CLI to convert many svg files to png rapidly.

Inspired by svg2png and phantomjs-node. Many thanks to them.

The main difference from svg2png that it works much faster convering many files. Because of it uses one PhantomJS instenct for many files and opens many web-pages simultaniously.

Using as NodeJS module

NOTE! All functions below return a promise.

Convert all svg from certain folder to the other folder.

const svg2png = require('svg2png-many');
var srcDir = 'dir/with/source/svgs';
var dstDir = 'dir/with/result/pngs';
svg2png(srcDir, dstDir).then(
  () => console.log('Done'),
  // rejected with the list of all happened errors
  // even if error happens while processing one file it will not stop conversion other files
  // first all files are processed, only then the result promise is rejected or resolved
  errors => errors.forEach(error => {
    arrors = Array.isArray(errors) ? errors : [errors];
    console.error(error.stack || error);
  })
);

// same function can be run as alias
svg2png.svg2PngDir(srcDir, dstDir);

Convert only certain files to defined destination. All possible arguments described below are also accepted by this function.

var fileMap = {
  'one/file/to/convert.svg': 'first/file/result/image.png',
  'second/file/to/process.svg': 'other/place/to/save/result.png'
};
svg2png.svg2PngFiles(fileMap);

Define sizes of result png. Height or/and width can be skipped. Aspect ration is preserved.

var sizes = {
	height: 300,
	width: 500
};
svg2png(srcDir, dstDir, sizes);

Define how many web-pages can be opened in PhantomJS simultaneously. This argument manages performance aspects. The higher this argument is the faster conversion, but more memory is consumed. Default value is 20.

var parallelPages = 10;
svg2png(srcDir, dstDir, null, parallelPages);

Using as CLI

To convert all svg files from one folter and put png to the other

$ ./node_modules/.bin/svg2png-many -i dir/with/source/svgs/ -o dir/with/result/pngs/
3 files have been converted successfully

To see all possible argument, run with help option

$ ./node_modules/.bin/svg2png-many --help
Options:
  -i, --input    Path to dir with svg files                  [string] [required]
  -o, --output   Path to dir with results, it not defined, input will be used
                                                                        [string]
  -w, --width    With of result png                                     [number]
  -h, --height   Height of result png                                   [number]
  -t, --threads  Number of threads                                      [number]
  --phantom      Path to alternative phantom                            [string]
  --help         Show help                                             [boolean]

Benchmark

I compared speed on 500 files. svg2png vs svg2png-many 11min vs 27sec

$ time ./node_modules/.bin/svg2png-many -i src res
500 files have been converted successfully
real    0m27.489s
user    0m11.483s
sys     0m7.330s

$ time for f in src/*.svg; do ./node_modules/.bin/svg2png $f; done  
real    11m40.203s
user    5m47.640s
sys     1m45.301s