🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

cherry-box

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cherry-box

A node-canvas package filled with utilities, manage text boxes easily and more

Source
npmnpm
Version
1.2.3
Version published
Weekly downloads
130
-62.32%
Maintainers
1
Weekly downloads
 
Created
Source

About

cherry-box is a Node.js package filled with utilities, which are useful for working with node-canvas.

Example usage

import { textBox } from "cherry-box";
import Canvas from "canvas";

let canvas = new Canvas.createCanvas(800, 600);
let ctx = canvas.getContext("2d");

let textSchema = [
    {
        text: "I like cookies!",
        color: "#ff8800",
        font: "Arial",
        modifier: "bold",
        shadow: {
            offset: [10, 10], blur: 5, color: "red"
        },
    }
]
textBox(800, 600, textSchema, 200, ['middle', 'center']);

Documentation

  • textBox - Align the text to specified width and height, adjust the size of the font so it fits.
  • textSchema - An easy way to specify text color, font, shadow and more into a JSON object.

textSchema

Text schema is made of multiple objects. These objects accepts the following values:

namedescriptionexampletyperequired
textText to be displayedHello worldstringtrue
colorColor of the text#FFFFFFstringtrue
shadowShadow of the textshadowfalse
fontFont of the textArialstringtrue
modifierModifier of the textboldstringtrue

Example text schema:

[
    {
        text: "I like cookies!",
        color: "#ff8800",
        shadow: {
            offset: [10, 10], blur: 5, color: "red"
        },
        font: "Arial",
        modifier: "bold"
    }
]

Shadow schema

Shadow is a JSON object with the following values:

x and y offsets are relative to the text size. For example use x: 10, y: 10 for minecraft font.

namedescriptionexampletyperequired
colorColor of the shadow#FFFFFFstringtrue
blurBlur of the shadow5numbertrue
offsetX and Y offset of the shadow[10, 5]arraytrue

textBox

textBox is an easy way to align your text, decrease font size to fit in an area and more.

textBox Schema

namedescriptionexampletyperequired
xX position of the textbox0numbertrue
yY position of the textbox0numbertrue
widthWidth of the textbox100numbertrue
heightHeight of the textbox100numbertrue
textText to be displayedtextSchematrue
maxFontMax font size of the text100numbertrue
fontNameFont of the textArialstringtrue
alignAlign of the textarraytrue

Align values

  • Horizontal: left, center or right
  • Vertical: top, middle or bottom

Example: ['top', 'middle']

Example use of textBox in your code:

textBox(ctx, 0, 0, canvas.width, canvas.height-20, upperText, 80, ["bottom", "center"]);

wrapText

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.

wrapText Schema

namedescriptionexampletyperequired
ctxCanvas contextobjecttrue
xX coordinate of the text box0numbertrue
yY coordinate of the text box0numbertrue
widthWidth of the text box100numbertrue
textText to be displayedtextSchematrue
fontSizeFont size of the text100numbertrue
alignAlign of the textjustifystringtrue

Align values

  • left
  • center
  • right
  • justify

Example use of wrapText in your code:

wrapText(ctx, 0, 0, canvas.width, wrapTextBox, 20, 'justify');

Keywords

canvas

FAQs

Package last updated on 11 May 2022

Did you know?

Socket

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.

Install

Related posts