UNPKG

canvasky

Version:

An easy and powerful image manipulator

42 lines (34 loc) 1.14 kB
const Canvas = require('@napi-rs/canvas'); const chalk = require("chalk"); const formatVariable = (prefix, variable) => { const formattedVariable = variable.toLowerCase() .split("-").map((word) => word.charAt(0).toUpperCase() + word.substr(1, word.length).toLowerCase()).join(""); return prefix + formattedVariable; } module.exports = class RankCard { constructor() { this.username = "Clyde"; this.avatar = `${__dirname}/./assets/img/0.png`; this.backgroundColor = "#000000"; } /** * Set background * @param {string} color The kind of background you want * @returns {RankCard} */ setBackground(color) { this.backgroundColor = color; return this; } /** * Creating the RankCard */ async build() { const canvas = Canvas.createCanvas(800, 200); const ctx = canvas.getContext("2d"); //Creating background color ctx.strokeStyle = this.backgroundColor; ctx.strokeRect(0, 0, 0, 0); return await canvas.toBuffer("image/png"); } }