UNPKG

text-to-image

Version:

A library for generating an image data URI representing an image containing the text of your choice.

20 lines (19 loc) 810 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const canvas_1 = require("canvas"); exports.default = ({ width, height }) => (canvas, conf) => { if (width <= 0 || height <= 0) { return canvas; } const tailedCanvas = (0, canvas_1.createCanvas)(canvas.width, canvas.height + height); const tailedCtx = tailedCanvas.getContext('2d'); tailedCtx.drawImage(canvas, 0, 0); tailedCtx.beginPath(); tailedCtx.moveTo(tailedCanvas.width / 2 - width / 2, tailedCanvas.height - height); tailedCtx.lineTo(tailedCanvas.width / 2, tailedCanvas.height); tailedCtx.lineTo(tailedCanvas.width / 2 + width / 2, tailedCanvas.height - height); tailedCtx.closePath(); tailedCtx.fillStyle = conf.bgColor; tailedCtx.fill(); return tailedCanvas; };