Version 1.4.0
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
|
||||||
|
},
|
||||||
|
};
|
Binary file not shown.
After Width: | Height: | Size: 88 KiB |
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
@ -1,15 +1,15 @@
|
|||||||
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,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 ;)
|
|
||||||
|
@ -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,66 +1,34 @@
|
|||||||
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;
|
||||||
ctx.font = `${fontSize}px Noto`;
|
ctx.font = `${fontSize}px Noto`;
|
||||||
}
|
}
|
||||||
const lines = await wrapText(ctx, text, 330);
|
const lines = await wrapText(ctx, text, 330);
|
||||||
const topMost = 185 - (((fontSize * lines.length) / 2) + ((20 * (lines.length - 1)) / 2));
|
const topMost = 185 - (((fontSize * lines.length) / 2) + ((20 * (lines.length - 1)) / 2));
|
||||||
for (let i = 0; i < lines.length; i++) {
|
for (let i = 0; i < lines.length; i++) {
|
||||||
const height = topMost + ((fontSize + 20) * i);
|
const height = topMost + ((fontSize + 20) * i);
|
||||||
ctx.fillText(lines[i], base.width / 2, height);
|
ctx.fillText(lines[i], base.width / 2, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
return canvas.toBuffer();
|
return canvas.toBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
};
|
Loading…
Reference in New Issue