Skip to main content

Getting started

thorvg-canvas brings ThorVG vector graphics and Lottie to Node.js. It renders headless on the CPU, into memory, and saves the result as PNG or raw pixels.

Drawing uses the @thorvg/webcanvas API, so code written for the browser runs in Node.js as is.

Requirements​

  • Node.js 20+
  • macOS 11+, Linux (glibc 2.28+ or musl) or Windows, on x64 or arm64

Installation​

npm install thorvg-canvas

The package includes prebuilt binaries for every supported platform. Nothing is compiled or downloaded on install.

Your first canvas​

import { init } from 'thorvg-canvas';

const TVG = await init();
const canvas = new TVG.Canvas({ width: 200, height: 160 });

const shape = new TVG.Shape();
shape.appendRect(20, 20, 160, 120, { rx: 16, ry: 16 }).fill(37, 99, 235, 255);

canvas.add(shape).render();
await canvas.toFile('rect.png');
canvas.destroy();

init() loads ThorVG and returns the ThorVG namespace (TVG). TVG.Canvas is the WebCanvas Canvas without an HTML canvas element: it draws into memory, and toFile() saves the last rendered frame.

Next steps​

  • Canvas explains sizing, the pixel ratio and the lifecycle.
  • Output saves frames as files, buffers or raw pixels.
  • Assets loads SVG, images, Lottie and fonts from files.
  • Examples shows complete scripts with the images they produce.