Socket
Socket
Sign inDemoInstall

canvas-text-colorizer

Package Overview
Dependencies
6
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

canvas-text-colorizer

To use the "canvas-text-colorizer" package, you need to have Node.js and the npm package manager installed on your machine.


Version published
Maintainers
1
0

Weekly downloads

Readme

Source

drawText (Beta)

To use the "canvas-text-colorizer" package, you need to have Node.js and the npm package manager installed on your machine.

Tools:

To use colors in text, simply insert a color code after the & character. If you want to make it bold, use &l; to underline, use &n; for italics, use &o; to add a line in the middle of text, use &m; to skip lines, use n; and to reset the formatting, use &r.

  • 0 black
  • 1 dark blue
  • 2 dark green
  • 3 dark cyan
  • 4 dark red
  • 5 dark magenta
  • 6 dark yellow
  • 7 light gray
  • 8 dark grey
  • 9 light blue
  • a light green
  • b light cyan
  • c light red
  • d light magenta
  • e light yellow
  • f white

Installation:

To install the package, open your terminal and type the following command:

npm install canvas-text-colorizer

Use:

To use the drawText function from the "canvas-text-colorizer" package in your Javascript code, follow the example below:

const {
   createCanvas,
   loadImage
} = require('canvas');

const {
   drawText
} = require('canvas-text-colorizer');

const canvas = createCanvas(500, 300);

loadImage('https://avatars.mds.yandex.net/i?id=78ecb61c196a8cdc540c59ae74ec56c0e47e8242-8498042-images-thumbs&n=13').then((image) => {
   const ctx = canvas.getContext('2d');
   ctx.drawImage(image, 0, 0, canvas.width, canvas.height);

   drawText(canvas, '&aText with color\n&r&lBold text\n&r&nUnderlined text\n&r&oItalic text\n&r&mText with ?', 50, 50, 'Arial', 30);

   const fs = require('fs');
   const out = fs.createWriteStream('output.png');
   const stream = canvas.createPNGStream();
   stream.pipe(out);
   out.on('finish', () => console.log('ok'));
});

The first parameter of the function is the canvas on which the text will be drawn. The second parameter is the text to be drawn, with the possibility of defining the color, style and formatting of the letters by means of the code & followed by a letter or number. The third and fourth parameters are the x and y coordinates where the text will be drawn. The fifth parameter is the font that will be used to draw the text and the sixth is the font size.

Output example:

The image generated in the example above would be something like:

[Image

Notices

There may be inaccuracies in the explanation of this readme as I used translation software to write it. In addition, I emphasize that this package was created with the aim of simplifying the use of Canvas, and that, therefore, it may present flaws, which have not been fully tested. If you find bugs, feel free to contact me on Discord. I also take the opportunity to invite suggestions or criticisms to improve the package.

Keywords

FAQs

Last updated on 24 Apr 2023

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc