Denoice + mirror
parent
fbdedebefd
commit
1d6ac1067f
@ -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}`);
|
||||
});
|
||||
}
|
@ -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