v1.2.9 Bugs fixes and nex generations
This commit is contained in:
21
README.md
21
README.md
@@ -105,6 +105,10 @@ bot.login("super_secret_token")
|
|||||||
|
|
||||||
## Montage
|
## Montage
|
||||||
|
|
||||||
|
- ``new DIG.Ad().getImage(`<Avatar>`);``
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
- ``new DIG.Affect().getImage(`<Avatar>`);``
|
- ``new DIG.Affect().getImage(`<Avatar>`);``
|
||||||
|
|
||||||

|

|
||||||
@@ -152,6 +156,14 @@ bot.login("super_secret_token")
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
- ``new DIG.Podium().getImage(`<Avatar1>, <Avatar2>, <Avatar2>, <Name1>, <Name2>, <Name3>`);``
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
- ``new DIG.Poutine().getImage(`<Avatar>`);``
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
- ``new DIG.Rip().getImage(`<Avatar>`);``
|
- ``new DIG.Rip().getImage(`<Avatar>`);``
|
||||||
|
|
||||||

|

|
||||||
@@ -176,7 +188,7 @@ bot.login("super_secret_token")
|
|||||||
|
|
||||||
> Currency ($, €, ...)
|
> Currency ($, €, ...)
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|
||||||
## Utils
|
## Utils
|
||||||
@@ -193,6 +205,13 @@ bot.login("super_secret_token")
|
|||||||
|
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## v1.2.9
|
||||||
|
- Added Podium()
|
||||||
|
- Added Ad()
|
||||||
|
- Added Poutine()
|
||||||
|
- Fixed Wanted()
|
||||||
|
- Bumped jimp from ^0.13.0 to ^0.14.0
|
||||||
|
|
||||||
## v1.1.5
|
## v1.1.5
|
||||||
- Added LisaPresentation
|
- Added LisaPresentation
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "discord-image-generation",
|
"name": "discord-image-generation",
|
||||||
"version": "1.1.9",
|
"version": "1.2.9",
|
||||||
"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": {
|
||||||
@@ -31,6 +31,6 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"canvas": "^2.6.1",
|
"canvas": "^2.6.1",
|
||||||
"gifencoder": "^2.0.1",
|
"gifencoder": "^2.0.1",
|
||||||
"jimp": "^0.13.0"
|
"jimp": "^0.14.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
BIN
src/assets/ad.png
Normal file
BIN
src/assets/ad.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 318 KiB |
BIN
src/assets/podium.png
Normal file
BIN
src/assets/podium.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 184 KiB |
BIN
src/assets/poutine.png
Normal file
BIN
src/assets/poutine.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 501 KiB |
@@ -7,6 +7,7 @@ Sepia = require('./module/filters/sepia')
|
|||||||
Triggered = require('./module/gif/triggered')
|
Triggered = require('./module/gif/triggered')
|
||||||
Blink = require('./module/gif/blink')
|
Blink = require('./module/gif/blink')
|
||||||
|
|
||||||
|
Ad = require('./module/montage/ad')
|
||||||
Affect = require('./module/montage/affect')
|
Affect = require('./module/montage/affect')
|
||||||
Batslap = require('./module/montage/batslap')
|
Batslap = require('./module/montage/batslap')
|
||||||
Beautiful = require('./module/montage/beautiful')
|
Beautiful = require('./module/montage/beautiful')
|
||||||
@@ -18,6 +19,8 @@ Jail = require('./module/montage/jail')
|
|||||||
Kiss = require('./module/montage/kiss')
|
Kiss = require('./module/montage/kiss')
|
||||||
LisaPresentation = require('./module/montage/lisa-presentation')
|
LisaPresentation = require('./module/montage/lisa-presentation')
|
||||||
Mms = require('./module/montage/mms')
|
Mms = require('./module/montage/mms')
|
||||||
|
Podium = require('./module/montage/podium')
|
||||||
|
Poutine = require('./module/montage/poutine')
|
||||||
Rip = require('./module/montage/rip')
|
Rip = require('./module/montage/rip')
|
||||||
Spank = require('./module/montage/spank')
|
Spank = require('./module/montage/spank')
|
||||||
Tatoo = require('./module/montage/tatoo')
|
Tatoo = require('./module/montage/tatoo')
|
||||||
@@ -36,6 +39,7 @@ module.exports = {
|
|||||||
Sepia,
|
Sepia,
|
||||||
Triggered,
|
Triggered,
|
||||||
Blink,
|
Blink,
|
||||||
|
Ad,
|
||||||
Affect,
|
Affect,
|
||||||
Batslap,
|
Batslap,
|
||||||
Beautiful,
|
Beautiful,
|
||||||
@@ -47,6 +51,8 @@ module.exports = {
|
|||||||
Kiss,
|
Kiss,
|
||||||
LisaPresentation,
|
LisaPresentation,
|
||||||
Mms,
|
Mms,
|
||||||
|
Podium,
|
||||||
|
Poutine,
|
||||||
Rip,
|
Rip,
|
||||||
Spank,
|
Spank,
|
||||||
Tatoo,
|
Tatoo,
|
||||||
|
@@ -11,8 +11,41 @@ module.exports = {
|
|||||||
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)-3}px ${font}`;
|
ctx.font = `${(defaultFontSize -= 1)}px ${font}`;
|
||||||
} while (ctx.measureText(text).width > width);
|
} while (ctx.measureText(text).width > width);
|
||||||
return ctx.font;
|
return ctx.font;
|
||||||
|
},
|
||||||
|
|
||||||
|
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);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
18
src/module/montage/ad.js
Normal file
18
src/module/montage/ad.js
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
const Canvas = require("canvas");
|
||||||
|
|
||||||
|
module.exports = class Ad {
|
||||||
|
/**
|
||||||
|
* Ad
|
||||||
|
* @param {image} image1
|
||||||
|
*/
|
||||||
|
async getImage(image1) {
|
||||||
|
if (!image1) throw new Error(`You must provide an image as 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();
|
||||||
|
}
|
||||||
|
}
|
59
src/module/montage/podium.js
Normal file
59
src/module/montage/podium.js
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
const Canvas = require("canvas");
|
||||||
|
const {
|
||||||
|
applyText
|
||||||
|
} = 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.`);
|
||||||
|
const canvas = Canvas.createCanvas(1173, 686);
|
||||||
|
const ctx = canvas.getContext(`2d`);
|
||||||
|
image1 = await Canvas.loadImage(image1);
|
||||||
|
image2 = await Canvas.loadImage(image2);
|
||||||
|
image3 = await Canvas.loadImage(image3);
|
||||||
|
const background = await Canvas.loadImage(`${__dirname}/../../assets/podium.png`);
|
||||||
|
ctx.drawImage(image1, 409, 115, 350, 350);
|
||||||
|
ctx.drawImage(image2, 96, 236, 225, 225);
|
||||||
|
ctx.drawImage(image3, 853, 236, 225, 225);
|
||||||
|
ctx.drawImage(background, 0, 0, 1173, 686);
|
||||||
|
let maxWidth = 20
|
||||||
|
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.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.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.fillStyle = `#513d34`
|
||||||
|
ctx.fillText(name3, 970, 540)
|
||||||
|
return canvas.toBuffer();
|
||||||
|
}
|
||||||
|
}
|
18
src/module/montage/poutine.js
Normal file
18
src/module/montage/poutine.js
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
const Canvas = require("canvas");
|
||||||
|
|
||||||
|
module.exports = class Poutine {
|
||||||
|
/**
|
||||||
|
* Ad
|
||||||
|
* @param {image} image1
|
||||||
|
*/
|
||||||
|
async getImage(image1) {
|
||||||
|
if (!image1) throw new Error(`You must provide an image as 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();
|
||||||
|
}
|
||||||
|
}
|
@@ -19,9 +19,10 @@ module.exports = class Wanted {
|
|||||||
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.font = applyText(canvas, price.toLocaleString() + currency, 40, 200, "Times New Roman");
|
ctx.textAlign = 'center';
|
||||||
|
ctx.font = applyText(canvas, price.toLocaleString() + currency, 80, 200, "Times New Roman");
|
||||||
ctx.fillStyle = `#513d34`
|
ctx.fillStyle = `#513d34`
|
||||||
ctx.fillText(price.toLocaleString() + currency, 54, 320)
|
ctx.fillText(price.toLocaleString() + currency, 128, 315)
|
||||||
return canvas.toBuffer();
|
return canvas.toBuffer();
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user