From 833c388b9849a2aa6e4a4744511c8b9554bc7572 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Sun, 31 May 2020 12:11:19 -0400 Subject: [PATCH] Fix --- commands/edit-meme/meme-gen-modern.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/commands/edit-meme/meme-gen-modern.js b/commands/edit-meme/meme-gen-modern.js index 02a44f54..10a10ae9 100644 --- a/commands/edit-meme/meme-gen-modern.js +++ b/commands/edit-meme/meme-gen-modern.js @@ -2,6 +2,7 @@ const Command = require('../../structures/Command'); const { createCanvas, loadImage, registerFont } = require('canvas'); const request = require('node-superfetch'); const path = require('path'); +const { wrapText } = 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' }); @@ -19,8 +20,7 @@ module.exports = class MemeGenModernCommand extends Command { 'create-modern-meme', 'm-meme-gen', 'm-meme-generator', - 'create-m-meme', - + 'create-m-meme' ], group: 'edit-meme', memberName: 'meme-gen-modern', @@ -58,14 +58,12 @@ module.exports = class MemeGenModernCommand extends Command { try { const { body } = await request.get(image); const base = await loadImage(body); - const scaleH = plate.width / base.width; - const height = Math.round(base.height * scaleH); - const canvas = createCanvas(plate.width, plate.height + height); + const canvas = createCanvas(body.width, body.height); const ctx = canvas.getContext('2d'); ctx.font = '23px Noto'; ctx.fillStyle = 'black'; ctx.textBaseline = 'top'; - const lines = await wrapText(ctx, text, plate.width - 10); + const lines = await wrapText(ctx, text, base.width - 10); const linesLen = (23 * lines.length) + (23 * (text.split('\n').length - 1)) + (9 * lines.length); canvas.height += linesLen; ctx.fillStyle = 'white';