scale height too

This commit is contained in:
Daniel Odendahl Jr
2018-09-14 01:38:34 +00:00
parent 4e920ac4a7
commit 3b35774882
+8 -5
View File
@@ -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';