mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Test allowing any image to be used in meme commands
This commit is contained in:
@@ -2,6 +2,7 @@ const Command = require('../../structures/Command');
|
||||
const { createCanvas, loadImage } = require('canvas');
|
||||
const request = require('node-superfetch');
|
||||
const path = require('path');
|
||||
const { centerImagePart } = require('../../util/Canvas');
|
||||
|
||||
module.exports = class ThreeThousandYearsCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -25,10 +26,10 @@ module.exports = class ThreeThousandYearsCommand extends Command {
|
||||
],
|
||||
args: [
|
||||
{
|
||||
key: 'user',
|
||||
prompt: 'Which user would you like to edit the avatar of?',
|
||||
type: 'user',
|
||||
default: msg => msg.author
|
||||
key: 'image',
|
||||
prompt: 'What image would you like to edit?',
|
||||
type: 'image',
|
||||
default: msg => msg.author.displayAvatarURL({ format: 'png', size: 512 })
|
||||
}
|
||||
]
|
||||
});
|
||||
@@ -43,7 +44,8 @@ module.exports = class ThreeThousandYearsCommand extends Command {
|
||||
const canvas = createCanvas(base.width, base.height);
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx.drawImage(base, 0, 0);
|
||||
ctx.drawImage(avatar, 461, 127, 200, 200);
|
||||
const { x, y, width, height } = centerImagePart(avatar, 200, 200, 461, 127);
|
||||
ctx.drawImage(avatar, x, y, width, height);
|
||||
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: '3000-years.png' }] });
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
|
||||
@@ -2,7 +2,7 @@ const Command = require('../../structures/Command');
|
||||
const { createCanvas, loadImage, registerFont } = require('canvas');
|
||||
const request = require('node-superfetch');
|
||||
const path = require('path');
|
||||
const { shortenText } = require('../../util/Canvas');
|
||||
const { shortenText, centerImagePart } = require('../../util/Canvas');
|
||||
registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Noto-Regular.ttf'), { family: 'Noto' });
|
||||
registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Noto-CJK.otf'), { family: 'Noto' });
|
||||
registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Noto-Emoji.ttf'), { family: 'Noto' });
|
||||
@@ -60,21 +60,8 @@ module.exports = class DemotivationalCommand extends Command {
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx.fillStyle = 'black';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
let { width, height } = data;
|
||||
const maxWidth = 602;
|
||||
if (width > maxWidth) {
|
||||
const ratio = maxWidth / width;
|
||||
width = maxWidth;
|
||||
height *= ratio;
|
||||
}
|
||||
const maxHeight = 402;
|
||||
if (height > maxHeight) {
|
||||
const ratio = maxHeight / height;
|
||||
height = maxHeight;
|
||||
width *= ratio;
|
||||
}
|
||||
const { y, width, height } = centerImagePart(data, 602, 402, 0, 44);
|
||||
const x = (canvas.width / 2) - (width / 2);
|
||||
const y = 44 + ((402 / 2) - (height / 2));
|
||||
ctx.fillStyle = 'white';
|
||||
ctx.fillRect(x - 4, y - 4, width + 8, height + 8);
|
||||
ctx.fillStyle = 'black';
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiao",
|
||||
"version": "112.12.6",
|
||||
"version": "112.12.7",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Xiao.js",
|
||||
"scripts": {
|
||||
|
||||
@@ -146,4 +146,21 @@ module.exports = class CanvasUtil {
|
||||
}
|
||||
return { x, y, width, height };
|
||||
}
|
||||
|
||||
static centerImagePart(data, maxWidth, maxHeight, widthOffset, heightOffest) {
|
||||
let { width, height } = data;
|
||||
if (width > maxWidth) {
|
||||
const ratio = maxWidth / width;
|
||||
width = maxWidth;
|
||||
height *= ratio;
|
||||
}
|
||||
if (height > maxHeight) {
|
||||
const ratio = maxHeight / height;
|
||||
height = maxHeight;
|
||||
width *= ratio;
|
||||
}
|
||||
const x = widthOffset + ((maxWidth / 2) - (width / 2));
|
||||
const y = heightOffest + ((maxHeight / 2) - (height / 2));
|
||||
return { x, y, width, height };
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user