diff --git a/commands/edit-image-text/spongebob-time-card.js b/commands/edit-image-text/spongebob-time-card.js index a1343398..529be820 100644 --- a/commands/edit-image-text/spongebob-time-card.js +++ b/commands/edit-image-text/spongebob-time-card.js @@ -57,11 +57,18 @@ module.exports = class SpongebobTimeCardCommand extends Command { ctx.drawImage(base, 0, 0); ctx.textAlign = 'center'; ctx.textBaseline = 'top'; - ctx.font = this.client.fonts.get('Spongeboytt1.ttf').toCanvasString(115); const lines = wrapText(ctx, text.toUpperCase(), 1800); - const topMost = (canvas.height / 2) - (((115 * lines.length) / 2) + ((60 * (lines.length - 1)) / 2)); + let fontSize = 345; + ctx.font = this.client.fonts.get('Spongeboytt1.ttf').toCanvasString(fontSize); + let metrics = ctx.measureText(lines.join('\n')); + while (metrics.width > 1800 || (metrics.actualBoundingBoxAscent + metrics.actualBoundingBoxDescent) > 1000) { + fontSize -= 10; + ctx.font = this.client.fonts.get('Spongeboytt1.ttf').toCanvasString(fontSize); + metrics = ctx.measureText(lines.join('\n')); + } + const topMost = (canvas.height / 2) - (((fontSize * lines.length) / 2) + ((60 * (lines.length - 1)) / 2)); for (let i = 0; i < lines.length; i++) { - const height = topMost + ((115 + 60) * i); + const height = topMost + ((fontSize + 60) * i); ctx.fillStyle = '#ecbd3b'; ctx.fillText(lines[i], (canvas.width / 2) + 6, height + 6); ctx.fillStyle = 'black';