Version 1.4.0

main
Killian 4 years ago
parent afa32e0211
commit 10fcffd6b6

@ -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
},
};

@ -94,7 +94,7 @@ bot.login("super_secret_token")
## Gifs ## Gifs
- ``new DIG.Blink().getImage(`<Avatar>`, `<Avatar2>`, <Timeout (Number in ms)>)`` - ``new DIG.Blink().getImage(`<Avatar>`, `<Avatar2>`, `<Timeout (Number in ms)>`);``
![Blink](https://imgur.com/JjUXmRU.gif) ![Blink](https://imgur.com/JjUXmRU.gif)
@ -137,6 +137,14 @@ bot.login("super_secret_token")
![Delete](https://imgur.com/6V1IYJp.png) ![Delete](https://imgur.com/6V1IYJp.png)
- ``new DIG.DiscordBlack().getImage(`<Avatar>`)``
![DiscordBlack](https://imgur.com/dTX3wta.png)
- ``new DIG.DiscordBlue().getImage(`<Avatar>`)``
![DiscordBlue](https://imgur.com/q1bRGrx.png)
- ``new DIG.DoubleStonk().getImage(`<Avatar`, `<Avatar2>`)`` - ``new DIG.DoubleStonk().getImage(`<Avatar`, `<Avatar2>`)``
![DoubleStonk](https://imgur.com/HbuuUC6.png) ![DoubleStonk](https://imgur.com/HbuuUC6.png)
@ -225,6 +233,11 @@ bot.login("super_secret_token")
# Changelog # 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 ## v1.3.9
- Edited links in README - Edited links in README
- Bumped jimp from 0.14.0 to 0.16.1 - Bumped jimp from 0.14.0 to 0.16.1

@ -1,6 +1,6 @@
{ {
"name": "discord-image-generation", "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.", "description": "discord-image-generation is a powerfull module that allow you to generate awesome images.",
"main": "src/index.js", "main": "src/index.js",
"scripts": { "scripts": {

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

@ -1,13 +1,13 @@
const { readdirSync } = require("fs"); const { readdirSync } = require(`fs`);
const { join } = require("path"); const { join } = require(`path`);
for (let type of readdirSync(join(__dirname, "module")).filter( for (let type of readdirSync(join(__dirname, `module`)).filter(
f => !f.includes(".") f => !f.includes(`.`)
)) { )) {
readdirSync(join(__dirname, "module", type)) readdirSync(join(__dirname, `module`, type))
.filter(file => file !== "index.js" && file.endsWith(".js")) .filter(file => file !== `index.js` && file.endsWith(`.js`))
.map(File => { .map(File => {
const Name = File.split(".")[0]; const Name = File.split(`.`)[0];
exports[ exports[
Name.charAt(0).toUpperCase() + Name.slice(1) Name.charAt(0).toUpperCase() + Name.slice(1)
] = require(`${__dirname}/module/${type}/${File}`); ] = require(`${__dirname}/module/${type}/${File}`);

@ -1,4 +1,4 @@
const jimp = require("jimp"); const jimp = require(`jimp`);
module.exports = class Blur { module.exports = class Blur {
/** /**
@ -9,7 +9,7 @@ module.exports = class Blur {
async getImage(image, level) { async getImage(image, level) {
if (!image) throw new Error(`You must provide an image.`); if (!image) throw new Error(`You must provide an image.`);
image = await jimp.read(image); image = await jimp.read(image);
image.resize(480, 480) image.resize(480, 480);
image.blur(isNaN(level) ? 5 : parseInt(level)); image.blur(isNaN(level) ? 5 : parseInt(level));
let raw; let raw;
image.getBuffer(`image/png`, (err, buffer) => { image.getBuffer(`image/png`, (err, buffer) => {
@ -17,4 +17,4 @@ module.exports = class Blur {
}); });
return raw; return raw;
} }
} };

@ -1,4 +1,4 @@
const Canvas = require("canvas"); const Canvas = require(`canvas`);
module.exports = class Gay { module.exports = class Gay {
/** /**
@ -15,4 +15,4 @@ module.exports = class Gay {
ctx.drawImage(bg, 0, 0, 480, 480); ctx.drawImage(bg, 0, 0, 480, 480);
return canvas.toBuffer(); return canvas.toBuffer();
} }
} };

@ -1,4 +1,4 @@
const jimp = require("jimp"); const jimp = require(`jimp`);
module.exports = class Geryscale { module.exports = class Geryscale {
/** /**
@ -8,7 +8,7 @@ module.exports = class Geryscale {
async getImage(image) { async getImage(image) {
if (!image) throw new Error(`You must provide an image.`); if (!image) throw new Error(`You must provide an image.`);
image = await jimp.read(image); image = await jimp.read(image);
image.resize(480, 480) image.resize(480, 480);
image.greyscale(); image.greyscale();
let raw; let raw;
image.getBuffer(`image/png`, (err, buffer) => { image.getBuffer(`image/png`, (err, buffer) => {
@ -16,4 +16,4 @@ module.exports = class Geryscale {
}); });
return raw; return raw;
} }
} };

@ -1,4 +1,4 @@
const jimp = require("jimp"); const jimp = require(`jimp`);
module.exports = class Invert { module.exports = class Invert {
/** /**
@ -8,7 +8,7 @@ module.exports = class Invert {
async getImage(image) { async getImage(image) {
if (!image) throw new Error(`You must provide an image.`); if (!image) throw new Error(`You must provide an image.`);
image = await jimp.read(image); image = await jimp.read(image);
image.resize(480, 480) image.resize(480, 480);
image.invert(); image.invert();
let raw; let raw;
image.getBuffer(`image/png`, (err, buffer) => { image.getBuffer(`image/png`, (err, buffer) => {
@ -16,4 +16,4 @@ module.exports = class Invert {
}); });
return raw; return raw;
} }
} };

@ -1,4 +1,4 @@
const jimp = require("jimp"); const jimp = require(`jimp`);
module.exports = class Sepia { module.exports = class Sepia {
/** /**
@ -8,7 +8,7 @@ module.exports = class Sepia {
async getImage(image) { async getImage(image) {
if (!image) throw new Error(`You must provide an image.`); if (!image) throw new Error(`You must provide an image.`);
image = await jimp.read(image); image = await jimp.read(image);
image.resize(480, 480) image.resize(480, 480);
image.sepia(); image.sepia();
let raw; let raw;
image.getBuffer(`image/png`, (err, buffer) => { image.getBuffer(`image/png`, (err, buffer) => {
@ -16,4 +16,4 @@ module.exports = class Sepia {
}); });
return raw; return raw;
} }
} };

@ -9,7 +9,7 @@ module.exports = {
* @param {string} font the font * @param {string} font the font
*/ */
applyText(canvas, text, defaultFontSize, width, font){ applyText(canvas, text, defaultFontSize, width, font){
const ctx = canvas.getContext("2d"); const ctx = canvas.getContext(`2d`);
do { do {
ctx.font = `${(defaultFontSize -= 1)}px ${font}`; ctx.font = `${(defaultFontSize -= 1)}px ${font}`;
} while (ctx.measureText(text).width > width); } while (ctx.measureText(text).width > width);
@ -19,10 +19,10 @@ module.exports = {
wrapText(ctx, text, maxWidth) { wrapText(ctx, text, maxWidth) {
return new Promise(resolve => { return new Promise(resolve => {
if (ctx.measureText(text).width < maxWidth) return resolve([text]); if (ctx.measureText(text).width < maxWidth) return resolve([text]);
if (ctx.measureText('W').width > maxWidth) return resolve(null); if (ctx.measureText(`W`).width > maxWidth) return resolve(null);
const words = text.split(' '); const words = text.split(` `);
const lines = []; const lines = [];
let line = ''; let line = ``;
while (words.length > 0) { while (words.length > 0) {
let split = false; let split = false;
while (ctx.measureText(words[0]).width >= maxWidth) { while (ctx.measureText(words[0]).width >= maxWidth) {
@ -41,11 +41,11 @@ module.exports = {
} }
else { else {
lines.push(line.trim()); lines.push(line.trim());
line = ''; line = ``;
} }
if (words.length === 0) lines.push(line.trim()); if (words.length === 0) lines.push(line.trim());
} }
return resolve(lines); return resolve(lines);
}); });
} }
} };

@ -8,30 +8,28 @@ module.exports = class Blink {
* @param {image} image1 * @param {image} image1
* @param {image} image2 * @param {image} image2
* @param {number} timeout * @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 (!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 (!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 img = await Canvas.loadImage(image1);
const base = await Canvas.loadImage(image2); const base = await Canvas.loadImage(image2);
const GIF = new GIFEncoder(480, 480) const GIF = new GIFEncoder(480, 480);
GIF.start(); GIF.start();
GIF.setRepeat(0); GIF.setRepeat(0);
GIF.setDelay(timeout); GIF.setDelay(timeout);
GIF.setTransparent(); GIF.setTransparent();
const canvas = Canvas.createCanvas(480, 480); const canvas = Canvas.createCanvas(480, 480);
const ctx = canvas.getContext('2d'); const ctx = canvas.getContext(`2d`);
ctx.clearRect(0, 0, 480, 480); ctx.clearRect(0, 0, 480, 480);
ctx.drawImage(img, 0, 0, 480, 480); ctx.drawImage(img, 0, 0, 480, 480);
GIF.addFrame(ctx); GIF.addFrame(ctx);
const ctx2 = canvas.getContext('2d'); const ctx2 = canvas.getContext(`2d`);
ctx2.clearRect(0, 0, 480, 480); ctx2.clearRect(0, 0, 480, 480);
ctx2.drawImage(base, 0, 0, 480, 480); ctx2.drawImage(base, 0, 0, 480, 480);
GIF.addFrame(ctx2) GIF.addFrame(ctx2);
GIF.finish(); GIF.finish();
return GIF.out.getData(); return GIF.out.getData();
} }
} };

@ -10,26 +10,26 @@ module.exports = class Triggered {
*/ */
async getImage(image, timeout = 15) { async getImage(image, timeout = 15) {
if (!image) throw new Error(`You must provide an image.`); 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 base = await Canvas.loadImage(`${__dirname}/../../assets/triggered.png`);
const img = await Canvas.loadImage(image); const img = await Canvas.loadImage(image);
const GIF = new GIFEncoder(256, 310) const GIF = new GIFEncoder(256, 310);
GIF.start(); GIF.start();
GIF.setRepeat(0); GIF.setRepeat(0);
GIF.setDelay(timeout); GIF.setDelay(timeout);
const canvas = Canvas.createCanvas(256, 310); const canvas = Canvas.createCanvas(256, 310);
const ctx = canvas.getContext('2d'); const ctx = canvas.getContext(`2d`);
const BR = 20; const BR = 20;
const LR = 10; const LR = 10;
for (var i = 0; i < 9; i++) { for (var i = 0; i < 9; i++) {
ctx.clearRect(0, 0, 256, 310); 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.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.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); 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.addFrame(ctx);
}; }
GIF.finish(); GIF.finish();
return GIF.out.getData(); return GIF.out.getData();
} }
} };

@ -1,4 +1,4 @@
const Canvas = require("canvas"); const Canvas = require(`canvas`);
module.exports = class Ad { module.exports = class Ad {
/** /**
@ -15,4 +15,4 @@ module.exports = class Ad {
ctx.drawImage(background, 0, 0, 550, 474); ctx.drawImage(background, 0, 0, 550, 474);
return canvas.toBuffer(); return canvas.toBuffer();
} }
} };

@ -1,4 +1,4 @@
const jimp = require("jimp"); const jimp = require(`jimp`);
module.exports = class Affect { module.exports = class Affect {
/** /**
@ -6,15 +6,15 @@ module.exports = class Affect {
* @param {image} image * @param {image} image
*/ */
async getImage(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 base = await jimp.read(`${__dirname}/../../assets/affect.png`);
let img = await jimp.read(image); let img = await jimp.read(image);
img.resize(200, 157); img.resize(200, 157);
base.composite(img, 180, 383); base.composite(img, 180, 383);
let raw; let raw;
base.getBuffer("image/png", (err, buffer) => { base.getBuffer(`image/png`, (err, buffer) => {
raw = buffer; raw = buffer;
}); });
return raw; return raw;
} }
} };

@ -1,4 +1,4 @@
const jimp = require("jimp"); const jimp = require(`jimp`);
module.exports = class Batslap { module.exports = class Batslap {
/** /**
@ -7,8 +7,8 @@ module.exports = class Batslap {
* @param {image} image2 * @param {image} image2
*/ */
async getImage(image1, image2) { async getImage(image1, image2) {
if (!image1) throw new Error("You must provide an image as a first 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."); if (!image2) throw new Error(`You must provide an image as a second argument.`);
let base = await jimp.read(`${__dirname}/../../assets/batslap.png`); let base = await jimp.read(`${__dirname}/../../assets/batslap.png`);
image1 = await jimp.read(image1); image1 = await jimp.read(image1);
image2 = await jimp.read(image2); image2 = await jimp.read(image2);
@ -20,9 +20,9 @@ module.exports = class Batslap {
base.composite(image2, 580, 260); base.composite(image2, 580, 260);
base.composite(image1, 350, 70); base.composite(image1, 350, 70);
let raw; let raw;
base.getBuffer("image/png", (err, buffer) => { base.getBuffer(`image/png`, (err, buffer) => {
raw = buffer; raw = buffer;
}); });
return raw; return raw;
} }
} };

@ -1,4 +1,4 @@
const jimp = require("jimp"); const jimp = require(`jimp`);
module.exports = class Beautiful { module.exports = class Beautiful {
/** /**
@ -6,7 +6,7 @@ module.exports = class Beautiful {
* @param {image} image * @param {image} image
*/ */
async getImage(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`); let base = await jimp.read(`${__dirname}/../../assets/beautiful.png`);
base.resize(376, 400); base.resize(376, 400);
let img = await jimp.read(image); let img = await jimp.read(image);
@ -14,9 +14,9 @@ module.exports = class Beautiful {
base.composite(img, 258, 28); base.composite(img, 258, 28);
base.composite(img, 258, 229); base.composite(img, 258, 229);
let raw; let raw;
base.getBuffer("image/png", (err, buffer) => { base.getBuffer(`image/png`, (err, buffer) => {
raw = buffer; raw = buffer;
}); });
return raw; return raw;
} }
} };

@ -1,4 +1,4 @@
const jimp = require("jimp"); const jimp = require(`jimp`);
module.exports = class Bed { module.exports = class Bed {
/** /**
@ -27,4 +27,4 @@ module.exports = class Bed {
}); });
return raw; return raw;
} }
} };

@ -1,22 +1,20 @@
const { createCanvas, loadImage } = require("canvas"); const { createCanvas, loadImage } = require(`canvas`);
module.exports = class Bobross { module.exports = class Bobross {
/** /**
* Bobross * Bobross
* @param {image} image1 * @param {image} image1
*/ */
async getImage(image1){ async getImage(image1) {
if (!image1) throw new Error(`You must provide an image as argument.`); if (!image1) throw new Error(`You must provide an image as argument.`);
const base = await loadImage(`${__dirname}/../../assets/bobross.png`); const base = await loadImage(`${__dirname}/../../assets/bobross.png`);
const canvas = createCanvas(base.width, base.height); const canvas = createCanvas(base.width, base.height);
const ctx = canvas.getContext("2d"); const ctx = canvas.getContext(`2d`);
image1 = await loadImage(image1); image1 = await loadImage(image1);
ctx.fillStyle = "white"; ctx.fillStyle = `white`;
ctx.fillRect(0, 0, base.width, base.height); ctx.fillRect(0, 0, base.width, base.height);
ctx.drawImage(image1, 15, 20, 440, 440); ctx.drawImage(image1, 15, 20, 440, 440);
ctx.drawImage(base, 0, 0); ctx.drawImage(base, 0, 0);
return canvas.toBuffer() return canvas.toBuffer();
} }
} };
// -N²O Pyro ;)

@ -1,4 +1,4 @@
const Canvas = require("canvas"); const Canvas = require(`canvas`);
module.exports = class ConfusedStonk { module.exports = class ConfusedStonk {
/** /**
@ -15,4 +15,4 @@ module.exports = class ConfusedStonk {
ctx.drawImage(background, 0, 0, 1994, 1296); ctx.drawImage(background, 0, 0, 1994, 1296);
return canvas.toBuffer(); return canvas.toBuffer();
} }
} };

@ -1,4 +1,4 @@
const jimp = require("jimp"); const jimp = require(`jimp`);
module.exports = class Delete { module.exports = class Delete {
/** /**
@ -17,4 +17,4 @@ module.exports = class Delete {
}); });
return raw; return raw;
} }
} };

@ -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();
}
};

@ -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();
}
};

@ -1,4 +1,4 @@
const jimp = require("jimp"); const jimp = require(`jimp`);
module.exports = class DoubleStonk { module.exports = class DoubleStonk {
/** /**
@ -7,8 +7,8 @@ module.exports = class DoubleStonk {
* @param {image} image2 * @param {image} image2
*/ */
async getImage(image1, image2) { async getImage(image1, image2) {
if (!image1) throw new Error("You must provide an image as a first 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."); if (!image2) throw new Error(`You must provide an image as a second argument.`);
let base = await jimp.read(`${__dirname}/../../assets/doubleStonk.png`); let base = await jimp.read(`${__dirname}/../../assets/doubleStonk.png`);
image1 = await jimp.read(image1); image1 = await jimp.read(image1);
image2 = await jimp.read(image2); image2 = await jimp.read(image2);
@ -20,9 +20,9 @@ module.exports = class DoubleStonk {
base.composite(image2, 60, 20); base.composite(image2, 60, 20);
base.composite(image1, 0, 30); base.composite(image1, 0, 30);
let raw; let raw;
base.getBuffer("image/png", (err, buffer) => { base.getBuffer(`image/png`, (err, buffer) => {
raw = buffer; raw = buffer;
}); });
return raw; return raw;
} }
} };

@ -1,4 +1,4 @@
const Canvas = require("canvas"); const Canvas = require(`canvas`);
module.exports = class Facepalm { module.exports = class Facepalm {
/** /**
@ -6,10 +6,10 @@ module.exports = class Facepalm {
* @param {image} image * @param {image} image
*/ */
async getImage(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 canvas = Canvas.createCanvas(632, 357);
let ctx = canvas.getContext("2d"); let ctx = canvas.getContext(`2d`);
ctx.fillStyle = "black"; ctx.fillStyle = `black`;
ctx.fillRect(0, 0, 632, 357); ctx.fillRect(0, 0, 632, 357);
let avatar = await Canvas.loadImage(image); let avatar = await Canvas.loadImage(image);
ctx.drawImage(avatar, 199, 112, 235, 235); ctx.drawImage(avatar, 199, 112, 235, 235);
@ -17,4 +17,4 @@ module.exports = class Facepalm {
ctx.drawImage(layer, 0, 0, 632, 357); ctx.drawImage(layer, 0, 0, 632, 357);
return canvas.toBuffer(); return canvas.toBuffer();
} }
} };

@ -1,4 +1,4 @@
const jimp = require("jimp"); const jimp = require(`jimp`);
module.exports = class Hitler { module.exports = class Hitler {
/** /**
@ -17,4 +17,4 @@ module.exports = class Hitler {
}); });
return raw; return raw;
} }
} };

@ -1,4 +1,4 @@
const Canvas = require("canvas"); const Canvas = require(`canvas`);
module.exports = class Jail { module.exports = class Jail {
/** /**
@ -15,4 +15,4 @@ module.exports = class Jail {
ctx.drawImage(bg, 0, 0, 400, 400); ctx.drawImage(bg, 0, 0, 400, 400);
return canvas.toBuffer(); return canvas.toBuffer();
} }
} };

@ -1,4 +1,4 @@
const jimp = require("jimp"); const jimp = require(`jimp`);
module.exports = class Kiss { module.exports = class Kiss {
/** /**
@ -25,4 +25,4 @@ module.exports = class Kiss {
}); });
return raw; return raw;
} }
} };

@ -1,53 +1,21 @@
const { createCanvas, loadImage, registerFont } = require('canvas'); const { createCanvas, loadImage, registerFont } = require(`canvas`);
registerFont(`${__dirname}/../../assets/fonts/Noto-Regular.ttf`, { family: 'Noto' }); registerFont(`${__dirname}/../../assets/fonts/Noto-Regular.ttf`, { family: `Noto` });
registerFont(`${__dirname}/../../assets/fonts/Noto-Emoji.ttf`, { family: 'Noto' }); registerFont(`${__dirname}/../../assets/fonts/Noto-Emoji.ttf`, { family: `Noto` });
const path = require("path"); const path = require(`path`);
const { wrapText } = require(`../functions`);
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);
});
}
module.exports = class LisaPresentation { module.exports = class LisaPresentation {
async getImage(text) { 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) 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 base = await loadImage(path.join(`${__dirname}/../../assets/lisa-presentation.png`));
const canvas = createCanvas(base.width, base.height); const canvas = createCanvas(base.width, base.height);
const ctx = canvas.getContext('2d'); const ctx = canvas.getContext(`2d`);
ctx.drawImage(base, 0, 0); ctx.drawImage(base, 0, 0);
ctx.textAlign = 'center'; ctx.textAlign = `center`;
ctx.textBaseline = 'top'; ctx.textBaseline = `top`;
ctx.font = '40px Noto'; ctx.font = `40px Noto`;
let fontSize = 40; let fontSize = 40;
while (ctx.measureText(text).width > 1320) { while (ctx.measureText(text).width > 1320) {
fontSize -= 1; fontSize -= 1;
@ -63,4 +31,4 @@ module.exports = class LisaPresentation {
return canvas.toBuffer(); return canvas.toBuffer();
} }
} };

@ -1,4 +1,4 @@
const Canvas = require("canvas"); const Canvas = require(`canvas`);
module.exports = class Mms { module.exports = class Mms {
/** /**
@ -15,4 +15,4 @@ module.exports = class Mms {
ctx.drawImage(bg, 0, 0, 400, 400); ctx.drawImage(bg, 0, 0, 400, 400);
return canvas.toBuffer(); return canvas.toBuffer();
} }
} };

@ -1,4 +1,4 @@
const Canvas = require("canvas"); const Canvas = require(`canvas`);
module.exports = class NotStonk { module.exports = class NotStonk {
/** /**
@ -13,6 +13,6 @@ module.exports = class NotStonk {
const background = await Canvas.loadImage(`${__dirname}/../../assets/notStonk.png`); const background = await Canvas.loadImage(`${__dirname}/../../assets/notStonk.png`);
ctx.drawImage(image1, 140, 5, 190, 190); ctx.drawImage(image1, 140, 5, 190, 190);
ctx.drawImage(background, 0, 0, 960, 576); ctx.drawImage(background, 0, 0, 960, 576);
return canvas.toBuffer(); return canvas.tofBuffer();
} }
} };

@ -1,7 +1,7 @@
const Canvas = require("canvas"); const Canvas = require(`canvas`);
const { const {
applyText applyText
} = require("../functions") } = require(`../functions`);
module.exports = class Podium { module.exports = class Podium {
/** /**
@ -34,26 +34,26 @@ module.exports = class Podium {
if (name1.length > 5) maxWidth = 150; if (name1.length > 5) maxWidth = 150;
if (name1.length > 10) maxWidth = 250; if (name1.length > 10) maxWidth = 250;
if (name1.length > 20) maxWidth = 350; if (name1.length > 20) maxWidth = 350;
ctx.textAlign = 'center'; ctx.textAlign = `center`;
ctx.font = applyText(canvas, name1, 80, maxWidth, "Comic Sans MS"); ctx.font = applyText(canvas, name1, 80, maxWidth, `Comic Sans MS`);
ctx.fillStyle = `#513d34`; ctx.fillStyle = `#513d34`;
ctx.fillText(name1, 580, 575); ctx.fillText(name1, 580, 575);
maxWidth = 80; maxWidth = 80;
if (name2.length > 5) maxWidth = 150; if (name2.length > 5) maxWidth = 150;
if (name2.length > 10) maxWidth = 180; if (name2.length > 10) maxWidth = 180;
if (name2.length > 20) maxWidth = 240; if (name2.length > 20) maxWidth = 240;
ctx.textAlign = 'center'; ctx.textAlign = `center`;
ctx.font = applyText(canvas, name2, 50, maxWidth, "Comic Sans MS"); ctx.font = applyText(canvas, name2, 50, maxWidth, `Comic Sans MS`);
ctx.fillStyle = `#513d34`; ctx.fillStyle = `#513d34`;
ctx.fillText(name2, 210, 540); ctx.fillText(name2, 210, 540);
maxWidth = 80; maxWidth = 80;
if (name3.length > 5) maxWidth = 150; if (name3.length > 5) maxWidth = 150;
if (name3.length > 10) maxWidth = 180; if (name3.length > 10) maxWidth = 180;
if (name3.length > 20) maxWidth = 240; if (name3.length > 20) maxWidth = 240;
ctx.textAlign = 'center'; ctx.textAlign = `center`;
ctx.font = applyText(canvas, name3, 50, maxWidth, "Comic Sans MS"); ctx.font = applyText(canvas, name3, 50, maxWidth, `Comic Sans MS`);
ctx.fillStyle = `#513d34`; ctx.fillStyle = `#513d34`;
ctx.fillText(name3, 970, 540); ctx.fillText(name3, 970, 540);
return canvas.toBuffer(); return canvas.toBuffer();
} }
} };

@ -1,4 +1,4 @@
const Canvas = require("canvas"); const Canvas = require(`canvas`);
module.exports = class Poutine { module.exports = class Poutine {
/** /**
@ -15,4 +15,4 @@ module.exports = class Poutine {
ctx.drawImage(background, 0, 0, 600, 539); ctx.drawImage(background, 0, 0, 600, 539);
return canvas.toBuffer(); return canvas.toBuffer();
} }
} };

@ -1,4 +1,4 @@
const Canvas = require("canvas"); const Canvas = require(`canvas`);
module.exports = class Rip { module.exports = class Rip {
/** /**
@ -16,4 +16,4 @@ module.exports = class Rip {
ctx.drawImage(background, 0, 0, canvas.width, canvas.height); ctx.drawImage(background, 0, 0, canvas.width, canvas.height);
return canvas.toBuffer(); return canvas.toBuffer();
} }
} };

@ -1,4 +1,4 @@
const jimp = require("jimp"); const jimp = require(`jimp`);
module.exports = class Spank { module.exports = class Spank {
/** /**
@ -27,4 +27,4 @@ module.exports = class Spank {
}); });
return raw; return raw;
} }
} };

@ -1,4 +1,4 @@
const Canvas = require("canvas"); const Canvas = require(`canvas`);
module.exports = class Stonk { module.exports = class Stonk {
/** /**
@ -15,4 +15,4 @@ module.exports = class Stonk {
ctx.drawImage(background, 0, 0, 900, 539); ctx.drawImage(background, 0, 0, 900, 539);
return canvas.toBuffer(); return canvas.toBuffer();
} }
} };

@ -1,4 +1,4 @@
const Canvas = require("canvas"); const Canvas = require(`canvas`);
module.exports = class Tatoo { module.exports = class Tatoo {
/** /**
@ -15,4 +15,4 @@ module.exports = class Tatoo {
ctx.drawImage(background, 0, 0, 750, 1089); ctx.drawImage(background, 0, 0, 750, 1089);
return canvas.toBuffer(); return canvas.toBuffer();
} }
} };

@ -1,4 +1,4 @@
const Canvas = require("canvas"); const Canvas = require(`canvas`);
module.exports = class Thomas { module.exports = class Thomas {
/** /**
@ -15,4 +15,4 @@ module.exports = class Thomas {
ctx.drawImage(background, 0, 0, 841, 1058); ctx.drawImage(background, 0, 0, 841, 1058);
return canvas.toBuffer(); return canvas.toBuffer();
} }
} };

@ -1,4 +1,4 @@
const jimp = require("jimp"); const jimp = require(`jimp`);
module.exports = class Trash { module.exports = class Trash {
/** /**
@ -18,4 +18,4 @@ module.exports = class Trash {
}); });
return raw; return raw;
} }
} };

@ -1,4 +1,4 @@
const Canvas = require("canvas"); const Canvas = require(`canvas`);
const { const {
applyText applyText
} = require(`../functions`); } = require(`../functions`);
@ -8,21 +8,21 @@ module.exports = class Wanted {
* Wanted * Wanted
* @param {image} image * @param {image} image
*/ */
async getImage(image, currency = "$") { async getImage(image, currency = `$`) {
if (!image) throw new Error(`You must provide an image.`); 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 (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 (currency.length > 1) throw new Error(`You must provide only one character for the currency.`);
var price = Math.floor(Math.random() * 188708) + 329889 var price = Math.floor(Math.random() * 188708) + 329889;
const canvas = Canvas.createCanvas(257, 383); const canvas = Canvas.createCanvas(257, 383);
const ctx = canvas.getContext(`2d`); const ctx = canvas.getContext(`2d`);
const avatar = await Canvas.loadImage(image); const avatar = await Canvas.loadImage(image);
const background = await Canvas.loadImage(`${__dirname}/../../assets/wanted.png`); const background = await Canvas.loadImage(`${__dirname}/../../assets/wanted.png`);
ctx.drawImage(avatar, 25, 60, 210, 210); ctx.drawImage(avatar, 25, 60, 210, 210);
ctx.drawImage(background, 0, 0, 257, 383); ctx.drawImage(background, 0, 0, 257, 383);
ctx.textAlign = 'center'; ctx.textAlign = `center`;
ctx.font = applyText(canvas, price.toLocaleString() + currency, 80, 200, "Times New Roman"); ctx.font = applyText(canvas, price.toLocaleString() + currency, 80, 200, `Times New Roman`);
ctx.fillStyle = `#513d34` ctx.fillStyle = `#513d34`;
ctx.fillText(price.toLocaleString() + currency, 128, 315) ctx.fillText(price.toLocaleString() + currency, 128, 315);
return canvas.toBuffer(); return canvas.toBuffer();
} }
} };

@ -1,4 +1,4 @@
const jimp = require("jimp"); const jimp = require(`jimp`);
module.exports = class Circle { module.exports = class Circle {
/** /**
@ -16,4 +16,4 @@ module.exports = class Circle {
}); });
return raw; return raw;
} }
} };

@ -1,4 +1,4 @@
const Canvas = require("canvas"); const Canvas = require(`canvas`);
module.exports = class Color { module.exports = class Color {
/** /**
@ -12,4 +12,4 @@ module.exports = class Color {
ctx.fillRect(0, 0, canvas.width, canvas.height); ctx.fillRect(0, 0, canvas.width, canvas.height);
return canvas.toBuffer(); return canvas.toBuffer();
} }
} };
Loading…
Cancel
Save