Skip to content
Apexify.jsDocs
Apexify.js version v5.4.5

Recipes · recipe

Recipe — social share card (OG-style PNG)

Current Apexify.js 6.0.0 documentation for Recipe — social share card (OG-style PNG).

apexify.jsRuntime: nodeCURRENTSince 6.0.0

Goal: A 1200×630 Open-Graph-style card — dark background + headline — written to disk with painter.save.

Prerequisites: Node ≥16, apexify.js installed, writable ./out (or change directory).


Steps

  1. Instantiate ApexPainter (constructor type optional here — we save raw PNG bytes).
  2. createCanvas — wide banner / colorBg.
  3. createText — large headline onto the CanvasResults.
  4. save — timestamped / counter filename under directory.

Full example

SOURCEtypescript
typescript
Studio
import { ApexPainter } from "apexify.js"; async function main() {  const painter = new ApexPainter({ type: "buffer" });   const canvas = await painter.createCanvas({    width: 1200,    height: 630,    colorBg: "#0f172a",  });   const png = await painter.createText(    [      {        text: "Ship graphics from Node",        x: 72,        y: 340,        font: { size: 64, family: "Arial" },        color: "#f8fafc",        bold: true,      },      {        text: "apexify.js · buffers · save · charts · GIF",        x: 72,        y: 420,        font: { size: 28, family: "Arial" },        color: "#94a3b8",      },    ],    canvas  );   const meta = await painter.save(png, {    directory: "./out",    naming: "timestamp",    prefix: "share-card-",    format: "png",  });   console.log("Wrote:", meta.path);} main().catch(console.error);

Variations

WantChange
Logo / avatarAdd createImage — Images overview
Gradient backdropcreateCanvas gradients / BG layers — Canvas overview
Return base64 for an APInew ApexPainter({ type: 'base64' }) + await painter.outPut(png) — Output encoding

Next steps