New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

canvas-multiline-emoji

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

canvas-multiline-emoji

Reduces font-size and auto create new lines based on rect-size with emoji support.

  • 1.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-80%
Maintainers
1
Weekly downloads
 
Created
Source

canvas-multiline-emoji

CodeFactor NPM-Version NPM-Downloads Github Stars Issues

Typesafe multiline text on canvas with emoji support

Draws text in a rectangle on a canvas, on multiple lines.

Instalattion

To install use:

npm i canvas-multiline-emoji

Usage

Exports a single function that draws text on a canvas, breaking it into multiple lines if needed.

Also shrinks the font size to make in fit in the defined rectangle.

Returns the font size used

const fontSize = await drawText(canvas2Dcontext, text, options);

Example

import fs from 'node:fs';
import { Canvas } from 'canvas';
import { drawText } from 'canvas-multiline-emoji';

const canvas = new Canvas(500, 500);
const ctx = canvas.getContext('2d');
const text = 'The old rusted farm equipment 🤪 surrounded the house predicting its demise. He uses onomatopoeia as a weapon of mental destruction. 👍';
const options = {
    font: 'OpenSans',
    verbose: true,
    rect: {
        x: 50,
        y: 50,
        width: canvas.width - (50 * 2),
        height: canvas.height - (50 * 2),
    },
    minFontSize: 10,
    maxFontSize: 40,
    lineHeight: 1.2
};

const test = async () => {
    /* --- background --- */
    ctx.fillStyle = '#4a4aad';
    ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
    /* --- font color --- */
    ctx.fillStyle = '#ceceec';
    
    const fontSizeUsed = await drawText(ctx, text, options);
    console.log('Font size used: ', fontSizeUsed);

    const buffer = canvas.toBuffer();
    fs.writeFileSync('test.png', buffer);
};

test();
Options

The options type is defined as MultilineOptions and (almost) all its keys are optional.

ParameterDescriptionDefault
fontFont name / family to usesans-serif
rectRectangle object with x, y, width, height. Text will be drawn inside this.Canvas Size
minFontSizeMinimum font size to use.8
maxFontSizeMaximum font size to use.100
lineHeightMultiplicator for line height1
strokeDefines whether strokeText will be used instead of fillTextfalse
verboseDefines whether if should print debug infofalse
logFunctionCustome function for logging.console.log

Dependencies

This module requires some kind of Canvas object.

Inspired on: https://gitlab.com/davideblasutto/canvas-multiline-text

Keywords

FAQs

Package last updated on 20 Feb 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc