UNPKG

@delirius/welcard

Version:

WelCard is a lightweight and futuristic welcome card library designed for WhatsApp Bots.

56 lines (55 loc) 3.01 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createPersonalityCanvas = void 0; const canvas_1 = __importDefault(require("@napi-rs/canvas")); /** * Creates a personalized canvas image with a background, title, name, and profile picture. * * @param backgroundurl - The URL of the background image to use. * @param title - The title text to display on the canvas. * @param name - The name text to display on the canvas. * @param perfil - The URL of the profile picture to include in the canvas. * @returns A promise that resolves to a PNG image buffer of the created canvas. */ function createPersonalityCanvas(backgroundurl = "https://i.pinimg.com/564x/15/7c/84/157c84a0715d04c2a556ab1fdc0ba3d2.jpg", title = "Test de personalidad", name = "Delirius", perfil = "https://i.ibb.co/ZcPLKgK/darlyn-profile-programacion.jpg") { return __awaiter(this, void 0, void 0, function* () { const canvas = canvas_1.default.createCanvas(1018, 468); const ctx = canvas.getContext("2d"); const background = yield canvas_1.default.loadImage(backgroundurl); ctx.drawImage(background, 0, 0, canvas.width, canvas.height); const gradient = ctx.createLinearGradient(0, 0, canvas.width, canvas.height); gradient.addColorStop(0, "red"); gradient.addColorStop(0.5, "orange"); gradient.addColorStop(1, "purple"); ctx.fillStyle = gradient; ctx.font = "70px Arial"; ctx.fillText(title, 199, 64); ctx.font = "40px Arial"; ctx.textAlign = "center"; ctx.fillText(name, 490, 450); const width = 350; const height = 350; const x = (canvas.width - width) / 2; const y = (canvas.height - height) / 2; ctx.beginPath(); ctx.arc(canvas.width / 2, canvas.height / 2, 175, 0, Math.PI * 2, true); ctx.closePath(); ctx.clip(); const avatar = yield canvas_1.default.loadImage(perfil); ctx.drawImage(avatar, x, y, width, height); return canvas.encode("png"); }); } exports.createPersonalityCanvas = createPersonalityCanvas;