sidebar_position | title |
---|---|
1 |
Getting Started |
If you’re running on a supported platform, installation should be as simple as:
npm install skia-canvas
This will download a pre-compiled library from the project’s most recent release.
The underlying Rust library uses N-API v8 which allows it to run on Node.js versions:
- v12.22+
- v14.17+
- v15.12+
- v16.0.0 and later
Pre-compiled binaries are available for:
- Linux (x64 & arm64)
- macOS (x64 & Apple silicon)
- Windows (x64)
Nearly everything you need is statically linked into the library. A notable exception is the Fontconfig library which must be installed separately if you’re running on Linux.
The library is compatible with Linux systems using glibc 2.28 or later as well as Alpine Linux (x64 & arm64) and the musl C library it favors. In both cases, Fontconfig must be installed on the system for skia-canvas
to operate correctly.
If you are setting up a Dockerfile that uses node
as its basis, the simplest approach is to set your FROM
image to one of the (Debian-derived) defaults like node:lts
, node:18
, node:16
, node:14-buster
, node:12-buster
, node:bullseye
, node:buster
, or simply:
FROM node
You can also use the ‘slim’ image if you manually install fontconfig:
FROM node:slim
RUN apt-get update && apt-get install -y -q --no-install-recommends libfontconfig1
If you wish to use Alpine as the underlying distribution, you can start with something along the lines of:
FROM node:alpine
RUN apk update && apk add fontconfig
If prebuilt binaries aren’t available for your system you’ll need to compile the portions of this library that directly interface with Skia.
Start by installing:
- The Rust compiler and cargo package manager using
rustup
- A C compiler toolchain (either LLVM/Clang or MSVC)
- Python 3 (used by Skia's build process)
- The Ninja build system
- On Linux: Fontconfig and OpenSSL
Detailed instructions for setting up these dependencies on different operating systems can be found in the ‘Building’ section of the Rust Skia documentation. Once all the necessary compilers and libraries are present, running npm run build
will give you a usable library (after a fairly lengthy compilation process).
When rendering canvases in the background (e.g., by using the asynchronous saveAs or toBuffer methods), tasks are spawned in a thread pool managed by the rayon library. By default it will create up to as many threads as your CPU has cores. You can see this default value by inspecting any Canvas object's engine.threads
property. If you wish to override this default, you can set the SKIA_CANVAS_THREADS
environment variable to your preferred value.
For example, you can limit your asynchronous processing to two simultaneous tasks by running your script with:
SKIA_CANVAS_THREADS=2 node my-canvas-script.js