Node / Canvas · guide
Canvas and createCanvas
Understand createCanvas, CanvasConfig, CanvasResults, validation, backgrounds, rendering order, and the core Node canvas workflow.
Signature & types
CanvasConfig and CanvasResults are the primary configuration and result contracts for the Node canvas workflow. The signature-types heading remains canonical so legacy deep links continue to resolve after the DOC-3 component migration.
Prerequisites
- Apexify.js 6.0.0 installed in a Node runtime.
- An
ApexPainterinstance configured for buffer output. - Explicit width and height for predictable production output unless an inherited image/video source determines them.
Minimal workflow
- Import
ApexPainterfromapexify.js. - Create a painter with buffer output.
- Call
createCanvaswith explicit dimensions and one primary fill. - Use
bufferas the PNG output or composite additional image/text/chart content.
Return value (CanvasResults)
| Feature | Field | Meaning |
|---|---|---|
| buffer | Buffer | PNG bytes for saving, output, or later composition |
| canvas | CanvasConfig | Effective configuration reference after inherited sizing or other mutations |
Defaults and validation
| Feature | Status | Notes |
|---|---|---|
| width / height | Defaults to 500 × 500 | Prefer explicit production dimensions unless customBg.inherit or videoBg.inherit determines size |
| primary background | Mutually exclusive | Use at most one of colorBg, gradientBg, customBg, videoBg, or transparentBase: true |
| videoBg still-frame controls | Image-style parity | Supports inherit, fit, align, filters, opacity, 1-based frame or time, jpg/png and FFmpeg quality 1–31 |
| opacity | 0 through 1 | Values outside the range are invalid |
| zoom.scale | Greater than 0 | Required when zoom is configured |
| bgLayers | Validated per entry | Supports configured color, gradient, image, pattern, preset-pattern, and noise layers |
the output dimensions remain independent of source-asset dimensions
the loaded image supplies effective dimensions
the extracted still frame supplies effective dimensions and then uses the same fit/align/filter/opacity pipeline as customBg
layers make paint order explicit instead of overloading the primary fill
Paint architecture
Primary fill rule
Use only one primary background among colorBg, gradientBg, customBg, videoBg, and transparentBase: true. videoBg extracts one still frame and then shares the same image-style inherit / fit / align / filters / opacity behavior as customBg. Additional layering concerns belong in the dedicated background-layer options.
Verified executable example
Executable example · minimal
Create a deterministic canvas
Render a fixed 320×180 server-side PNG using the public ApexPainter canvas API.
Prerequisites
- Node.js 22, 24, or 26
- apexify.js 6.0.0
Authoritative source
Source hash: d1603f74395a1b3c07efbf96be39ca6d867413977a29ea556c0bfc1e712649e4. The displayed payload is generated from the files executed by DOC-5 verification.

Goal
Create the smallest useful server-rendered image with explicit dimensions and background color.
Important options
widthheightcolorBg
Why these choices
- Explicit dimensions make output verification deterministic.
- A local color background avoids remote assets and font dependencies.
Variants
- Replace colorBg with a gradient or layered background after the basic pipeline is understood.
Performance note
The example uses one small canvas and performs no remote I/O.
Error note
Invalid dimensions are rejected by Apexify.js runtime validation before rendering.
Related documentation
Related API
Next steps
Use node.chart.bar for a generated chart or node.integration.report for a multi-file workflow.
What happens next
- The source above is read from the authoritative example file, not copied into this MDX page.
- DOC-5 installs the packed Apexify.js artifact into an isolated consumer fixture.
- The source typechecks, executes, and produces the preview shown above.
- Gallery consumes the same stable example identity and generated source/output record.
Implementation path
CanvasCreator.createCanvas (canvas/canvas-creator.ts) delegates through the canvas composition/paint helpers and supporting background, pattern, shadow, stroke, and clip-path modules.
Next steps
- Continue to Canvas size and coordinates.
- Open the canonical executable example page for source, verification state, output, and API relationships.
- Use the legacy feature-guide links for deeper background/effect topics until DOC-9 migrates the remaining corpus to canonical routes.
Interactive example
Create a deterministic canvas
Open the verified source and output side by side. The editor is deferred until requested; this documentation surface does not pretend to run Node code in the browser.
