diff --git a/commands/edit-image/yu-gi-oh-gen.js b/commands/edit-image/yu-gi-oh-gen.js index 6c2fc26a..17a03f36 100644 --- a/commands/edit-image/yu-gi-oh-gen.js +++ b/commands/edit-image/yu-gi-oh-gen.js @@ -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`