diff --git a/.gitignore b/.gitignore index 4822008..c2f3017 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ node_modules/ package-lock.json -test/ +tests/ pas fait/ .vscode/ \ No newline at end of file diff --git a/README.md b/README.md index 6c2c613..62b9130 100644 --- a/README.md +++ b/README.md @@ -198,10 +198,19 @@ bot.login("super_secret_token") ![Bobross](https://imgur.com/lATDohK.png) +- ``new DIG.Clown().getImage(``);`` + +![Clown](https://imgur.com/qXUAAkb.png) + - ``new DIG.ConfusedStonk().getImage(``);`` ![ConfusedStonk](https://imgur.com/b4UB3BE.png) + +- ``new DIG.Deepfry().getImage(``);`` + +![Deepfry](https://imgur.com/beAiPNv.png) + - ``new DIG.Delete().getImage(``);`` ![Delete](https://imgur.com/6V1IYJp.png) @@ -222,6 +231,10 @@ bot.login("super_secret_token") ![Facepalm](https://imgur.com/cdPC3P1.png) +- ``new DIG.Hearbreaking().getImage(``);`` + +![Hearbreaking](https://imgur.com/P6USTJ3.png) + - ``new DIG.Hitler().getImage(``);`` ![Hitler](https://imgur.com/wK9puxH.png) @@ -244,6 +257,10 @@ bot.login("super_secret_token") > Limited to 300char +- ``new DIG.Mikkelsen().getImage(``);`` + +![Mikkelsen](https://imgur.com/4p71VGS.png) + (Thanks to sιмση ℓεcℓεяε#5765) - ``new DIG.Mms().getImage(``);`` @@ -265,6 +282,10 @@ bot.login("super_secret_token") ![RIP](https://imgur.com/qhyZKfz.png) +- ``new DIG.Snyder().getImage(``);`` + +![Snyder](https://imgur.com/0dFnTcP.png) + - ``new DIG.Spank().getImage(``, ``);`` ![Spank](https://imgur.com/25gq0es.png) @@ -304,10 +325,15 @@ bot.login("super_secret_token") ![Color](https://imgur.com/40tMwfe.png) -# Changelog +# Changelog -## v1.4.8 -- Typings added, thanks to https://github.com/Lioness100 +## v1.4.20 +- Some fixes +- Added Clown() (thanks to Retrojection#1937) +- Added Deepfry() (thanks to Retrojection#1937) +- Added Hearbreaking() (thanks to Retrojection#1937) +- Added Mikkelsen() (thanks to Retrojection#1937) +- Added Snyder() (thanks to Retrojection#1937) ## v1.4.7 - Improved Blink() generation, now supports adding an insane amount of images ^^ diff --git a/package.json b/package.json index 37ba491..3a9df40 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,10 @@ { "name": "discord-image-generation", - "version": "1.4.15", + "version": "1.4.20", "description": "discord-image-generation is a powerful module that allow you to generate awesome images.", "main": "src/index.js", - "types": "typings/index.d.ts", "scripts": { - "test": "node src/index.js" + "test": "node tests/test.js" }, "author": { "name": "Mr¤KayJayDee", @@ -34,6 +33,7 @@ ], "dependencies": { "canvas": "^2.10.1", + "discord.js": "^14.7.1", "gifencoder": "^2.0.1", "jimp": "^0.16.0" }, diff --git a/src/assets/clown.png b/src/assets/clown.png new file mode 100644 index 0000000..ed779e6 Binary files /dev/null and b/src/assets/clown.png differ diff --git a/src/assets/heartbreaking.png b/src/assets/heartbreaking.png new file mode 100644 index 0000000..83e1a5a Binary files /dev/null and b/src/assets/heartbreaking.png differ diff --git a/src/assets/mikkelsen.png b/src/assets/mikkelsen.png new file mode 100644 index 0000000..6316f00 Binary files /dev/null and b/src/assets/mikkelsen.png differ diff --git a/src/assets/snyder.png b/src/assets/snyder.png new file mode 100644 index 0000000..2d190fe Binary files /dev/null and b/src/assets/snyder.png differ diff --git a/src/index.js b/src/index.js index de4940f..30c052d 100644 --- a/src/index.js +++ b/src/index.js @@ -1,15 +1,21 @@ -const { readdirSync } = require(`fs`); -const { join } = require(`path`); +const { promisify } = require(`util`); +const fs = require(`fs`); +const path = require(`path`); -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 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`))) { const Name = File.split(`.`)[0]; exports[ Name.charAt(0).toUpperCase() + Name.slice(1) - ] = require(`${__dirname}/module/${type}/${File}`); - }); + ] = require(`${__dirname}/module/${type}/${File}`, { lazy: true }); + } + } } + +optimize(); diff --git a/src/module/filters/blur.js b/src/module/filters/blur.js index caba99c..389f326 100644 --- a/src/module/filters/blur.js +++ b/src/module/filters/blur.js @@ -1,19 +1,12 @@ const jimp = require(`jimp`); - +const { validateURL } = require(`../functions`); module.exports = class Blur { - /** - * Blur - * @param {image} image - * @param {level} level - */ async getImage(image, level) { - if (!image) throw new Error(`You must provide an image as a first argument.`); + 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.blur(isNaN(level) ? 5 : parseInt(level)); - let raw; - image.getBuffer(`image/png`, (err, buffer) => { - raw = buffer; - }); - return raw; + return await image.getBufferAsync(`image/png`); } }; \ No newline at end of file diff --git a/src/module/filters/gay.js b/src/module/filters/gay.js index 800dbd6..d604974 100644 --- a/src/module/filters/gay.js +++ b/src/module/filters/gay.js @@ -1,12 +1,11 @@ const Canvas = require(`canvas`); +const { validateURL } = require(`../functions`); module.exports = class Gay { - /** - * Gay - * @param {image} image - */ async getImage(image) { - if (!image) throw new Error(`You must provide an image as a first argument.`); + 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.`); let bg = await Canvas.loadImage(`${__dirname}/../../assets/gay.png`); let img = await Canvas.loadImage(image); const canvas = Canvas.createCanvas(480, 480); diff --git a/src/module/filters/greyscale.js b/src/module/filters/greyscale.js index 90b974a..2d3027e 100644 --- a/src/module/filters/greyscale.js +++ b/src/module/filters/greyscale.js @@ -1,18 +1,12 @@ const jimp = require(`jimp`); - +const { validateURL } = require(`../functions`); module.exports = class Geryscale { - /** - * Greyscale - * @param {image} image - */ async getImage(image) { - if (!image) throw new Error(`You must provide an image as a first argument.`); + 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.greyscale(); - let raw; - image.getBuffer(`image/png`, (err, buffer) => { - raw = buffer; - }); - return raw; + return await image.getBufferAsync(`image/png`); } }; \ No newline at end of file diff --git a/src/module/filters/invert.js b/src/module/filters/invert.js index e602f41..2a02855 100644 --- a/src/module/filters/invert.js +++ b/src/module/filters/invert.js @@ -1,18 +1,12 @@ const jimp = require(`jimp`); - +const { validateURL } = require(`../functions`); module.exports = class Invert { - /** - * Invert - * @param {image} image - */ async getImage(image) { - if (!image) throw new Error(`You must provide an image as a first argument.`); + 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.invert(); - let raw; - image.getBuffer(`image/png`, (err, buffer) => { - raw = buffer; - }); - return raw; + return await image.getBufferAsync(`image/png`); } }; \ No newline at end of file diff --git a/src/module/filters/sepia.js b/src/module/filters/sepia.js index 431e032..2576c92 100644 --- a/src/module/filters/sepia.js +++ b/src/module/filters/sepia.js @@ -1,18 +1,12 @@ const jimp = require(`jimp`); - +const { validateURL } = require(`../functions`); module.exports = class Sepia { - /** - * Sepia - * @param {image} image - */ async getImage(image) { - if (!image) throw new Error(`You must provide an image as a first argument.`); + 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.sepia(); - let raw; - image.getBuffer(`image/png`, (err, buffer) => { - raw = buffer; - }); - return raw; + return await image.getBufferAsync(`image/png`); } }; \ No newline at end of file diff --git a/src/module/functions.js b/src/module/functions.js index 39e18c0..21138e6 100644 --- a/src/module/functions.js +++ b/src/module/functions.js @@ -1,3 +1,5 @@ +const https = require(`https`); + module.exports = { /** * Crate a responsive on the text @@ -47,5 +49,38 @@ module.exports = { } return resolve(lines); }); + }, + + async validateURL(url) { + if (!url) return null; + if (Buffer.isBuffer(url)) { + return url; + } + try { + // if url is not https + if (!url.startsWith(`https`)) { + return console.error(`The url must be https`); + return null; + } + return new Promise((resolve, reject) => { + https.get(url, (response) => { + if (response.statusCode !== 200) { + return console.error(`Invalid status code ${response.statusCode}`); + return; + } + const type = response.headers['content-type']; + if (!type.startsWith('image/')) { + return console.error(`Invalid content type ${type}`); + return; + } + const chunks = []; + response.on('data', (chunk) => chunks.push(chunk)); + response.on('end', () => resolve(Buffer.concat(chunks))); + }); + }); + } catch (error) { + return console.error(error); + return null; + } } }; \ No newline at end of file diff --git a/src/module/gif/blink.js b/src/module/gif/blink.js index 140fa64..976b639 100644 --- a/src/module/gif/blink.js +++ b/src/module/gif/blink.js @@ -1,16 +1,21 @@ const Canvas = require(`canvas`); const GIFEncoder = require(`gifencoder`); - +const { validateURL } = require(`../functions`); module.exports = class Blink { async getImage(delay, ...images) { - if (!images || images.length < 2) throw new Error(`You must provide at least two images.`); - + if (!images || images.length < 2) return console.error(`You must provide at least two images.`); + + for (const image of images) { + let isValid = await validateURL(image); + if (!isValid) return console.error(`You must provide a valid image URL or buffer.`); + } + const GIF = new GIFEncoder(480, 480); GIF.start(); GIF.setRepeat(0); GIF.setDelay(delay); GIF.setTransparent(); - + const canvas = Canvas.createCanvas(480, 480); for (const image of images) { @@ -20,7 +25,7 @@ module.exports = class Blink { ctx2.drawImage(base, 0, 0, 480, 480); GIF.addFrame(ctx2); } - + GIF.finish(); return GIF.out.getData(); } diff --git a/src/module/gif/triggered.js b/src/module/gif/triggered.js index 39a09d9..d7943cc 100644 --- a/src/module/gif/triggered.js +++ b/src/module/gif/triggered.js @@ -1,16 +1,13 @@ const Canvas = require(`canvas`); const GIFEncoder = require(`gifencoder`); - +const { validateURL } = require(`../functions`); module.exports = class Triggered { - /** - * Triggered - * @param {image} image - * @param {number} timeout - */ async getImage(image, timeout = 15) { - if (!image) throw new Error(`You must provide an image as a first argument.`); - if (isNaN(timeout)) throw new Error(`The timeout argument must be a number.`); + 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(timeout)) return console.error(`The timeout argument must be a number.`); const base = await Canvas.loadImage(`${__dirname}/../../assets/triggered.png`); const img = await Canvas.loadImage(image); const GIF = new GIFEncoder(256, 310); diff --git a/src/module/montage/ad.js b/src/module/montage/ad.js index 5db0930..b8d1da0 100644 --- a/src/module/montage/ad.js +++ b/src/module/montage/ad.js @@ -1,18 +1,14 @@ -const Canvas = require(`canvas`); - +const Jimp = require('jimp'); +const { validateURL } = require(`../functions`); module.exports = class Ad { - /** - * Ad - * @param {image} image1 - */ async getImage(image1) { - if (!image1) throw new Error(`You must provide an image as an argument`); - const canvas = Canvas.createCanvas(550, 474); - const ctx = canvas.getContext(`2d`); - image1 = await Canvas.loadImage(image1); - const background = await Canvas.loadImage(`${__dirname}/../../assets/ad.png`); - ctx.drawImage(image1, 150, 75, 230, 230); - ctx.drawImage(background, 0, 0, 550, 474); - return canvas.toBuffer(); + if (!image1) return console.error(`You must provide an image as an argument`); + let isValid = await validateURL(image1); + if (!isValid) return console.error(`You must provide a valid image URL or buffer.`); + const image1Buffer = await Jimp.read(image1); + image1Buffer.resize(230, 230); + const background = await Jimp.read(`${__dirname}/../../assets/ad.png`); + background.composite(image1Buffer, 150, 75); + return background.getBufferAsync(Jimp.MIME_PNG); } }; diff --git a/src/module/montage/affect.js b/src/module/montage/affect.js index 3622746..ab44e46 100644 --- a/src/module/montage/affect.js +++ b/src/module/montage/affect.js @@ -1,20 +1,14 @@ const jimp = require(`jimp`); - +const { validateURL } = require(`../functions`); module.exports = class Affect { - /** - * Affect - * @param {image} image - */ async getImage(image) { - if (!image) throw new Error(`You must provide an image as a first argument.`); + 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.`); let base = await jimp.read(`${__dirname}/../../assets/affect.png`); let img = await jimp.read(image); img.resize(200, 157); base.composite(img, 180, 383); - let raw; - base.getBuffer(`image/png`, (err, buffer) => { - raw = buffer; - }); - return raw; + return await base.getBufferAsync(`image/png`); } }; \ No newline at end of file diff --git a/src/module/montage/batslap.js b/src/module/montage/batslap.js index 6482ee5..6e5d445 100644 --- a/src/module/montage/batslap.js +++ b/src/module/montage/batslap.js @@ -1,14 +1,13 @@ const jimp = require(`jimp`); - +const { validateURL } = require(`../functions`); module.exports = class Batslap { - /** - * Batslap - * @param {image} image1 - * @param {image} image2 - */ async getImage(image1, image2) { - if (!image1) throw new Error(`You must provide an image as a first argument.`); - if (!image2) throw new Error(`You must provide an image as a second argument.`); + if (!image1) return console.error(`You must provide an image as a first argument.`); + let isValid1 = await validateURL(image1); + if (!isValid1) return console.error(`You must provide a valid image URL or buffer.`); + if (!image2) return console.error(`You must provide an image as a second argument.`); + let isValid2 = await validateURL(image1); + if (!isValid2) return console.error(`You must provide a valid image URL or buffer.`); let base = await jimp.read(`${__dirname}/../../assets/batslap.png`); image1 = await jimp.read(image1); image2 = await jimp.read(image2); @@ -19,10 +18,6 @@ module.exports = class Batslap { image2.resize(200, 200); base.composite(image2, 580, 260); base.composite(image1, 350, 70); - let raw; - base.getBuffer(`image/png`, (err, buffer) => { - raw = buffer; - }); - return raw; + return await base.getBufferAsync(`image/png`); } }; \ No newline at end of file diff --git a/src/module/montage/beautiful.js b/src/module/montage/beautiful.js index a2ed674..3f4cdab 100644 --- a/src/module/montage/beautiful.js +++ b/src/module/montage/beautiful.js @@ -1,22 +1,16 @@ const jimp = require(`jimp`); - +const { validateURL } = require(`../functions`); module.exports = class Beautiful { - /** - * Beautiful - * @param {image} image - */ async getImage(image) { - if (!image) throw new Error(`You must provide an image as a first argument.`); + 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.`); let base = await jimp.read(`${__dirname}/../../assets/beautiful.png`); base.resize(376, 400); let img = await jimp.read(image); img.resize(84, 95); base.composite(img, 258, 28); base.composite(img, 258, 229); - let raw; - base.getBuffer(`image/png`, (err, buffer) => { - raw = buffer; - }); - return raw; + return await base.getBufferAsync(`image/png`); } }; \ No newline at end of file diff --git a/src/module/montage/bed.js b/src/module/montage/bed.js index 08e360c..d2e7494 100644 --- a/src/module/montage/bed.js +++ b/src/module/montage/bed.js @@ -1,14 +1,13 @@ const jimp = require(`jimp`); - +const { validateURL } = require(`../functions`); module.exports = class Bed { - /** - * Bed - * @param {image} image1 - * @param {image} image2 - */ async getImage(image1, image2) { - if (!image1) throw new Error(`You must provide an image as a first argument.`); - if (!image2) throw new Error(`You must provide an image as a second argument.`); + if (!image1) return console.error(`You must provide an image as a first argument.`); + let isValid1 = await validateURL(image1); + if (!isValid1) return console.error(`You must provide a valid image URL or buffer.`); + if (!image2) return console.error(`You must provide an image as a second argument.`); + let isValid2 = await validateURL(image2); + if (!isValid2) return console.error(`You must provide a valid image URL or buffer.`); let bg = await jimp.read(`${__dirname}/../../assets/bed.png`); image1 = await jimp.read(image1); image2 = await jimp.read(image2); @@ -21,10 +20,6 @@ module.exports = class Bed { bg.composite(image1, 25, 300); bg.composite(image3, 53, 450); bg.composite(image2, 53, 575); - let raw; - bg.getBuffer(`image/png`, (err, buffer) => { - raw = buffer; - }); - return raw; + return await bg.getBufferAsync(`image/png`); } }; \ No newline at end of file diff --git a/src/module/montage/bobross.js b/src/module/montage/bobross.js index f059810..3d4c5ff 100644 --- a/src/module/montage/bobross.js +++ b/src/module/montage/bobross.js @@ -1,20 +1,16 @@ -const { createCanvas, loadImage } = require(`canvas`); - +const Jimp = require('jimp'); +const { validateURL } = require(`../functions`); module.exports = class Bobross { - /** - * Bobross - * @param {image} image1 - */ - async getImage(image1) { - if (!image1) throw new Error(`You must provide an image as an argument`); - const base = await loadImage(`${__dirname}/../../assets/bobross.png`); - const canvas = createCanvas(base.width, base.height); - const ctx = canvas.getContext(`2d`); - image1 = await loadImage(image1); - ctx.fillStyle = `white`; - ctx.fillRect(0, 0, base.width, base.height); - ctx.drawImage(image1, 15, 20, 440, 440); - ctx.drawImage(base, 0, 0); - return canvas.toBuffer(); - } + async getImage(image1) { + if (!image1) return console.error(`You must provide an image as an argument`); + let isValid = await validateURL(image1); + if (!isValid) return console.error(`You must provide a valid image URL or buffer.`); + const base = await Jimp.read(`${__dirname}/../../assets/bobross.png`); + const image1Buffer = await Jimp.read(image1); + image1Buffer.resize(440, 440); + const compositeImage = new Jimp(base.getWidth(), base.getHeight(), 0xFFFFFFFF); + compositeImage.composite(image1Buffer, 15, 20); + compositeImage.composite(base, 0, 0); + return compositeImage.getBufferAsync(Jimp.MIME_PNG); + } }; diff --git a/src/module/montage/clown.js b/src/module/montage/clown.js new file mode 100644 index 0000000..d187fd2 --- /dev/null +++ b/src/module/montage/clown.js @@ -0,0 +1,28 @@ +const Canvas = require(`canvas`); +const { validateURL } = require(`../functions`); + +module.exports = class Clown { + async getImage(image) { + + function drawImage(ctx, image, x, y, w, h, degrees) { + ctx.save(); + ctx.translate(x + w / 2, y + h / 2); + ctx.rotate(degrees * Math.PI / 180.0); + ctx.translate(-x - w / 2, -y - h / 2); + ctx.drawImage(image, x, y, w, h); + ctx.restore(); + } + + if (!image) throw new Error(`You must provide an image as an argument`); + let isValid = await validateURL(img1); + if (!isValid) return console.error(`You must provide a valid image URL or buffer.`); + const canvas = Canvas.createCanvas(610, 343); + const ctx = canvas.getContext(`2d`); + image = await Canvas.loadImage(image); + const background = await Canvas.loadImage(`${__dirname}/../../assets/clown.png`); + ctx.fillRect(0, 0, 610, 343); + drawImage(ctx, image, 15, 55, 145, 130, -5); + ctx.drawImage(background, 0, 0, 610, 343); + return canvas.toBuffer(); + } +} \ No newline at end of file diff --git a/src/module/montage/confusedStonk.js b/src/module/montage/confusedStonk.js index 22e2d16..545c2a2 100644 --- a/src/module/montage/confusedStonk.js +++ b/src/module/montage/confusedStonk.js @@ -1,18 +1,16 @@ -const Canvas = require(`canvas`); - +const Jimp = require('jimp'); +const { validateURL } = require(`../functions`); module.exports = class ConfusedStonk { - /** - * ConfusedStonk - * @param {image} image1 - */ - async getImage(image1) { - if (!image1) throw new Error(`You must provide an image as an argument`); - const canvas = Canvas.createCanvas(1994, 1296); - const ctx = canvas.getContext(`2d`); - image1 = await Canvas.loadImage(image1); - const background = await Canvas.loadImage(`${__dirname}/../../assets/confusedStonk.png`); - ctx.drawImage(image1, 190, 70, 400, 400); - ctx.drawImage(background, 0, 0, 1994, 1296); - return canvas.toBuffer(); + async getImage(img1) { + if (!img1) return console.error(`You must provide an image as an argument`); + let isValid = await validateURL(img1); + if (!isValid) return console.error(`You must provide a valid image URL or buffer.`); + const image1 = await Jimp.read(img1); + const background = await Jimp.read(`${__dirname}/../../assets/confusedStonk.png`); + image1.resize(400, 400); + const compositeImage = new Jimp(background.getWidth(), background.getHeight(), 0xFFFFFFFF); + compositeImage.composite(image1, 190, 70); + compositeImage.composite(background, 0, 0); + return await compositeImage.getBufferAsync(Jimp.MIME_PNG); } }; diff --git a/src/module/montage/deepfry.js b/src/module/montage/deepfry.js new file mode 100644 index 0000000..a45c58b --- /dev/null +++ b/src/module/montage/deepfry.js @@ -0,0 +1,17 @@ +const jimp = require(`jimp`); +const { validateURL } = require(`../functions`); + +module.exports = class Deepfry { + async getImage(image) { + if (!image) throw new Error(`You must provide an image as a first argument.`); + let isValid = await validateURL(img1); + if (!isValid) return console.error(`You must provide a valid image URL or buffer.`); + image = await jimp.read(image); + image.resize(500, 500); + image.quality(2) + image.contrast(1); + image.pixelate(2); + image.posterize(10); + return await image.getBufferAsync(`image/png`); + } +}; \ No newline at end of file diff --git a/src/module/montage/delete.js b/src/module/montage/delete.js index 40a8ae3..fad3ae8 100644 --- a/src/module/montage/delete.js +++ b/src/module/montage/delete.js @@ -1,20 +1,14 @@ const jimp = require(`jimp`); - +const { validateURL } = require(`../functions`); module.exports = class Delete { - /** - * Delete - * @param {image} image - */ async getImage(image) { - if (!image) throw new Error(`You must provide an image as a first argument.`); - let bg = await jimp.read(`${__dirname}/../../assets/delete.png`); + 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.`); + const background = await jimp.read(`${__dirname}/../../assets/delete.png`); image = await jimp.read(image); image.resize(195, 195); - bg.composite(image, 120, 135); - let raw; - bg.getBuffer(`image/png`, (err, buffer) => { - raw = buffer; - }); - return raw; + background.composite(image, 120, 135); + return await background.getBufferAsync(`image/png`); } }; \ No newline at end of file diff --git a/src/module/montage/discordBlack.js b/src/module/montage/discordBlack.js index 1208d33..c1023d5 100644 --- a/src/module/montage/discordBlack.js +++ b/src/module/montage/discordBlack.js @@ -1,18 +1,16 @@ -const Canvas = require(`canvas`); - +const Jimp = require('jimp'); +const { validateURL } = require(`../functions`); module.exports = class DiscordBlack { - /** - * Bobross - * @param {image} image1 - */ - async getImage(image1) { - if (!image1) throw new Error(`You must provide an image as an argument`); - const canvas = Canvas.createCanvas(610, 610); - const ctx = canvas.getContext(`2d`); - image1 = await Canvas.loadImage(image1); - const background = await Canvas.loadImage(`${__dirname}/../../assets/discordblack.png`); - ctx.drawImage(image1, 0, 0, 610, 610); - ctx.drawImage(background, 0, 0, 610, 610); - return canvas.toBuffer(); + async getImage(img1) { + if (!img1) return console.error(`You must provide an image as an argument`); + let isValid = await validateURL(img1); + if (!isValid) return console.error(`You must provide a valid image URL or buffer.`); + const background = await Jimp.read(`${__dirname}/../../assets/discordblack.png`); + const image1 = await Jimp.read(img1); + image1.resize(background.getWidth(), background.getHeight()); + const compositeImage = new Jimp(background.getWidth(), background.getHeight(), 0xFFFFFFFF); + compositeImage.composite(image1, 0, 0); + compositeImage.composite(background, 0, 0); + return await compositeImage.getBufferAsync(Jimp.MIME_PNG); } }; diff --git a/src/module/montage/discordBlue.js b/src/module/montage/discordBlue.js index c7ec0bb..1ce105a 100644 --- a/src/module/montage/discordBlue.js +++ b/src/module/montage/discordBlue.js @@ -1,18 +1,16 @@ -const Canvas = require(`canvas`); - +const Jimp = require('jimp'); +const { validateURL } = require(`../functions`); module.exports = class DiscordBlue { - /** - * Bobross - * @param {image} image1 - */ - async getImage(image1) { - if (!image1) throw new Error(`You must provide an image as an argument`); - const canvas = Canvas.createCanvas(610, 610); - const ctx = canvas.getContext(`2d`); - image1 = await Canvas.loadImage(image1); - const background = await Canvas.loadImage(`${__dirname}/../../assets/discordblue.png`); - ctx.drawImage(image1, 0, 0, 610, 610); - ctx.drawImage(background, 0, 0, 610, 610); - return canvas.toBuffer(); + async getImage(img1) { + if (!img1) return console.error(`You must provide an image as an argument`); + let isValid = await validateURL(img1); + if (!isValid) return console.error(`You must provide a valid image URL or buffer.`); + const background = await Jimp.read(`${__dirname}/../../assets/discordblue.png`); + const image1 = await Jimp.read(img1); + image1.resize(background.getWidth(), background.getHeight()); + const compositeImage = new Jimp(background.getWidth(), background.getHeight(), 0xFFFFFFFF); + compositeImage.composite(image1, 0, 0); + compositeImage.composite(background, 0, 0); + return await compositeImage.getBufferAsync(Jimp.MIME_PNG); } }; diff --git a/src/module/montage/doubleStonk.js b/src/module/montage/doubleStonk.js index e064a51..12e8e73 100644 --- a/src/module/montage/doubleStonk.js +++ b/src/module/montage/doubleStonk.js @@ -1,14 +1,13 @@ const jimp = require(`jimp`); - +const { validateURL } = require(`../functions`); module.exports = class DoubleStonk { - /** - * DoubleStonk - * @param {image} image1 - * @param {image} image2 - */ async getImage(image1, image2) { - if (!image1) throw new Error(`You must provide an image as a first argument.`); - if (!image2) throw new Error(`You must provide an image as a second argument.`); + if (!image1) return console.error(`You must provide an image as a first argument.`); + let isValid1 = await validateURL(image1); + if (!isValid1) return console.error(`You must provide a valid image URL or buffer.`); + if (!image2) return console.error(`You must provide an image as a second argument.`); + let isValid2 = await validateURL(image2); + if (!isValid2) return console.error(`You must provide a valid image URL or buffer.`); let base = await jimp.read(`${__dirname}/../../assets/doubleStonk.png`); image1 = await jimp.read(image1); image2 = await jimp.read(image2); @@ -19,10 +18,6 @@ module.exports = class DoubleStonk { image2.resize(140, 140); base.composite(image2, 60, 20); base.composite(image1, 0, 30); - let raw; - base.getBuffer(`image/png`, (err, buffer) => { - raw = buffer; - }); - return raw; + return await base.getBufferAsync(`image/png`); } }; \ No newline at end of file diff --git a/src/module/montage/facepalm.js b/src/module/montage/facepalm.js index 96c3d3e..cd114dc 100644 --- a/src/module/montage/facepalm.js +++ b/src/module/montage/facepalm.js @@ -1,20 +1,16 @@ -const Canvas = require(`canvas`); - +const Jimp = require('jimp'); +const { validateURL } = require(`../functions`); module.exports = class Facepalm { - /** - * Facepalm - * @param {image} image - */ async getImage(image) { - if (!image) throw new Error(`You must provide an image as a first argument.`); - let canvas = Canvas.createCanvas(632, 357); - let ctx = canvas.getContext(`2d`); - ctx.fillStyle = `black`; - ctx.fillRect(0, 0, 632, 357); - let avatar = await Canvas.loadImage(image); - ctx.drawImage(avatar, 199, 112, 235, 235); - let layer = await Canvas.loadImage(`${__dirname}/../../assets/facepalm.png`); - ctx.drawImage(layer, 0, 0, 632, 357); - return canvas.toBuffer(); + if (!image) return console.error(`You must provide an image as an argument.`); + let isValid = await validateURL(image); + if (!isValid) return console.error(`You must provide a valid image URL or buffer.`); + const layer = await Jimp.read(`${__dirname}/../../assets/facepalm.png`); + const avatar = await Jimp.read(image); + const compositeImage = new Jimp(layer.getWidth(), layer.getHeight(), 0xFFFFFFFF); + avatar.resize(235, 235); + compositeImage.composite(avatar, 199, 112); + compositeImage.composite(layer, 0, 0); + return await compositeImage.getBufferAsync(Jimp.MIME_PNG); } -}; \ No newline at end of file +}; diff --git a/src/module/montage/heartbreaking.js b/src/module/montage/heartbreaking.js new file mode 100644 index 0000000..632810b --- /dev/null +++ b/src/module/montage/heartbreaking.js @@ -0,0 +1,17 @@ +const Canvas = require(`canvas`); +const { validateURL } = require(`../functions`); + +module.exports = class Heartbreaking { + async getImage(image) { + if (!image) throw new Error(`You must provide an image as an argument`); + let isValid = await validateURL(img1); + if (!isValid) return console.error(`You must provide a valid image URL or buffer.`); + const canvas = Canvas.createCanvas(610, 797); + const ctx = canvas.getContext(`2d`); + image = await Canvas.loadImage(image); + const background = await Canvas.loadImage(`${__dirname}/../../assets/heartbreaking.png`); + ctx.drawImage(image, 0, 150, 610, 610); + ctx.drawImage(background, 0, 0, 610, 797); + return canvas.toBuffer(); + } +}; \ No newline at end of file diff --git a/src/module/montage/hitler.js b/src/module/montage/hitler.js index 7912033..a30c28d 100644 --- a/src/module/montage/hitler.js +++ b/src/module/montage/hitler.js @@ -1,20 +1,14 @@ const jimp = require(`jimp`); - +const { validateURL } = require(`../functions`); module.exports = class Hitler { - /** - * Hitler - * @param {image} image - */ async getImage(image) { - if (!image) throw new Error(`You must provide an image as a first argument.`); + 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.`); let bg = await jimp.read(`${__dirname}/../../assets/hitler.png`); let img = await jimp.read(image); img.resize(140, 140); bg.composite(img, 46, 43); - let raw; - bg.getBuffer(`image/png`, (err, buffer) => { - raw = buffer; - }); - return raw; + return await bg.getBufferAsync(`image/png`); } }; \ No newline at end of file diff --git a/src/module/montage/jail.js b/src/module/montage/jail.js index 269b91e..fbe8bac 100644 --- a/src/module/montage/jail.js +++ b/src/module/montage/jail.js @@ -1,18 +1,17 @@ -const Canvas = require(`canvas`); - +const Jimp = require('jimp'); +const { validateURL } = require(`../functions`); module.exports = class Jail { - /** - * Jail - * @param {image} image - */ async getImage(image) { - if (!image) throw new Error(`You must provide an image as a first argument.`); - let bg = await Canvas.loadImage(`${__dirname}/../../assets/jail.png`); - let img = await Canvas.loadImage(image); - const canvas = Canvas.createCanvas(400, 400); - const ctx = canvas.getContext(`2d`); - ctx.drawImage(img, 0, 0, 400, 400); - ctx.drawImage(bg, 0, 0, 400, 400); - return canvas.toBuffer(); + 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.`); + let bg = await Jimp.read(`${__dirname}/../../assets/jail.png`); + let img = await Jimp.read(image); + const compositeImage = new Jimp(400, 400, 0xFFFFFFFF); + img.resize(400, 400); + bg.resize(400, 400); + compositeImage.composite(img, 0, 0); + compositeImage.composite(bg, 0, 0); + return await compositeImage.getBufferAsync(Jimp.MIME_PNG); } }; \ No newline at end of file diff --git a/src/module/montage/karaba.js b/src/module/montage/karaba.js index 2a213db..e7696c0 100644 --- a/src/module/montage/karaba.js +++ b/src/module/montage/karaba.js @@ -1,18 +1,17 @@ -const Canvas = require(`canvas`); - -module.exports = class Mms { - /** - * MMS - * @param {image} image - */ +const Jimp = require('jimp'); +const { validateURL } = require(`../functions`); +module.exports = class Karaba { async getImage(image) { - if (!image) throw new Error(`You must provide an image as an argument`); - let bg = await Canvas.loadImage(`${__dirname}/../../assets/karaba.png`); - let img = await Canvas.loadImage(image); - const canvas = Canvas.createCanvas(bg.width, bg.height); - const ctx = canvas.getContext(`2d`); - ctx.drawImage(img, 130, 44, 130, 130); - ctx.drawImage(bg, 0, 0, bg.width, bg.height); - return canvas.toBuffer(); + if (!image) return console.error(`You must provide an image as an argument`); + let isValid = await validateURL(image); + if (!isValid) return console.error(`You must provide a valid image URL or buffer.`); + let bg = await Jimp.read(`${__dirname}/../../assets/karaba.png`); + let img = await Jimp.read(image); + const compositeImage = new Jimp(bg.getWidth(), bg.getHeight(), 0xFFFFFFFF); + img.resize(130, 130); + bg.resize(bg.getWidth(), bg.getHeight()); + compositeImage.composite(img, 130, 44); + compositeImage.composite(bg, 0, 0); + return await compositeImage.getBufferAsync(Jimp.MIME_PNG); } }; diff --git a/src/module/montage/kiss.js b/src/module/montage/kiss.js index f76ae2a..a9adc34 100644 --- a/src/module/montage/kiss.js +++ b/src/module/montage/kiss.js @@ -1,14 +1,13 @@ const jimp = require(`jimp`); - +const { validateURL } = require(`../functions`); module.exports = class Kiss { - /** - * Kiss - * @param {image} image1 - * @param {image} image2 - */ async getImage(image1, image2) { - if (!image1) throw new Error(`You must provide an image as a first argument.`); - if (!image2) throw new Error(`You must provide an image as a second argument.`); + if (!image1) return console.error(`You must provide an image as a first argument.`); + let isValid1 = await validateURL(image1); + if (!isValid1) return console.error(`You must provide a valid image URL or buffer.`); + if (!image2) return console.error(`You must provide an image as a second argument.`); + let isValid2 = await validateURL(image2); + if (!isValid2) return console.error(`You must provide a valid image URL or buffer.`); let base = await jimp.read(`${__dirname}/../../assets/kiss.png`); image1 = await jimp.read(image1); image2 = await jimp.read(image2); @@ -19,10 +18,6 @@ module.exports = class Kiss { image2.resize(200, 200); base.composite(image1, 150, 25); base.composite(image2, 350, 25); - let raw; - base.getBuffer(`image/png`, (err, buffer) => { - raw = buffer; - }); - return raw; + return await base.getBufferAsync(`image/png`); } }; \ No newline at end of file diff --git a/src/module/montage/lisaPresentation.js b/src/module/montage/lisaPresentation.js index e311bd1..6c8d427 100644 --- a/src/module/montage/lisaPresentation.js +++ b/src/module/montage/lisaPresentation.js @@ -5,10 +5,8 @@ const path = require(`path`); const { wrapText } = require(`../functions`); module.exports = class LisaPresentation { - async getImage(text) { - if (!text || text.length > 300) throw new Error(`You must provide a text of 300 characters or less.`); - + if (!text || text.length > 300) return console.error(`You must provide a text of 300 characters or less.`); const base = await loadImage(path.join(`${__dirname}/../../assets/lisa-presentation.png`)); const canvas = createCanvas(base.width, base.height); const ctx = canvas.getContext(`2d`); @@ -27,8 +25,6 @@ module.exports = class LisaPresentation { const height = topMost + ((fontSize + 20) * i); ctx.fillText(lines[i], base.width / 2, height); } - return canvas.toBuffer(); } - }; \ No newline at end of file diff --git a/src/module/montage/mikkelsen.js b/src/module/montage/mikkelsen.js new file mode 100644 index 0000000..1631c2c --- /dev/null +++ b/src/module/montage/mikkelsen.js @@ -0,0 +1,17 @@ +const Canvas = require(`canvas`); +const { validateURL } = require(`../functions`); + +module.exports = class Mikkelsen { + async getImage(image) { + if (!image) throw new Error(`You must provide an image as an argument`); + let isValid = await validateURL(img1); + if (!isValid) return console.error(`You must provide a valid image URL or buffer.`); + const canvas = Canvas.createCanvas(610, 955); + const ctx = canvas.getContext(`2d`); + image = await Canvas.loadImage(image); + const background = await Canvas.loadImage(`${__dirname}/../../assets/mikkelsen.png`); + ctx.drawImage(image, 20, 460, 580, 580); + ctx.drawImage(background, 0, 0, 610, 955); + return canvas.toBuffer(); + } +}; \ No newline at end of file diff --git a/src/module/montage/mms.js b/src/module/montage/mms.js index 4fd00fe..2adcb47 100644 --- a/src/module/montage/mms.js +++ b/src/module/montage/mms.js @@ -1,18 +1,17 @@ -const Canvas = require(`canvas`); - +const Jimp = require(`jimp`); +const { validateURL } = require(`../functions`); module.exports = class Mms { - /** - * MMS - * @param {image} image - */ async getImage(image) { - if (!image) throw new Error(`You must provide an image as a first argument.`); - let bg = await Canvas.loadImage(`${__dirname}/../../assets/mms.png`); - let img = await Canvas.loadImage(image); - const canvas = Canvas.createCanvas(400, 400); - const ctx = canvas.getContext(`2d`); - ctx.drawImage(img, 60, 10, 270, 270); - ctx.drawImage(bg, 0, 0, 400, 400); - return canvas.toBuffer(); + 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.`); + const bg = await Jimp.read(`${__dirname}/../../assets/mms.png`); + const img = await Jimp.read(image); + const canvas = new Jimp(400, 400); + bg.resize(400, 400); + img.resize(270, 270); + canvas.composite(img, 60, 10); + canvas.composite(bg, 0, 0); + return canvas.getBufferAsync(Jimp.MIME_PNG); } -}; \ No newline at end of file +}; diff --git a/src/module/montage/notStonk.js b/src/module/montage/notStonk.js index da008fa..6d5949c 100644 --- a/src/module/montage/notStonk.js +++ b/src/module/montage/notStonk.js @@ -1,18 +1,17 @@ -const Canvas = require(`canvas`); - +const Jimp = require(`jimp`); +const { validateURL } = require(`../functions`); module.exports = class NotStonk { - /** - * NotStonk - * @param {image} image1 - */ - async getImage(image1) { - if (!image1) throw new Error(`You must provide an image as an argument`); - const canvas = Canvas.createCanvas(960, 576); - const ctx = canvas.getContext(`2d`); - image1 = await Canvas.loadImage(image1); - const background = await Canvas.loadImage(`${__dirname}/../../assets/notStonk.png`); - ctx.drawImage(image1, 140, 5, 190, 190); - ctx.drawImage(background, 0, 0, 960, 576); - return canvas.toBuffer(); + async getImage(image) { + if (!image) return console.error(`You must provide an image as an argument`); + let isValid = await validateURL(image); + if (!isValid) return console.error(`You must provide a valid image URL or buffer.`); + const canvas = new Jimp(960, 576); + const img1 = await Jimp.read(image); + const background = await Jimp.read(`${__dirname}/../../assets/notStonk.png`); + img1.resize(190, 190); + background.resize(960, 576); + canvas.composite(img1, 140, 5); + canvas.composite(background, 0, 0); + return canvas.getBufferAsync(Jimp.MIME_PNG); } }; diff --git a/src/module/montage/podium.js b/src/module/montage/podium.js index 6a63a8a..dc5064a 100644 --- a/src/module/montage/podium.js +++ b/src/module/montage/podium.js @@ -2,24 +2,21 @@ const Canvas = require(`canvas`); const { applyText } = require(`../functions`); - +const { validateURL } = require(`../functions`); module.exports = class Podium { - /** - * Podium - * @param {image} image1 - * @param {image} image2 - * @param {image} image3 - * @param {string} name1 - * @param {string} name2 - * @param {string} name3 - */ async getImage(image1, image2, image3, name1, name2, name3) { - if (!image1) throw new Error(`You must provide an image as a first argument.`); - if (!image2) throw new Error(`You must provide an image as a second argument.`); - if (!image3) throw new Error(`You must provide an image as a third argument.`); - if (!name1) throw new Error(`You must provide a text as a fourth argument.`); - if (!name2) throw new Error(`You must provide a text as a fifth argument.`); - if (!name3) throw new Error(`You must provide a text as a sixth argument.`); + if (!image1) return console.error(`You must provide an image as a first argument.`); + let isValid1 = await validateURL(image1); + if (!isValid1) return console.error(`You must provide a valid image URL or buffer.`); + if (!image2) return console.error(`You must provide an image as a second argument.`); + let isValid2 = await validateURL(image2); + if (!isValid2) return console.error(`You must provide a valid image URL or buffer.`); + if (!image3) return console.error(`You must provide an image as a third argument.`); + let isValid3 = await validateURL(image3); + if (!isValid3) return console.error(`You must provide a valid image URL or buffer.`); + if (!name1) return console.error(`You must provide a text as a fourth argument.`); + if (!name2) return console.error(`You must provide a text as a fifth argument.`); + if (!name3) return console.error(`You must provide a text as a sixth argument.`); const canvas = Canvas.createCanvas(1173, 686); const ctx = canvas.getContext(`2d`); image1 = await Canvas.loadImage(image1); diff --git a/src/module/montage/poutine.js b/src/module/montage/poutine.js index e46b968..c4851ee 100644 --- a/src/module/montage/poutine.js +++ b/src/module/montage/poutine.js @@ -1,18 +1,15 @@ -const Canvas = require(`canvas`); - +const Jimp = require(`jimp`); +const { validateURL } = require(`../functions`); module.exports = class Poutine { - /** - * Ad - * @param {image} image1 - */ - async getImage(image1) { - if (!image1) throw new Error(`You must provide an image as an argument`); - const canvas = Canvas.createCanvas(600, 539); - const ctx = canvas.getContext(`2d`); - image1 = await Canvas.loadImage(image1); - const background = await Canvas.loadImage(`${__dirname}/../../assets/poutine.png`); - ctx.drawImage(image1, 350, 20, 135, 135); - ctx.drawImage(background, 0, 0, 600, 539); - return canvas.toBuffer(); + async getImage(image) { + if (!image) return console.error(`You must provide an image as an argument`); + let isValid = await validateURL(image); + if (!isValid) return console.error(`You must provide a valid image URL or buffer.`); + const canvas = new Jimp(600, 539); + const img1 = await Jimp.read(image); + const background = await Jimp.read(`${__dirname}/../../assets/poutine.png`); + canvas.composite(img1, 350, 20); + canvas.composite(background, 0, 0); + return canvas.getBufferAsync(Jimp.MIME_PNG); } }; diff --git a/src/module/montage/rip.js b/src/module/montage/rip.js index 5ddcefa..71dfc76 100644 --- a/src/module/montage/rip.js +++ b/src/module/montage/rip.js @@ -1,13 +1,10 @@ const Canvas = require(`canvas`); - +const { validateURL } = require(`../functions`); module.exports = class Rip { - /** - * Rip - * @param {image} image - */ - async getImage(image) { - if (!image) throw new Error(`You must provide an image as a first argument.`); + 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.`); const canvas = Canvas.createCanvas(720, 405); const ctx = canvas.getContext(`2d`); const background = await Canvas.loadImage(`${__dirname}/../../assets/rip.png`); diff --git a/src/module/montage/snyder.js b/src/module/montage/snyder.js new file mode 100644 index 0000000..8fe994f --- /dev/null +++ b/src/module/montage/snyder.js @@ -0,0 +1,28 @@ +const Canvas = require(`canvas`); +const { validateURL } = require(`../functions`); + +module.exports = class Snyder { + async getImage(image) { + + function drawImage(ctx, image, x, y, w, h, degrees) { + ctx.save(); + ctx.translate(x + w / 2, y + h / 2); + ctx.rotate(degrees * Math.PI / 180.0); + ctx.translate(-x - w / 2, -y - h / 2); + ctx.drawImage(image, x, y, w, h); + ctx.restore(); + } + + if (!image) throw new Error(`You must provide an image as an argument`); + let isValid = await validateURL(img1); + if (!isValid) return console.error(`You must provide a valid image URL or buffer.`); + const canvas = Canvas.createCanvas(610, 343); + const ctx = canvas.getContext(`2d`); + image = await Canvas.loadImage(image); + const background = await Canvas.loadImage(`${__dirname}/../../assets/snyder.png`); + ctx.fillRect(0, 0, 610, 343); + drawImage(ctx, image, 62, 70, 300, 300, -6); + ctx.drawImage(background, 0, 0, 610, 343); + return canvas.toBuffer(); + } +}; \ No newline at end of file diff --git a/src/module/montage/spank.js b/src/module/montage/spank.js index 81b4302..e46ca39 100644 --- a/src/module/montage/spank.js +++ b/src/module/montage/spank.js @@ -1,14 +1,13 @@ const jimp = require(`jimp`); - +const { validateURL } = require(`../functions`); module.exports = class Spank { - /** - * - * @param {image} image1 - * @param {image} image2 - */ async getImage(image1, image2) { - if (!image1) throw new Error(`You must provide an image as a first argument.`); - if (!image2) throw new Error(`You must provide an image as a second argument.`); + if (!image1) return console.error(`You must provide an image as a first argument.`); + let isValid1 = await validateURL(image1); + if (!isValid1) return console.error(`You must provide a valid image URL or buffer.`); + if (!image2) return console.error(`You must provide an image as a second argument.`); + let isValid2 = await validateURL(image2); + if (!isValid2) return console.error(`You must provide a valid image URL or buffer.`); let bg = await jimp.read(`${__dirname}/../../assets/spank.png`); image1 = await jimp.read(image1); image2 = await jimp.read(image2); @@ -21,10 +20,6 @@ module.exports = class Spank { image2.resize(120, 120); bg.composite(image2, 350, 220); bg.composite(image1, 225, 5); - let raw; - bg.getBuffer(`image/png`, (err, buffer) => { - raw = buffer; - }); - return raw; + return await bg.getBufferAsync(`image/png`); } }; \ No newline at end of file diff --git a/src/module/montage/stonk.js b/src/module/montage/stonk.js index b9a4c34..18e0935 100644 --- a/src/module/montage/stonk.js +++ b/src/module/montage/stonk.js @@ -1,17 +1,15 @@ const Canvas = require(`canvas`); - +const { validateURL } = require(`../functions`); module.exports = class Stonk { - /** - * Stonk - * @param {image} image1 - */ - async getImage(image1) { - if (!image1) throw new Error(`You must provide an image as an argument`); + async getImage(image) { + if (!image) return console.error(`You must provide an image as an argument`); + let isValid = await validateURL(image); + if (!isValid) return console.error(`You must provide a valid image URL or buffer.`); const canvas = Canvas.createCanvas(900, 539); const ctx = canvas.getContext(`2d`); - image1 = await Canvas.loadImage(image1); + image = await Canvas.loadImage(image); const background = await Canvas.loadImage(`${__dirname}/../../assets/stonk.png`); - ctx.drawImage(image1, 70, 40, 240, 240); + ctx.drawImage(image, 70, 40, 240, 240); ctx.drawImage(background, 0, 0, 900, 539); return canvas.toBuffer(); } diff --git a/src/module/montage/tatoo.js b/src/module/montage/tatoo.js index 3eb4e2c..4bf8c2e 100644 --- a/src/module/montage/tatoo.js +++ b/src/module/montage/tatoo.js @@ -1,12 +1,10 @@ const Canvas = require(`canvas`); - +const { validateURL } = require(`../functions`); module.exports = class Tatoo { - /** - * Tatoo - * @param {image} image - */ async getImage(image) { - if (!image) throw new Error(`You must provide an image as a first argument.`); + 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.`); const canvas = Canvas.createCanvas(750, 1089); const ctx = canvas.getContext(`2d`); const avatar = await Canvas.loadImage(image); diff --git a/src/module/montage/thomas.js b/src/module/montage/thomas.js index 8006584..4701231 100644 --- a/src/module/montage/thomas.js +++ b/src/module/montage/thomas.js @@ -1,12 +1,10 @@ const Canvas = require(`canvas`); - +const { validateURL } = require(`../functions`); module.exports = class Thomas { - /** - * Thomas - * @param {image} image - */ async getImage(image) { - if (!image) throw new Error(`You must provide an image as a first argument.`); + 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.`); const canvas = Canvas.createCanvas(841, 1058); const ctx = canvas.getContext(`2d`); const avatar = await Canvas.loadImage(image); diff --git a/src/module/montage/trash.js b/src/module/montage/trash.js index 147f066..da14cd9 100644 --- a/src/module/montage/trash.js +++ b/src/module/montage/trash.js @@ -1,21 +1,15 @@ const jimp = require(`jimp`); - +const { validateURL } = require(`../functions`); module.exports = class Trash { - /** - * Trash - * @param {image} image - */ async getImage(image) { - if (!image) throw new Error(`You must provide an image as a first argument.`); + 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.`); let bg = await jimp.read(`${__dirname}/../../assets/trash.png`); image = await jimp.read(image); image.resize(309, 309); image.blur(5); bg.composite(image, 309, 0); - let raw; - bg.getBuffer(`image/png`, (err, buffer) => { - raw = buffer; - }); - return raw; + return await bg.getBufferAsync(`image/png`); } }; \ No newline at end of file diff --git a/src/module/montage/wanted.js b/src/module/montage/wanted.js index 711391d..5d5c236 100644 --- a/src/module/montage/wanted.js +++ b/src/module/montage/wanted.js @@ -2,16 +2,14 @@ const Canvas = require(`canvas`); const { applyText } = require(`../functions`); - +const { validateURL } = require(`../functions`); module.exports = class Wanted { - /** - * Wanted - * @param {image} image - */ async getImage(image, currency = `$`) { - if (!image) throw new Error(`You must provide an image as a first argument.`); - if (typeof currency != `string`) throw new Error(`You must provide a string for the currency.`); - if (currency.length > 1) throw new Error(`You must provide only one character for the currency.`); + 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 (typeof currency != `string`) return console.error(`You must provide a string for the currency.`); + if (currency.length > 1) return console.error(`You must provide only one character for the currency.`); var price = Math.floor(Math.random() * 188708) + 329889; const canvas = Canvas.createCanvas(257, 383); const ctx = canvas.getContext(`2d`); diff --git a/src/module/utils/circle.js b/src/module/utils/circle.js index 218c660..e48dc95 100644 --- a/src/module/utils/circle.js +++ b/src/module/utils/circle.js @@ -1,19 +1,13 @@ const jimp = require(`jimp`); - +const { validateURL } = require(`../functions`); module.exports = class Circle { - /** - * Circle - * @param {image} image - */ async getImage(image) { - if (!image) throw new Error(`You must provide an image as a first argument.`); + 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.resize(480, 480); image.circle(); - let raw; - image.getBuffer(`image/png`, (err, buffer) => { - raw = buffer; - }); - return raw; + return await image.getBufferAsync(`image/png`); } }; \ No newline at end of file diff --git a/src/module/utils/color.js b/src/module/utils/color.js index d25f4a3..7b82439 100644 --- a/src/module/utils/color.js +++ b/src/module/utils/color.js @@ -1,10 +1,6 @@ const Canvas = require(`canvas`); module.exports = class Color { - /** - * Color - * @param {string} color - */ async getImage(color = `#FFFFFF`) { const canvas = Canvas.createCanvas(2048, 2048); const ctx = canvas.getContext(`2d`); diff --git a/typings/index.d.ts b/typings/index.d.ts deleted file mode 100644 index 021744f..0000000 --- a/typings/index.d.ts +++ /dev/null @@ -1,85 +0,0 @@ -declare abstract class ImageGenerator { - abstract getImage(...args: any[]): Promise; -} - -declare class DefaultImageGenerator extends ImageGenerator { - getImage(avatar: string): Promise; -} - -export class Blur extends ImageGenerator { - getImage(avatar: string, level?: number): Promise; -} - -export class Blink extends ImageGenerator { - getImage(avatar: string, avatar2: string, ...avatars: string[]): Promise; -} - -export class Batslap extends ImageGenerator { - getImage(avatar: string, avatar2: string): Promise; -} - -export class Bed extends ImageGenerator { - getImage(avatar: string, avatar2: string): Promise; -} - -export class DoubleStonk extends ImageGenerator { - getImage(avatar: string, avatar2: string): Promise; -} - -export class Kiss extends ImageGenerator { - getImage(avatar: string, avatar2: string): Promise; -} - -export class LisaPresentation extends ImageGenerator { - getImage(text: string): Promise; -} - -export class Podium extends ImageGenerator { - getImage( - avatar: string, - avatar2: string, - avatar3: string, - name: string, - name2: string, - name3: string - ): Promise; -} - -export class Spank extends ImageGenerator { - getImage(avatar: string, avatar2: string): Promise; -} - -export class Wanted extends ImageGenerator { - getImage(avatar: string, currency: string): Promise; -} - -export class Color extends ImageGenerator { - getImage(color: string): Promise; -} - -export class Gay extends DefaultImageGenerator {} -export class Greyscale extends DefaultImageGenerator {} -export class Invert extends DefaultImageGenerator {} -export class Sepia extends DefaultImageGenerator {} -export class Triggered extends DefaultImageGenerator {} -export class Ad extends DefaultImageGenerator {} -export class Affect extends DefaultImageGenerator {} -export class Beautiful extends DefaultImageGenerator {} -export class Bobross extends DefaultImageGenerator {} -export class ConfusedStonk extends DefaultImageGenerator {} -export class Delete extends DefaultImageGenerator {} -export class DiscordBlack extends DefaultImageGenerator {} -export class DiscordBlue extends DefaultImageGenerator {} -export class Facepalm extends DefaultImageGenerator {} -export class Hitler extends DefaultImageGenerator {} -export class Jail extends DefaultImageGenerator {} -export class Karaba extends DefaultImageGenerator {} -export class Mms extends DefaultImageGenerator {} -export class NotStonk extends DefaultImageGenerator {} -export class Poutine extends DefaultImageGenerator {} -export class Rip extends DefaultImageGenerator {} -export class Stonk extends DefaultImageGenerator {} -export class Tatoo extends DefaultImageGenerator {} -export class Thomas extends DefaultImageGenerator {} -export class Trash extends DefaultImageGenerator {} -export class Circle extends DefaultImageGenerator {}