UNPKG

canvafy

Version:

Make configurable canvas easily with Canvafy

20 lines (17 loc) 761 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const { createCanvas, loadImage, GlobalFonts } = require('@napi-rs/canvas'); module.exports = async (template_image) => { let image; try { image = await loadImage(template_image); } catch { throw new Error("The image given in the argument of the gay method is not valid or you are not connected to the internet."); } const background = await loadImage(`${__dirname}/../assets/images/gay.png`); const canvas = await createCanvas(background.width, background.height); const ctx = canvas.getContext("2d"); ctx.drawImage(image, 0, 0, canvas.width, canvas.height); ctx.drawImage(background, 0, 0); return canvas.toBuffer('image/png'); };