UNPKG

discord-image-utils

Version:

A powerful library for generating and modifying images with Discord.js - includes meme generation, filters, effects and animations

31 lines 1.16 kB
"use strict"; /** @format */ Object.defineProperty(exports, "__esModule", { value: true }); const canvas_compat_1 = require("./canvas-compat"); /** * Class for generating a solid color image. */ class Color { /** * Creates a new image filled with the specified color. * * @param color - A valid CSS color (e.g. "#FFFFFF", "rgb(255,255,255)") to fill the image with. Defaults to white. * @param width - The width of the image in pixels. Defaults to 480. * @param height - The height of the image in pixels. Defaults to 480. * @returns A Promise resolving with a Buffer containing the generated PNG image. */ async getImage(color = "#FFFFFF", width = 480, height = 480) { try { const canvas = (0, canvas_compat_1.createCanvas)(width, height); const ctx = canvas.getContext("2d"); ctx.fillStyle = color; ctx.fillRect(0, 0, width, height); return canvas.toBuffer("image/png"); } catch (error) { throw new Error(`Failed to generate image: ${error}`); } } } exports.default = Color; //# sourceMappingURL=color.js.map