Square image properly in ygogen

This commit is contained in:
Dragon Fire
2021-02-21 21:49:34 -05:00
parent 784bb70bf2
commit 76697b1a8f
+9 -2
View File
@@ -99,8 +99,7 @@ module.exports = class YuGiOhGenCommand extends Command {
const ctx = canvas.getContext('2d');
ctx.fillStyle = 'white';
ctx.fillRect(0, 0, base.width, base.height);
const height = 617 / data.width;
ctx.drawImage(data, 98, 217, 617, data.height * height);
ctx.drawImage(this.squareImage(data), 98, 217, 617, 617);
ctx.drawImage(base, 0, 0);
ctx.drawImage(atr, 686, 55 + (monsterType === 'link' ? 4 : 0), 70, 70);
if (level > 0) {
@@ -154,6 +153,14 @@ module.exports = class YuGiOhGenCommand extends Command {
}
}
squareImage(image) {
const dimensions = image.width <= image.height ? image.width : image.height;
const canvas = createCanvas(dimensions, dimensions);
const ctx = canvas.getContext('2d');
ctx.drawImage(image, (canvas.width / 2) - (image.width / 2), 0);
return canvas;
}
async determineMonsterType(msg, type) {
if (type !== 'monster') return type;
await msg.reply(stripIndents`