diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..262a4c8 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,22 @@ +module.exports = { + "rules": { + "no-console": `off`, + "indent": [`error`, 4], + "semi": [`error`, `always`], + "quotes": [`error`, `backtick`], + "keyword-spacing": [ + `error`, + { + "before": true, "after": true + } + ], + }, + "extends": `eslint:recommended`, + "env": { + "es6": true, + "node": true, + }, + "parserOptions": { + "ecmaVersion": 2020 + }, +}; diff --git a/README.md b/README.md index 7d07fad..38e10a9 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ bot.login("super_secret_token") ## Gifs -- ``new DIG.Blink().getImage(``, ``, )`` +- ``new DIG.Blink().getImage(``, ``, ``);`` ![Blink](https://imgur.com/JjUXmRU.gif) @@ -137,6 +137,14 @@ bot.login("super_secret_token") ![Delete](https://imgur.com/6V1IYJp.png) +- ``new DIG.DiscordBlack().getImage(``)`` + +![DiscordBlack](https://imgur.com/dTX3wta.png) + +- ``new DIG.DiscordBlue().getImage(``)`` + +![DiscordBlue](https://imgur.com/q1bRGrx.png) + - ``new DIG.DoubleStonk().getImage(``)`` ![DoubleStonk](https://imgur.com/HbuuUC6.png) @@ -225,6 +233,11 @@ bot.login("super_secret_token") # Changelog +## v1.4.0 +- Added DiscordBlack() and DiscordBlue() +- Added ESLint and fixed all problems +- Use of the function file in LisaPresentation() instead of an in file function + ## v1.3.9 - Edited links in README - Bumped jimp from 0.14.0 to 0.16.1 diff --git a/package.json b/package.json index 052b485..55c2f7a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord-image-generation", - "version": "1.3.9", + "version": "1.4.0", "description": "discord-image-generation is a powerfull module that allow you to generate awesome images.", "main": "src/index.js", "scripts": { diff --git a/src/assets/discordblack.png b/src/assets/discordblack.png new file mode 100644 index 0000000..ee035f9 Binary files /dev/null and b/src/assets/discordblack.png differ diff --git a/src/assets/discordblue.png b/src/assets/discordblue.png new file mode 100644 index 0000000..e2214f6 Binary files /dev/null and b/src/assets/discordblue.png differ diff --git a/src/index.js b/src/index.js index eddb585..de4940f 100644 --- a/src/index.js +++ b/src/index.js @@ -1,15 +1,15 @@ -const { readdirSync } = require("fs"); -const { join } = require("path"); +const { readdirSync } = require(`fs`); +const { join } = require(`path`); -for (let type of readdirSync(join(__dirname, "module")).filter( - f => !f.includes(".") +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}`); - }); + 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}`); + }); } diff --git a/src/module/filters/blur.js b/src/module/filters/blur.js index 0b7e075..2b48590 100644 --- a/src/module/filters/blur.js +++ b/src/module/filters/blur.js @@ -1,4 +1,4 @@ -const jimp = require("jimp"); +const jimp = require(`jimp`); module.exports = class Blur { /** @@ -9,7 +9,7 @@ module.exports = class Blur { async getImage(image, level) { if (!image) throw new Error(`You must provide an image.`); image = await jimp.read(image); - image.resize(480, 480) + image.resize(480, 480); image.blur(isNaN(level) ? 5 : parseInt(level)); let raw; image.getBuffer(`image/png`, (err, buffer) => { @@ -17,4 +17,4 @@ module.exports = class Blur { }); return raw; } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/module/filters/gay.js b/src/module/filters/gay.js index bae12d5..b7c3419 100644 --- a/src/module/filters/gay.js +++ b/src/module/filters/gay.js @@ -1,4 +1,4 @@ -const Canvas = require("canvas"); +const Canvas = require(`canvas`); module.exports = class Gay { /** @@ -15,4 +15,4 @@ module.exports = class Gay { ctx.drawImage(bg, 0, 0, 480, 480); return canvas.toBuffer(); } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/module/filters/greyscale.js b/src/module/filters/greyscale.js index ffa7c7c..cbcb6df 100644 --- a/src/module/filters/greyscale.js +++ b/src/module/filters/greyscale.js @@ -1,4 +1,4 @@ -const jimp = require("jimp"); +const jimp = require(`jimp`); module.exports = class Geryscale { /** @@ -8,7 +8,7 @@ module.exports = class Geryscale { async getImage(image) { if (!image) throw new Error(`You must provide an image.`); image = await jimp.read(image); - image.resize(480, 480) + image.resize(480, 480); image.greyscale(); let raw; image.getBuffer(`image/png`, (err, buffer) => { @@ -16,4 +16,4 @@ module.exports = class Geryscale { }); return raw; } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/module/filters/invert.js b/src/module/filters/invert.js index 645611e..26fae2e 100644 --- a/src/module/filters/invert.js +++ b/src/module/filters/invert.js @@ -1,4 +1,4 @@ -const jimp = require("jimp"); +const jimp = require(`jimp`); module.exports = class Invert { /** @@ -8,7 +8,7 @@ module.exports = class Invert { async getImage(image) { if (!image) throw new Error(`You must provide an image.`); image = await jimp.read(image); - image.resize(480, 480) + image.resize(480, 480); image.invert(); let raw; image.getBuffer(`image/png`, (err, buffer) => { @@ -16,4 +16,4 @@ module.exports = class Invert { }); return raw; } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/module/filters/sepia.js b/src/module/filters/sepia.js index 94a1d81..7876450 100644 --- a/src/module/filters/sepia.js +++ b/src/module/filters/sepia.js @@ -1,4 +1,4 @@ -const jimp = require("jimp"); +const jimp = require(`jimp`); module.exports = class Sepia { /** @@ -8,7 +8,7 @@ module.exports = class Sepia { async getImage(image) { if (!image) throw new Error(`You must provide an image.`); image = await jimp.read(image); - image.resize(480, 480) + image.resize(480, 480); image.sepia(); let raw; image.getBuffer(`image/png`, (err, buffer) => { @@ -16,4 +16,4 @@ module.exports = class Sepia { }); return raw; } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/module/functions.js b/src/module/functions.js index 15ffac5..7e77ceb 100644 --- a/src/module/functions.js +++ b/src/module/functions.js @@ -9,7 +9,7 @@ module.exports = { * @param {string} font the font */ applyText(canvas, text, defaultFontSize, width, font){ - const ctx = canvas.getContext("2d"); + const ctx = canvas.getContext(`2d`); do { ctx.font = `${(defaultFontSize -= 1)}px ${font}`; } while (ctx.measureText(text).width > width); @@ -19,10 +19,10 @@ module.exports = { wrapText(ctx, text, maxWidth) { return new Promise(resolve => { if (ctx.measureText(text).width < maxWidth) return resolve([text]); - if (ctx.measureText('W').width > maxWidth) return resolve(null); - const words = text.split(' '); + if (ctx.measureText(`W`).width > maxWidth) return resolve(null); + const words = text.split(` `); const lines = []; - let line = ''; + let line = ``; while (words.length > 0) { let split = false; while (ctx.measureText(words[0]).width >= maxWidth) { @@ -41,11 +41,11 @@ module.exports = { } else { lines.push(line.trim()); - line = ''; + line = ``; } if (words.length === 0) lines.push(line.trim()); } return resolve(lines); }); } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/module/gif/blink.js b/src/module/gif/blink.js index 22ba398..720fcdb 100644 --- a/src/module/gif/blink.js +++ b/src/module/gif/blink.js @@ -8,30 +8,28 @@ module.exports = class Blink { * @param {image} image1 * @param {image} image2 * @param {number} timeout - * @param {number} height For later - * @param {number} width For later */ - async getImage(image1, image2, timeout = 1000, height, width) { + async getImage(image1, image2, timeout = 1000) { 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 (isNaN(timeout)) throw new Error(`The timeout argument must be a number.`) + if (isNaN(timeout)) throw new Error(`The timeout argument must be a number.`); const img = await Canvas.loadImage(image1); const base = await Canvas.loadImage(image2); - const GIF = new GIFEncoder(480, 480) + const GIF = new GIFEncoder(480, 480); GIF.start(); GIF.setRepeat(0); GIF.setDelay(timeout); GIF.setTransparent(); const canvas = Canvas.createCanvas(480, 480); - const ctx = canvas.getContext('2d'); + const ctx = canvas.getContext(`2d`); ctx.clearRect(0, 0, 480, 480); ctx.drawImage(img, 0, 0, 480, 480); GIF.addFrame(ctx); - const ctx2 = canvas.getContext('2d'); + const ctx2 = canvas.getContext(`2d`); ctx2.clearRect(0, 0, 480, 480); ctx2.drawImage(base, 0, 0, 480, 480); - GIF.addFrame(ctx2) + GIF.addFrame(ctx2); GIF.finish(); return GIF.out.getData(); } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/module/gif/triggered.js b/src/module/gif/triggered.js index 737342f..82db5b7 100644 --- a/src/module/gif/triggered.js +++ b/src/module/gif/triggered.js @@ -10,26 +10,26 @@ module.exports = class Triggered { */ async getImage(image, timeout = 15) { if (!image) throw new Error(`You must provide an image.`); - if (isNaN(timeout)) throw new Error(`The timeout argument must be a number.`) + if (isNaN(timeout)) throw new 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) + const GIF = new GIFEncoder(256, 310); GIF.start(); GIF.setRepeat(0); GIF.setDelay(timeout); const canvas = Canvas.createCanvas(256, 310); - const ctx = canvas.getContext('2d'); + const ctx = canvas.getContext(`2d`); const BR = 20; const LR = 10; for (var i = 0; i < 9; i++) { ctx.clearRect(0, 0, 256, 310); ctx.drawImage(img, Math.floor(Math.random() * BR) - BR, Math.floor(Math.random() * BR) - BR, 256 + BR, 310 - 54 + BR); - ctx.fillStyle = '#FF000033'; + ctx.fillStyle = `#FF000033`; ctx.fillRect(0, 0, 256, 310); ctx.drawImage(base, Math.floor(Math.random() * LR) - LR, 310 - 54 + Math.floor(Math.random() * LR) - LR, 256 + LR, 54 + LR); GIF.addFrame(ctx); - }; + } GIF.finish(); return GIF.out.getData(); } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/module/montage/ad.js b/src/module/montage/ad.js index a113ccc..939cd3c 100644 --- a/src/module/montage/ad.js +++ b/src/module/montage/ad.js @@ -1,4 +1,4 @@ -const Canvas = require("canvas"); +const Canvas = require(`canvas`); module.exports = class Ad { /** @@ -15,4 +15,4 @@ module.exports = class Ad { ctx.drawImage(background, 0, 0, 550, 474); return canvas.toBuffer(); } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/module/montage/affect.js b/src/module/montage/affect.js index 187cb26..f9b6b5f 100644 --- a/src/module/montage/affect.js +++ b/src/module/montage/affect.js @@ -1,4 +1,4 @@ -const jimp = require("jimp"); +const jimp = require(`jimp`); module.exports = class Affect { /** @@ -6,15 +6,15 @@ module.exports = class Affect { * @param {image} image */ async getImage(image) { - if (!image) throw new Error("You must provide an image."); + if (!image) throw new Error(`You must provide an image.`); 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) => { + base.getBuffer(`image/png`, (err, buffer) => { raw = buffer; }); return raw; } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/module/montage/batslap.js b/src/module/montage/batslap.js index 545a06b..6482ee5 100644 --- a/src/module/montage/batslap.js +++ b/src/module/montage/batslap.js @@ -1,4 +1,4 @@ -const jimp = require("jimp"); +const jimp = require(`jimp`); module.exports = class Batslap { /** @@ -7,8 +7,8 @@ module.exports = class Batslap { * @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) 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.`); let base = await jimp.read(`${__dirname}/../../assets/batslap.png`); image1 = await jimp.read(image1); image2 = await jimp.read(image2); @@ -20,9 +20,9 @@ module.exports = class Batslap { base.composite(image2, 580, 260); base.composite(image1, 350, 70); let raw; - base.getBuffer("image/png", (err, buffer) => { + base.getBuffer(`image/png`, (err, buffer) => { raw = buffer; }); return raw; } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/module/montage/beautiful.js b/src/module/montage/beautiful.js index 3d0daec..c63a1f9 100644 --- a/src/module/montage/beautiful.js +++ b/src/module/montage/beautiful.js @@ -1,4 +1,4 @@ -const jimp = require("jimp"); +const jimp = require(`jimp`); module.exports = class Beautiful { /** @@ -6,7 +6,7 @@ module.exports = class Beautiful { * @param {image} image */ async getImage(image) { - if (!image) throw new Error("You must provide an image."); + if (!image) throw new Error(`You must provide an image.`); let base = await jimp.read(`${__dirname}/../../assets/beautiful.png`); base.resize(376, 400); let img = await jimp.read(image); @@ -14,9 +14,9 @@ module.exports = class Beautiful { base.composite(img, 258, 28); base.composite(img, 258, 229); let raw; - base.getBuffer("image/png", (err, buffer) => { + base.getBuffer(`image/png`, (err, buffer) => { raw = buffer; }); return raw; } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/module/montage/bed.js b/src/module/montage/bed.js index d349b0e..08e360c 100644 --- a/src/module/montage/bed.js +++ b/src/module/montage/bed.js @@ -1,4 +1,4 @@ -const jimp = require("jimp"); +const jimp = require(`jimp`); module.exports = class Bed { /** @@ -27,4 +27,4 @@ module.exports = class Bed { }); return raw; } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/module/montage/bobross.js b/src/module/montage/bobross.js index 4ea107c..2e89415 100644 --- a/src/module/montage/bobross.js +++ b/src/module/montage/bobross.js @@ -1,22 +1,20 @@ -const { createCanvas, loadImage } = require("canvas"); +const { createCanvas, loadImage } = require(`canvas`); module.exports = class Bobross { - /** + /** * Bobross * @param {image} image1 */ - async getImage(image1){ - if (!image1) throw new Error(`You must provide an image as 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() - } -} - -// -N²O Pyro ;) + async getImage(image1) { + if (!image1) throw new Error(`You must provide an image as 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(); + } +}; diff --git a/src/module/montage/confusedStonk.js b/src/module/montage/confusedStonk.js index ba03512..306e1ca 100644 --- a/src/module/montage/confusedStonk.js +++ b/src/module/montage/confusedStonk.js @@ -1,4 +1,4 @@ -const Canvas = require("canvas"); +const Canvas = require(`canvas`); module.exports = class ConfusedStonk { /** @@ -15,4 +15,4 @@ module.exports = class ConfusedStonk { ctx.drawImage(background, 0, 0, 1994, 1296); return canvas.toBuffer(); } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/module/montage/delete.js b/src/module/montage/delete.js index 508f19f..1519449 100644 --- a/src/module/montage/delete.js +++ b/src/module/montage/delete.js @@ -1,4 +1,4 @@ -const jimp = require("jimp"); +const jimp = require(`jimp`); module.exports = class Delete { /** @@ -17,4 +17,4 @@ module.exports = class Delete { }); return raw; } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/module/montage/discordBlack.js b/src/module/montage/discordBlack.js new file mode 100644 index 0000000..ee2c20f --- /dev/null +++ b/src/module/montage/discordBlack.js @@ -0,0 +1,18 @@ +const Canvas = require(`canvas`); + +module.exports = class DiscordBlack { + /** + * Bobross + * @param {image} image1 + */ + async getImage(image1) { + if (!image1) throw new Error(`You must provide an image as 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(); + } +}; diff --git a/src/module/montage/discordBlue.js b/src/module/montage/discordBlue.js new file mode 100644 index 0000000..f4b403c --- /dev/null +++ b/src/module/montage/discordBlue.js @@ -0,0 +1,18 @@ +const Canvas = require(`canvas`); + +module.exports = class DiscordBlue { + /** + * Bobross + * @param {image} image1 + */ + async getImage(image1) { + if (!image1) throw new Error(`You must provide an image as 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(); + } +}; diff --git a/src/module/montage/doubleStonk.js b/src/module/montage/doubleStonk.js index 6d49541..e064a51 100644 --- a/src/module/montage/doubleStonk.js +++ b/src/module/montage/doubleStonk.js @@ -1,4 +1,4 @@ -const jimp = require("jimp"); +const jimp = require(`jimp`); module.exports = class DoubleStonk { /** @@ -7,8 +7,8 @@ module.exports = class DoubleStonk { * @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) 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.`); let base = await jimp.read(`${__dirname}/../../assets/doubleStonk.png`); image1 = await jimp.read(image1); image2 = await jimp.read(image2); @@ -20,9 +20,9 @@ module.exports = class DoubleStonk { base.composite(image2, 60, 20); base.composite(image1, 0, 30); let raw; - base.getBuffer("image/png", (err, buffer) => { + base.getBuffer(`image/png`, (err, buffer) => { raw = buffer; }); return raw; } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/module/montage/facepalm.js b/src/module/montage/facepalm.js index 24a8fd6..5cc2a05 100644 --- a/src/module/montage/facepalm.js +++ b/src/module/montage/facepalm.js @@ -1,4 +1,4 @@ -const Canvas = require("canvas"); +const Canvas = require(`canvas`); module.exports = class Facepalm { /** @@ -6,10 +6,10 @@ module.exports = class Facepalm { * @param {image} image */ async getImage(image) { - if (!image) throw new Error("You must provide an image."); + if (!image) throw new Error(`You must provide an image.`); let canvas = Canvas.createCanvas(632, 357); - let ctx = canvas.getContext("2d"); - ctx.fillStyle = "black"; + 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); @@ -17,4 +17,4 @@ module.exports = class Facepalm { ctx.drawImage(layer, 0, 0, 632, 357); return canvas.toBuffer(); } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/module/montage/hitler.js b/src/module/montage/hitler.js index 8df408e..7af7fce 100644 --- a/src/module/montage/hitler.js +++ b/src/module/montage/hitler.js @@ -1,4 +1,4 @@ -const jimp = require("jimp"); +const jimp = require(`jimp`); module.exports = class Hitler { /** @@ -17,4 +17,4 @@ module.exports = class Hitler { }); return raw; } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/module/montage/jail.js b/src/module/montage/jail.js index f1fdf6b..d3cb373 100644 --- a/src/module/montage/jail.js +++ b/src/module/montage/jail.js @@ -1,4 +1,4 @@ -const Canvas = require("canvas"); +const Canvas = require(`canvas`); module.exports = class Jail { /** @@ -15,4 +15,4 @@ module.exports = class Jail { ctx.drawImage(bg, 0, 0, 400, 400); return canvas.toBuffer(); } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/module/montage/kiss.js b/src/module/montage/kiss.js index e24ca51..f76ae2a 100644 --- a/src/module/montage/kiss.js +++ b/src/module/montage/kiss.js @@ -1,4 +1,4 @@ -const jimp = require("jimp"); +const jimp = require(`jimp`); module.exports = class Kiss { /** @@ -25,4 +25,4 @@ module.exports = class Kiss { }); return raw; } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/module/montage/lisaPresentation.js b/src/module/montage/lisaPresentation.js index d60baf8..e311bd1 100644 --- a/src/module/montage/lisaPresentation.js +++ b/src/module/montage/lisaPresentation.js @@ -1,66 +1,34 @@ -const { createCanvas, loadImage, registerFont } = require('canvas'); -registerFont(`${__dirname}/../../assets/fonts/Noto-Regular.ttf`, { family: 'Noto' }); -registerFont(`${__dirname}/../../assets/fonts/Noto-Emoji.ttf`, { family: 'Noto' }); -const path = require("path"); - -function wrapText(ctx, text, maxWidth) { - return new Promise(resolve => { - if (ctx.measureText(text).width < maxWidth) return resolve([text]); - if (ctx.measureText('W').width > maxWidth) return resolve(null); - const words = text.split(' '); - const lines = []; - let line = ''; - while (words.length > 0) { - let split = false; - while (ctx.measureText(words[0]).width >= maxWidth) { - const temp = words[0]; - words[0] = temp.slice(0, -1); - if (split) { - words[1] = `${temp.slice(-1)}${words[1]}`; - } - else { - split = true; - words.splice(1, 0, temp.slice(-1)); - } - } - if (ctx.measureText(`${line}${words[0]}`).width < maxWidth) { - line += `${words.shift()} `; - } - else { - lines.push(line.trim()); - line = ''; - } - if (words.length === 0) lines.push(line.trim()); - } - return resolve(lines); - }); -} +const { createCanvas, loadImage, registerFont } = require(`canvas`); +registerFont(`${__dirname}/../../assets/fonts/Noto-Regular.ttf`, { family: `Noto` }); +registerFont(`${__dirname}/../../assets/fonts/Noto-Emoji.ttf`, { family: `Noto` }); +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.`) + async getImage(text) { + if (!text || text.length > 300) throw new 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'); - ctx.drawImage(base, 0, 0); - ctx.textAlign = 'center'; - ctx.textBaseline = 'top'; - ctx.font = '40px Noto'; - let fontSize = 40; - while (ctx.measureText(text).width > 1320) { + const base = await loadImage(path.join(`${__dirname}/../../assets/lisa-presentation.png`)); + const canvas = createCanvas(base.width, base.height); + const ctx = canvas.getContext(`2d`); + ctx.drawImage(base, 0, 0); + ctx.textAlign = `center`; + ctx.textBaseline = `top`; + ctx.font = `40px Noto`; + let fontSize = 40; + while (ctx.measureText(text).width > 1320) { fontSize -= 1; ctx.font = `${fontSize}px Noto`; - } - const lines = await wrapText(ctx, text, 330); - const topMost = 185 - (((fontSize * lines.length) / 2) + ((20 * (lines.length - 1)) / 2)); - for (let i = 0; i < lines.length; i++) { + } + const lines = await wrapText(ctx, text, 330); + const topMost = 185 - (((fontSize * lines.length) / 2) + ((20 * (lines.length - 1)) / 2)); + for (let i = 0; i < lines.length; i++) { const height = topMost + ((fontSize + 20) * i); ctx.fillText(lines[i], base.width / 2, height); - } + } - return canvas.toBuffer(); - } + return canvas.toBuffer(); + } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/module/montage/mms.js b/src/module/montage/mms.js index c683ec7..42c58d8 100644 --- a/src/module/montage/mms.js +++ b/src/module/montage/mms.js @@ -1,4 +1,4 @@ -const Canvas = require("canvas"); +const Canvas = require(`canvas`); module.exports = class Mms { /** @@ -15,4 +15,4 @@ module.exports = class Mms { ctx.drawImage(bg, 0, 0, 400, 400); return canvas.toBuffer(); } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/module/montage/notStonk.js b/src/module/montage/notStonk.js index a4dd9f0..2c7e9f7 100644 --- a/src/module/montage/notStonk.js +++ b/src/module/montage/notStonk.js @@ -1,4 +1,4 @@ -const Canvas = require("canvas"); +const Canvas = require(`canvas`); module.exports = class NotStonk { /** @@ -13,6 +13,6 @@ module.exports = class NotStonk { 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(); + return canvas.tofBuffer(); } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/module/montage/podium.js b/src/module/montage/podium.js index eee1896..6a63a8a 100644 --- a/src/module/montage/podium.js +++ b/src/module/montage/podium.js @@ -1,7 +1,7 @@ -const Canvas = require("canvas"); -const { - applyText -} = require("../functions") +const Canvas = require(`canvas`); +const { + applyText +} = require(`../functions`); module.exports = class Podium { /** @@ -34,26 +34,26 @@ module.exports = class Podium { if (name1.length > 5) maxWidth = 150; if (name1.length > 10) maxWidth = 250; if (name1.length > 20) maxWidth = 350; - ctx.textAlign = 'center'; - ctx.font = applyText(canvas, name1, 80, maxWidth, "Comic Sans MS"); + ctx.textAlign = `center`; + ctx.font = applyText(canvas, name1, 80, maxWidth, `Comic Sans MS`); ctx.fillStyle = `#513d34`; ctx.fillText(name1, 580, 575); maxWidth = 80; if (name2.length > 5) maxWidth = 150; if (name2.length > 10) maxWidth = 180; if (name2.length > 20) maxWidth = 240; - ctx.textAlign = 'center'; - ctx.font = applyText(canvas, name2, 50, maxWidth, "Comic Sans MS"); + ctx.textAlign = `center`; + ctx.font = applyText(canvas, name2, 50, maxWidth, `Comic Sans MS`); ctx.fillStyle = `#513d34`; ctx.fillText(name2, 210, 540); maxWidth = 80; if (name3.length > 5) maxWidth = 150; if (name3.length > 10) maxWidth = 180; if (name3.length > 20) maxWidth = 240; - ctx.textAlign = 'center'; - ctx.font = applyText(canvas, name3, 50, maxWidth, "Comic Sans MS"); + ctx.textAlign = `center`; + ctx.font = applyText(canvas, name3, 50, maxWidth, `Comic Sans MS`); ctx.fillStyle = `#513d34`; ctx.fillText(name3, 970, 540); return canvas.toBuffer(); } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/module/montage/poutine.js b/src/module/montage/poutine.js index b5ec321..eabc82f 100644 --- a/src/module/montage/poutine.js +++ b/src/module/montage/poutine.js @@ -1,4 +1,4 @@ -const Canvas = require("canvas"); +const Canvas = require(`canvas`); module.exports = class Poutine { /** @@ -15,4 +15,4 @@ module.exports = class Poutine { ctx.drawImage(background, 0, 0, 600, 539); return canvas.toBuffer(); } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/module/montage/rip.js b/src/module/montage/rip.js index e0fe099..e891a75 100644 --- a/src/module/montage/rip.js +++ b/src/module/montage/rip.js @@ -1,4 +1,4 @@ -const Canvas = require("canvas"); +const Canvas = require(`canvas`); module.exports = class Rip { /** @@ -16,4 +16,4 @@ module.exports = class Rip { ctx.drawImage(background, 0, 0, canvas.width, canvas.height); return canvas.toBuffer(); } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/module/montage/spank.js b/src/module/montage/spank.js index 5e71891..81b4302 100644 --- a/src/module/montage/spank.js +++ b/src/module/montage/spank.js @@ -1,4 +1,4 @@ -const jimp = require("jimp"); +const jimp = require(`jimp`); module.exports = class Spank { /** @@ -27,4 +27,4 @@ module.exports = class Spank { }); return raw; } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/module/montage/stonk.js b/src/module/montage/stonk.js index 6fc36c5..e926d17 100644 --- a/src/module/montage/stonk.js +++ b/src/module/montage/stonk.js @@ -1,4 +1,4 @@ -const Canvas = require("canvas"); +const Canvas = require(`canvas`); module.exports = class Stonk { /** @@ -15,4 +15,4 @@ module.exports = class Stonk { ctx.drawImage(background, 0, 0, 900, 539); return canvas.toBuffer(); } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/module/montage/tatoo.js b/src/module/montage/tatoo.js index a2dc8c4..8d0d45d 100644 --- a/src/module/montage/tatoo.js +++ b/src/module/montage/tatoo.js @@ -1,4 +1,4 @@ -const Canvas = require("canvas"); +const Canvas = require(`canvas`); module.exports = class Tatoo { /** @@ -15,4 +15,4 @@ module.exports = class Tatoo { ctx.drawImage(background, 0, 0, 750, 1089); return canvas.toBuffer(); } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/module/montage/thomas.js b/src/module/montage/thomas.js index 5fd0a77..7f0cec5 100644 --- a/src/module/montage/thomas.js +++ b/src/module/montage/thomas.js @@ -1,4 +1,4 @@ -const Canvas = require("canvas"); +const Canvas = require(`canvas`); module.exports = class Thomas { /** @@ -15,4 +15,4 @@ module.exports = class Thomas { ctx.drawImage(background, 0, 0, 841, 1058); return canvas.toBuffer(); } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/module/montage/trash.js b/src/module/montage/trash.js index 46778f2..f9dc7da 100644 --- a/src/module/montage/trash.js +++ b/src/module/montage/trash.js @@ -1,4 +1,4 @@ -const jimp = require("jimp"); +const jimp = require(`jimp`); module.exports = class Trash { /** @@ -18,4 +18,4 @@ module.exports = class Trash { }); return raw; } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/module/montage/wanted.js b/src/module/montage/wanted.js index b330f8f..56b6a24 100644 --- a/src/module/montage/wanted.js +++ b/src/module/montage/wanted.js @@ -1,4 +1,4 @@ -const Canvas = require("canvas"); +const Canvas = require(`canvas`); const { applyText } = require(`../functions`); @@ -8,21 +8,21 @@ module.exports = class Wanted { * Wanted * @param {image} image */ - async getImage(image, currency = "$") { + async getImage(image, currency = `$`) { if (!image) throw new Error(`You must provide an image.`); - 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.`) - var price = Math.floor(Math.random() * 188708) + 329889 + 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.`); + var price = Math.floor(Math.random() * 188708) + 329889; const canvas = Canvas.createCanvas(257, 383); const ctx = canvas.getContext(`2d`); const avatar = await Canvas.loadImage(image); const background = await Canvas.loadImage(`${__dirname}/../../assets/wanted.png`); ctx.drawImage(avatar, 25, 60, 210, 210); ctx.drawImage(background, 0, 0, 257, 383); - ctx.textAlign = 'center'; - ctx.font = applyText(canvas, price.toLocaleString() + currency, 80, 200, "Times New Roman"); - ctx.fillStyle = `#513d34` - ctx.fillText(price.toLocaleString() + currency, 128, 315) + ctx.textAlign = `center`; + ctx.font = applyText(canvas, price.toLocaleString() + currency, 80, 200, `Times New Roman`); + ctx.fillStyle = `#513d34`; + ctx.fillText(price.toLocaleString() + currency, 128, 315); return canvas.toBuffer(); } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/module/utils/circle.js b/src/module/utils/circle.js index 7ba7d8c..1e0685d 100644 --- a/src/module/utils/circle.js +++ b/src/module/utils/circle.js @@ -1,4 +1,4 @@ -const jimp = require("jimp"); +const jimp = require(`jimp`); module.exports = class Circle { /** @@ -16,4 +16,4 @@ module.exports = class Circle { }); return raw; } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/module/utils/color.js b/src/module/utils/color.js index c250ac0..d25f4a3 100644 --- a/src/module/utils/color.js +++ b/src/module/utils/color.js @@ -1,4 +1,4 @@ -const Canvas = require("canvas"); +const Canvas = require(`canvas`); module.exports = class Color { /** @@ -12,4 +12,4 @@ module.exports = class Color { ctx.fillRect(0, 0, canvas.width, canvas.height); return canvas.toBuffer(); } -} \ No newline at end of file +}; \ No newline at end of file