https://github.com/piqnt/svgexport
SVG to PNG/JPEG command-line tool and Node.js module
https://github.com/piqnt/svgexport
cli command-line javascript jpeg png rasterizer svg
Last synced: 4 months ago
JSON representation
SVG to PNG/JPEG command-line tool and Node.js module
- Host: GitHub
- URL: https://github.com/piqnt/svgexport
- Owner: piqnt
- Created: 2014-09-23T03:18:11.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2025-04-03T17:12:45.000Z (about 1 year ago)
- Last Synced: 2025-06-20T19:19:22.907Z (10 months ago)
- Topics: cli, command-line, javascript, jpeg, png, rasterizer, svg
- Language: JavaScript
- Homepage:
- Size: 113 KB
- Stars: 944
- Watchers: 17
- Forks: 88
- Open Issues: 56
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
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
```
#### Installation Issues
You might encounter an error while installing because of a puppeteer issue documented here
[puppeteer/puppeteer#367](https://github.com/puppeteer/puppeteer/issues/367)
To circumvent this, you will need the following command
```
sudo npm install -g svgexport --unsafe-perm=true
```
#### Usage
```usage
svgexport
svgexport
[] [] [] [] [] []
png|jpeg|jpg
If not specified, it will be inferred from output file extension or defaults to "png".
1%-100%
:::|:
If input viewbox is not specified it will be inferred from input file.
x|:|:|:
If output size is specified as width:height, is used.
crop|pad
Crop (slice) or pad (extend) input to match output aspect ratio, default mode is "crop".
Path of a JSON file with following content:
[ {
"input" : ["", "", "", ...],
"output": [ ["", "", "", ...] ]
}, ...]
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*