From 0121d342ff8f91cc5b2641b3c5dc505061c6826c Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Wed, 12 Sep 2018 12:27:21 +0000 Subject: [PATCH] Improve text centering in nike-ad --- commands/image-edit/nike-ad.js | 12 ++++++++---- package.json | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/commands/image-edit/nike-ad.js b/commands/image-edit/nike-ad.js index 0b71c7b1..12027ea8 100644 --- a/commands/image-edit/nike-ad.js +++ b/commands/image-edit/nike-ad.js @@ -58,12 +58,16 @@ module.exports = class NikeAdCommand extends Command { const width = data.width / 3; const height = Math.round(width / ratio); ctx.drawImage(base, (data.width / 2) - (width / 2), data.height - height, width, height); - ctx.font = `${Math.round(data.height / 25)}px Noto`; + const fontSize = Math.round(data.height / 25); + ctx.font = `${fontSize}px Noto`; ctx.fillStyle = 'white'; ctx.textAlign = 'center'; - ctx.textBaseline = 'middle'; - const text = wrapText(ctx, `Believe in ${something}. Even if it means ${sacrifice}.`, data.width); - ctx.fillText(text.join('\n'), data.width / 2, data.height / 2); + const lines = wrapText(ctx, `Believe in ${something}. Even if it means ${sacrifice}.`, data.width); + const initial = data.height / 2; + for (let i = 0; i < lines.length; i++) { + const height = initial + (i * fontSize) + (i * 10); + ctx.fillText(lines[i], data.width / 2, height); + } const attachment = canvas.toBuffer(); if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.'); return msg.say({ files: [{ attachment, name: 'nike-ad.png' }] }); diff --git a/package.json b/package.json index 440c2a4e..cc146773 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "91.1.1", + "version": "91.1.2", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {