From f2bcd764076971c24cb54d1e68fa21cf5a65109c Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Fri, 14 Sep 2018 02:13:57 +0000 Subject: [PATCH] IT WORKS --- commands/image-edit/demotivational-poster.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/commands/image-edit/demotivational-poster.js b/commands/image-edit/demotivational-poster.js index cf98b25a..77b0b5c5 100644 --- a/commands/image-edit/demotivational-poster.js +++ b/commands/image-edit/demotivational-poster.js @@ -50,9 +50,20 @@ module.exports = class DemotivationalPosterCommand extends Command { const ctx = canvas.getContext('2d'); ctx.fillStyle = 'black'; ctx.fillRect(0, 0, canvas.width, canvas.height); - const ratio = data.width / data.height; - const width = Math.min(Math.round(data.height / ratio), 602); - const height = Math.min(Math.round(data.width * ratio), 402); + let width = data.width; + let height = data.height; + const maxWidth = 602; + if (width > maxWidth) { + const ratio = maxWidth / width; + width = maxWidth; + height = height * ratio; + } + const maxHeight = 402; + if (height > maxHeight) { + const ratio = maxHeight / height; + height = maxHeight; + width = width * ratio; + } const x = (canvas.width / 2) - (width / 2); const y = 44 + ((402 / 2) - (height / 2)); ctx.fillStyle = 'white';