From 1d6ac1067f49527a60c25b460fa1afaf391a4c83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=A4KayJayDee?= Date: Thu, 5 Jan 2023 16:53:03 +0100 Subject: [PATCH] Denoice + mirror --- README.md | 12 ++++++++++++ package.json | 2 +- src/index.js | 28 +++++++++++----------------- src/module/utils/denoise.js | 16 ++++++++++++++++ src/module/utils/mirror.js | 12 ++++++++++++ 5 files changed, 52 insertions(+), 18 deletions(-) create mode 100644 src/module/utils/denoise.js create mode 100644 src/module/utils/mirror.js diff --git a/README.md b/README.md index 5f28202..0923fda 100644 --- a/README.md +++ b/README.md @@ -352,8 +352,20 @@ bot.login("super_secret_token"); ![Color](https://imgur.com/40tMwfe.png) +- ``new DIG.Denoise().getImage(``, ``);`` + +> Level should be a number + +- ``new DIG.Mirror().getImage(``, ``);`` + +![Mirror](https://imgur.com/oaxbVAC.png) + # Changelog +## v1.4.23 +- Fixed import issue +- Added Denoise() +- Added Mirror() ## v1.4.22 - Fixed some bugs diff --git a/package.json b/package.json index 134de6b..8f79359 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord-image-generation", - "version": "1.4.22", + "version": "1.4.23", "description": "discord-image-generation is a powerful module that allow you to generate awesome images.", "main": "src/index.js", "scripts": { diff --git a/src/index.js b/src/index.js index 30c052d..9f3ffae 100644 --- a/src/index.js +++ b/src/index.js @@ -1,21 +1,15 @@ -const { promisify } = require(`util`); -const fs = require(`fs`); -const path = require(`path`); +const { readdirSync } = require(`fs`); +const { join } = require(`path`); -const readdir = promisify(fs.readdir); - -async function optimize() { - for (let type of (await readdir(path.join(__dirname, `module`))).filter( - f => !f.includes(`.`) - )) { - for (let File of (await readdir(path.join(__dirname, `module`, type))) - .filter(file => file !== `index.js` && file.endsWith(`.js`))) { +for (let type of readdirSync(join(__dirname, `module`)).filter( + f => !f.includes(`.`) +)) { + readdirSync(join(__dirname, `module`, type)) + .filter(file => file !== `index.js` && file.endsWith(`.js`)) + .map(File => { const Name = File.split(`.`)[0]; exports[ Name.charAt(0).toUpperCase() + Name.slice(1) - ] = require(`${__dirname}/module/${type}/${File}`, { lazy: true }); - } - } -} - -optimize(); + ] = require(`${__dirname}/module/${type}/${File}`); + }); +} \ No newline at end of file diff --git a/src/module/utils/denoise.js b/src/module/utils/denoise.js new file mode 100644 index 0000000..158d88d --- /dev/null +++ b/src/module/utils/denoise.js @@ -0,0 +1,16 @@ +const jimp = require(`jimp`); +const { validateURL } = require(`../functions`); +module.exports = class Denoise { + async getImage(image, level = 1) { + if (!image) return console.error(`You must provide an image as a first argument.`); + let isValid = await validateURL(image); + if (!isValid) return console.error(`You must provide a valid image URL or buffer.`); + if (isNaN(level)) level = 1; + if (level > 10) level = 10; + if (level < 1) level = 1; + image = await jimp.read(image); + // apply gaussBlur + image.gaussian(level); + return await image.getBufferAsync(`image/png`); + } +}; \ No newline at end of file diff --git a/src/module/utils/mirror.js b/src/module/utils/mirror.js new file mode 100644 index 0000000..46551a9 --- /dev/null +++ b/src/module/utils/mirror.js @@ -0,0 +1,12 @@ +const jimp = require(`jimp`); +const { validateURL } = require(`../functions`); +module.exports = class Mirror { + async getImage(image, horizontal = true, vertical = false) { + if (!image) return console.error(`You must provide an image as a first argument.`); + let isValid = await validateURL(image); + if (!isValid) return console.error(`You must provide a valid image URL or buffer.`); + image = await jimp.read(image); + image.flip(horizontal, vertical); + return await image.getBufferAsync(`image/png`); + } +}; \ No newline at end of file