Denoice + mirror
parent
fbdedebefd
commit
1d6ac1067f
@ -1,21 +1,15 @@
|
|||||||
const { promisify } = require(`util`);
|
const { readdirSync } = require(`fs`);
|
||||||
const fs = require(`fs`);
|
const { join } = require(`path`);
|
||||||
const path = require(`path`);
|
|
||||||
|
|
||||||
const readdir = promisify(fs.readdir);
|
for (let type of readdirSync(join(__dirname, `module`)).filter(
|
||||||
|
f => !f.includes(`.`)
|
||||||
async function optimize() {
|
)) {
|
||||||
for (let type of (await readdir(path.join(__dirname, `module`))).filter(
|
readdirSync(join(__dirname, `module`, type))
|
||||||
f => !f.includes(`.`)
|
.filter(file => file !== `index.js` && file.endsWith(`.js`))
|
||||||
)) {
|
.map(File => {
|
||||||
for (let File of (await readdir(path.join(__dirname, `module`, type)))
|
|
||||||
.filter(file => file !== `index.js` && file.endsWith(`.js`))) {
|
|
||||||
const Name = File.split(`.`)[0];
|
const Name = File.split(`.`)[0];
|
||||||
exports[
|
exports[
|
||||||
Name.charAt(0).toUpperCase() + Name.slice(1)
|
Name.charAt(0).toUpperCase() + Name.slice(1)
|
||||||
] = require(`${__dirname}/module/${type}/${File}`, { lazy: true });
|
] = require(`${__dirname}/module/${type}/${File}`);
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
optimize();
|
|
@ -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`);
|
||||||
|
}
|
||||||
|
};
|
@ -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`);
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in New Issue