SVG to PNG/JPEG command-line tool and Node.js module
Switch branches/tags
Nothing to show
Clone or download
Latest commit 97df46e May 3, 2016
Failed to load latest commit information.
bin path with space fixed Mar 3, 2015
test update test May 1, 2016
.gitignore init Sep 23, 2014
.travis.yml update travis May 1, 2016 temporary fix for phantomjs+windows May 1, 2016
appveyor.yml update appveyor May 1, 2016
index.js fix May 3, 2016
package.json fix May 3, 2016
render.js temporary fix for phantomjs+windows May 1, 2016
resize.js fix viewbox issue Oct 9, 2015


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

Command Line


npm install svgexport -g


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.


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;}"

Node.js Module


npm install svgexport --save


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.


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

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