UNPKG

discord-image-utils

Version:

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

36 lines 1.28 kB
"use strict"; /** @format */ Object.defineProperty(exports, "__esModule", { value: true }); const jimp_1 = require("jimp"); const utils_1 = require("./utils"); class Circle { /** * Converts an image into a circular shape. * * @param image - The image URL or Buffer to process. * @returns A Promise that resolves with a Buffer containing the processed PNG image. * @throws Will throw an error if the image is invalid or if processing fails. */ async getImage(image) { if (!image) { throw new Error("You must provide an image as the first argument."); } const isValid = await (0, utils_1.validateURL)(image); if (!isValid) { throw new Error("You must provide a valid image URL or buffer."); } try { const jimpImage = await jimp_1.Jimp.read(image); jimpImage.resize({ w: 480, h: 480 }); jimpImage.circle(); // Use the async method to get the Buffer. const buffer = await jimpImage.getBuffer("image/png"); return buffer; } catch (error) { throw new Error(`Failed to process the image: ${error}`); } } } exports.default = Circle; //# sourceMappingURL=circle.js.map