
Security News
Frontier AI Is Now Critical Infrastructure
The Fable shutdown shows how quickly model access can become a business continuity risk for AI-dependent engineering teams.
cherry-box
Advanced tools
A node-canvas package filled with utilities, manage text boxes easily and more
cherry-box is a Node.js package filled with utilities, which are useful for working with node-canvas.
const cb = require("cherry-box")
const Canvas = require("canvas")
const fs = require("fs");
let canvas = Canvas.createCanvas(1000, 200);
let ctx = canvas.getContext('2d');
let text = [
{
text: "I like cookies!",
color: "#ffffff",
font: "monospace",
modifier: "bold",
}
]
cb.textBox(ctx, 0, 0, 1000, 200, text, 200, [1, 1]);
// Save canvas to file
let out = fs.createWriteStream("./out.png");
let stream = canvas.createPNGStream();
stream.pipe(out);
Using modules:
import { textBox } from "cherry-box";
import { createCanvas } from "canvas";
import fs from "fs";
let canvas = Canvas.createCanvas(1000, 200);
let ctx = canvas.getContext('2d');
let text = [
{
text: "I like cookies!",
color: "#ffffff",
font: "monospace",
modifier: "bold",
}
]
textBox(ctx, 0, 0, 1000, 200, text, 200, [1, 1]);
// Save canvas to file
let out = fs.createWriteStream("./out.png");
let stream = canvas.createPNGStream();
stream.pipe(out);
When using textObject you also need to import TextObject
import { textObject } from "cherry-box";
...
let text: TextObject = [
{
text: "I like cookies!",
color: "#ffffff",
font: "monospace",
modifier: "bold",
}
]
...
TextObject is made of multiple objects. These objects accepts the following values:
| name | description | example | type | required |
|---|---|---|---|---|
| text | Text to be displayed | Hello world | string | true |
| font | Font of the text | Arial | string | true |
| color | Color of the text | #FFFFFF | string | true |
| modifier | Modifier of the text | bold | string | false |
| shadow | Shadow of the text | object | false |
Shadow is a JSON object with the following values:
xandyoffsets are relative to the text size. For example usex: 10, y: 10
| name | description | example | type | required |
|---|---|---|---|---|
| color | Color of the shadow | #FFFFFF | string | true |
| blur | Blur of the shadow | 5 | number | true |
| offset | X and Y offset of the shadow | [10, 5] | array | true |
Example text schema:
[
{
text: "I like cookies!",
color: "#ff8800",
shadow: {
offset: [10, 10], blur: 5, color: "red"
},
font: "Arial",
modifier: "bold"
}
]
textBox is an easy way to align your text, decrease font size to fit in an area and more.
| name | description | example | type | required |
|---|---|---|---|---|
| ctx | Canvas context | CanvasRenderingContext2D | true | |
| x | X coordinate of the text box | 0 | number | true |
| y | Y coordinate of the text box | 0 | number | true |
| width | Width of the text box | 100 | number | true |
| height | Height of the text box | 100 | number | true |
| text | Text to be displayed in the text box | TextObject | true | |
| fontSize | Maximum font size of the text | 100 | number | true |
| align | Align of the text | [1,1] | array | true |
0, center 1, right 20, middle 1, bottom 2Example: [1,1]
Example use of textBox in your code:
textBox(ctx, 0, 0, canvas.width, canvas.height-20, upperText, 80, [2,1]);
wrapText is a function similar to textBox, but it doesn't just align the text. It also wraps the text to fit in the specified width.
| name | description | example | type | required |
|---|---|---|---|---|
| ctx | Canvas context | CanvasRenderingContext2D | true | |
| x | X coordinate of the text box | 0 | number | true |
| y | Y coordinate of the text box | 0 | number | true |
| width | Width of the text box | 100 | number | true |
| text | Text to be displayed in the text box | TextObject | true | |
| fontSize | Maximum font size of the text | 100 | number | true |
| align | Align of the text | 3 | number | true |
0123Example use of wrapText in your code:
wrapText(ctx, 0, 0, canvas.width, text, 20, 3);
FAQs
A node-canvas package filled with utilities, manage text boxes easily and more
The npm package cherry-box receives a total of 143 weekly downloads. As such, cherry-box popularity was classified as not popular.
We found that cherry-box demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
The Fable shutdown shows how quickly model access can become a business continuity risk for AI-dependent engineering teams.

Security News
AI agents are pulling packages into environments no scanner is watching, creating exposure before security teams can see it.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.