Added lisapresentation
This commit is contained in:
@@ -143,6 +143,12 @@ bot.login("super_secret_token")
|
|||||||
|
|
||||||
- ``new DIG.Mms().getImage(`<Avatar>`);``
|
- ``new DIG.Mms().getImage(`<Avatar>`);``
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
- ``new DIG.LisaPresentation().getImage(`<Text>`);``
|
||||||
|
|
||||||
|
> Limited to 300char
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
- ``new DIG.Rip().getImage(`<Avatar>`);``
|
- ``new DIG.Rip().getImage(`<Avatar>`);``
|
||||||
@@ -186,6 +192,9 @@ bot.login("super_secret_token")
|
|||||||
|
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## v1.1.5
|
||||||
|
- Added LisaPresentation
|
||||||
|
|
||||||
## v1.1.2
|
## v1.1.2
|
||||||
- Fixed invalid path
|
- Fixed invalid path
|
||||||
- Moved assets folder
|
- Moved assets folder
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "discord-image-generation",
|
"name": "discord-image-generation",
|
||||||
"version": "1.1.4",
|
"version": "1.1.5",
|
||||||
"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": {
|
||||||
|
BIN
src/assets/fonts/Noto-Emoji.ttf
Normal file
BIN
src/assets/fonts/Noto-Emoji.ttf
Normal file
Binary file not shown.
BIN
src/assets/fonts/Noto-Regular.ttf
Normal file
BIN
src/assets/fonts/Noto-Regular.ttf
Normal file
Binary file not shown.
BIN
src/assets/lisa-presentation.png
Normal file
BIN
src/assets/lisa-presentation.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 172 KiB |
@@ -16,6 +16,7 @@ Facepalm = require('./module/montage/facepalm')
|
|||||||
Hitler = require('./module/montage/hitler')
|
Hitler = require('./module/montage/hitler')
|
||||||
Jail = require('./module/montage/jail')
|
Jail = require('./module/montage/jail')
|
||||||
Kiss = require('./module/montage/kiss')
|
Kiss = require('./module/montage/kiss')
|
||||||
|
LisaPresentation = require('./module/montage/lisa-presentation')
|
||||||
Mms = require('./module/montage/mms')
|
Mms = require('./module/montage/mms')
|
||||||
Rip = require('./module/montage/rip')
|
Rip = require('./module/montage/rip')
|
||||||
Spank = require('./module/montage/spank')
|
Spank = require('./module/montage/spank')
|
||||||
@@ -44,6 +45,7 @@ module.exports = {
|
|||||||
Hitler,
|
Hitler,
|
||||||
Jail,
|
Jail,
|
||||||
Kiss,
|
Kiss,
|
||||||
|
LisaPresentation,
|
||||||
Mms,
|
Mms,
|
||||||
Rip,
|
Rip,
|
||||||
Spank,
|
Spank,
|
||||||
|
66
src/module/montage/lisa-presentation.js
Normal file
66
src/module/montage/lisa-presentation.js
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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.`)
|
||||||
|
|
||||||
|
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 height = topMost + ((fontSize + 20) * i);
|
||||||
|
ctx.fillText(lines[i], base.width / 2, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
return canvas.toBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user