Generate dynamic images or thumbnails on a server without spinning up a browser
Render charts, diagrams, or annotated images as PNG files in a Node.js backend
Produce PDFs programmatically using the same canvas drawing code you'd write for a browser
Add text with full Unicode and right-to-left script support to server-generated images
Requires installing system libraries (libcairo, libpango) via your OS package manager before running npm install.
Node-canvas brings the browser's drawing API to Node.js, letting you create and manipulate images on a server without a browser involved. In a browser, you can draw shapes, text, and images onto a canvas element and then export the result as a PNG or JPEG. Node-canvas replicates that same programming interface so that scripts running on a server can do all the same things: draw rectangles, render text with custom fonts, load and composite photos, and save the finished image to a file or send it as a response. Under the hood, it relies on Cairo, a well-established graphics library used in Linux desktop environments and many other places. This is why the installation involves a few system-level dependencies beyond the usual npm install. On a Mac or Linux machine you install libraries like libpango and libcairo through your system package manager first, then install the npm package. Pre-built binaries are available for common platforms, so most users do not need to compile anything themselves. The API closely follows the standard Web Canvas API that browsers expose. If you have written canvas drawing code for a website, most of it will work in node-canvas with little or no change. The project documents the gaps where behavior differs from the browser standard. There are also a handful of extras not found in browsers, such as the ability to export directly to a PDF or SVG file, stream output progressively, or load fonts from local files using registerFont. Common use cases include generating dynamic images on a server, creating thumbnail previews, rendering charts or diagrams as PNG files, and producing PDFs programmatically. Because Cairo handles text through the Pango library, node-canvas supports full Unicode text, right-to-left scripts, and complex font features, which plain image-manipulation libraries sometimes lack. The package is maintained by Automattic, the company behind WordPress.com. It requires Node.js 18.12.0 or later.
← automattic on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.