# svg2png-many

> Fast svg to png converter for many files based on PhantomJS

Latest version **0.0.7** (published 2016-06-14) · ISC license · 0 weekly downloads

## Install

```sh
npm install svg2png-many
pnpm add svg2png-many
yarn add svg2png-many
bun add svg2png-many
```

Provides the command `svg2png-many`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.7 |
| Published | 2016-06-14 |
| First published | 2016-04-25 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.12 |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Author | Alexey Tronov |
| Maintainers | atronov |
| Keywords | phantom, phantomjs, svg, png, converter, fast |

## Links

- npm: https://www.npmjs.com/package/svg2png-many
- Repository: https://github.com/atronov/svg2png-many
- Issues: https://github.com/atronov/svg2png-many/issues
- npm.io page: https://npm.io/package/svg2png-many

## Dependencies (2)

- [yargs](https://npm.io/package/yargs.md) ^4.6.0
- [phantom](https://npm.io/package/phantom.md) ^2.0.x

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 0.0.7 (latest) — 2016-06-14
- 0.0.6 — 2016-04-29
- 0.0.5 — 2016-04-29
- 0.0.4 — 2016-04-28
- 0.0.3 — 2016-04-26
- 0.0.2 — 2016-04-26
- 0.0.1 — 2016-04-25

## README

# svg2png-many
NodeJS module and CLI to convert **many** svg files to png rapidly.

Inspired by [svg2png](https://github.com/domenic/svg2png) and [phantomjs-node](https://github.com/amir20/phantomjs-node). Many thanks to them.

The main difference from [svg2png](https://github.com/domenic/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.
```javascript
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.<br/>
All possible arguments described below are also accepted by this function.
```javascript
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.<br/>
Height or/and width can be skipped. Aspect ration is preserved.
```javascript
var sizes = {
	height: 300,
	width: 500
};
svg2png(srcDir, dstDir, sizes);
```

Define how many web-pages can be opened in PhantomJS simultaneously.<br/>
This argument manages performance aspects. The higher this argument is the faster conversion, but more memory is consumed.<br/>
Default value is 20.
```javascript
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
```bash
$ ./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
```bash
$ ./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.<br/>
**svg2png** vs **svg2png-many**<br/>
**11min** vs **27sec**

```bash
$ 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
```

---
_Source: https://npm.io/package/svg2png-many · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
