# svgexport

> Node.js module and command-line tool for exporting SVG to PNG and JPEG.

Latest version **0.4.2** (published 2021-04-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install svgexport
pnpm add svgexport
yarn add svgexport
bun add svgexport
```

Provides the command `svgexport`.

## Health

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

Positive: no vulnerabilities; high maintenance score.

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

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.4.2 |
| Published | 2021-04-30 |
| First published | 2014-09-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 138.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 951 |
| Author | Ali Shakiba |
| Maintainers | shakiba, michaelheerklotz |
| Keywords | svg, export, rasterize, converter, png, jpeg, jpg, cli, command line, inkscape, illustrator, coreldraw |

## Links

- npm: https://www.npmjs.com/package/svgexport
- Repository: https://github.com/shakiba/svgexport
- Homepage: https://github.com/shakiba/svgexport#readme
- Issues: https://github.com/shakiba/svgexport/issues
- npm.io page: https://npm.io/package/svgexport

## Dependencies (2)

- [async](https://npm.io/package/async.md) ^3.2.0
- [puppeteer](https://npm.io/package/puppeteer.md) ^3.0.2

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 0.4.2 (latest) — 2021-04-30
- 0.4.1 — 2020-08-04
- 0.4.0 — 2020-01-16
- 0.3.2 — 2016-05-03
- 0.3.1 — 2016-05-03
- 0.3.0 — 2016-02-27
- 0.2.8 — 2015-11-10
- 0.2.7 — 2015-10-13
- 0.2.6 — 2015-10-09
- 0.2.5 — 2015-05-19
- 0.2.4 — 2015-03-11
- 0.2.3 — 2015-03-10
- 0.2.2 — 2015-03-05
- 0.2.1 — 2015-03-03
- 0.2.0 — 2015-02-01
- … 14 more at https://npm.io/package/svgexport/versions

## README

# svgexport

svgexport is a Node.js module and command-line tool for exporting SVG files to PNG and JPEG, it uses Puppeteer for rendering SVG files.

### Command Line

#### Installation
```
npm install svgexport -g
```

#### Usage
```usage
svgexport <input file> <output file> <options>
svgexport <datafile>

<options>        [<format>] [<quality>] [<input viewbox>] [<output size>] [<resize mode>] [<styles>]

<format>         png|jpeg|jpg
                 If not specified, it will be inferred from output file extension or defaults to "png".
                 
<quality>        1%-100%

<input viewbox>  <left>:<top>:<width>:<height>|<width>:<height>
                 If input viewbox is not specified it will be inferred from input file.
                 
<output size>    <scale>x|<width>:<height>|<width>:|:<height>
                 If output size is specified as width:height, <viewbox mode> is used.

<viewbox mode>   crop|pad
                 Crop (slice) or pad (extend) input to match output aspect ratio, default mode is "crop".

<datafile>       Path of a JSON file with following content:
                 [ {
                   "input" : ["<input file>", "<option>", "<option>", ...],
                   "output": [ ["<output file>", "<option>", "<option>", ...] ]
                 }, ...]
                 Input file options are merged with and overridden by output file options.
                 Instead of a JSON file, a Node module which exports same content can be provided.
```

#### Examples

Scale 1.5x proportionally:
```
svgexport input.svg output.png 1.5x
```

Scale proportionally to set output width to 32px:
```
svgexport input.svg output.png 32:
```

Scale proportionally and pad output to set output width:height to 32px:54px:
```
svgexport input.svg output.png pad 32:54
```

Export `-1:-1:24:24` (`left:top:width:height`) of input.svg to output.png:
```
svgexport input.svg output.png -1:-1:24:24 1x
```

Set output JPEG quality:
```
svgexport input.svg output.jpg 80%
```

Use a CSS to style input SVG:
```
svgexport input.svg output.jpg "svg{background:silver;}"
```

By default, Puppeteer has a page load timeout of 30 seconds. This might not be
enough for large SVG files. If you want to change the page timeout, set the
`SVGEXPORT_TIMEOUT` environment variable to the desired number of seconds.
```bash
// One minute timeout
SVGEXPORT_TIMEOUT=60 svgexport input.svg output.png
```

### Node.js Module

#### Installation
```
npm install svgexport --save
```

#### Usage

```javascript
var svgexport = require('svgexport');

svgexport.render(datafile, callback);
```
`datafile` can be an object, an array of objects or a JSON file path, see command line usage for its format.

### Contributors

svgexport was migrated from PhantomJS to Puppeteer by [Michael Heerklotz](https://github.com/MichaelHeerklotz).

### License

Copyright (c) 2016 Ali Shakiba  
Available under the MIT license

*Keywords: svg, export, rasterize, converter, png, jpeg, jpg, cli, command-line, inkscape, illustrator, coreldraw*

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