Node.js SVGExport Module Project to Export SVG to PNG/JPEG Image in Browser Using Express.js

 

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 i -g svgexport

 

Usage

 

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:

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

Set output JPEG quality:

Use a CSS to style input SVG:

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.

Node.js Module

Installation

Usage

datafile can be an object, an array of objects or a JSON file path, see command line usage for its format

Node.js Express App in Browser

 

 

npm init -y

 

 

npm i express

 

 

npm i multer

 

 

Make a uploads directory inside the root project

 

 

index.js

 

 

 

 

 

index.html

 

 

Leave a Reply