From 3b357748827e0fca0440d15b02474f4f19920747 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Fri, 14 Sep 2018 01:38:34 +0000 Subject: [PATCH] scale height too --- commands/image-edit/demotivational-poster.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/commands/image-edit/demotivational-poster.js b/commands/image-edit/demotivational-poster.js index 8444028e..3d52e175 100644 --- a/commands/image-edit/demotivational-poster.js +++ b/commands/image-edit/demotivational-poster.js @@ -51,15 +51,18 @@ module.exports = class DemotivationalPosterCommand extends Command { ctx.fillStyle = 'black'; ctx.fillRect(0, 0, canvas.width, canvas.height); const ratio = data.width / data.height; - const width = Math.min(Math.round(402 / ratio), 602); + const widthHigher = width >= height; + const width = widthHigher ? 602 : Math.min(Math.round(402 / ratio), 602); + const height = widthHigher ? Math.min(Math.round(602 * ratio), 402) : 402; const x = (canvas.width / 2) - (width / 2); + const y = (402 / 2) - (height / 2); ctx.fillStyle = 'white'; - ctx.fillRect(x - 4, 40, width + 8, 410); + ctx.fillRect(x - 4, y - 4, width + 8, height + 8); ctx.fillStyle = 'black'; - ctx.fillRect(x - 2, 42, width + 4, 406); + ctx.fillRect(x - 2, y - 2, width + 4, height + 4); ctx.fillStyle = 'white'; - ctx.fillRect(x, 44, width, 402); - ctx.drawImage(data, x, 44, width, 402); + ctx.fillRect(x, y, width, height); + ctx.drawImage(data, x, y, width, height); ctx.textAlign = 'center'; ctx.font = '60px Noto'; ctx.fillStyle = 'aquamarine';