Export SVG to PNG/JPEG Image Using Node.js Express.js and SVGExport Module

What is 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.

Installation

Shell

Usage

Scale 1.5x proportionally:

Shell

Scale proportionally to set output width to 32px:

Shell

Scale proportionally and pad output to set output width:height to 32px:54px:

Shell

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

Shell

Set output JPEG quality:

Shell

Use a CSS to style input SVG:

Shell

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.

Shell

Node.js Module

Installation

Shell

Usage

HTML

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

Shell
Shell
Shell

Make a uploads directory inside the root project

index.js

JavaScript

index.html

HTML

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.