From 3cd67819d61ed75778a8892b85079a66fb1bbc6e Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Sun, 28 Apr 2024 14:55:13 -0400 Subject: [PATCH] Draw border around image in tweet --- commands/edit-image-text/tweet.js | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/commands/edit-image-text/tweet.js b/commands/edit-image-text/tweet.js index 70ddbff2..24f678f2 100644 --- a/commands/edit-image-text/tweet.js +++ b/commands/edit-image-text/tweet.js @@ -90,19 +90,13 @@ module.exports = class TweetCommand extends Command { const y = 0; const imageWidth = 740; const radius = 15; - imageCtx.beginPath(); - imageCtx.moveTo(x + radius, y); - imageCtx.lineTo(x + imageWidth - radius, y); - imageCtx.quadraticCurveTo(x + imageWidth, y, x + imageWidth, y + radius); - imageCtx.lineTo(x + imageWidth, y + imageHeight - radius); - imageCtx.quadraticCurveTo(x + imageWidth, y + imageHeight, x + imageWidth - radius, y + imageHeight); - imageCtx.lineTo(x + radius, y + imageHeight); - imageCtx.quadraticCurveTo(x, y + imageHeight, x, y + imageHeight - radius); - imageCtx.lineTo(x, y + radius); - imageCtx.quadraticCurveTo(x, y, x + radius, y); - imageCtx.closePath(); + this.createImageBorder(imageCtx, radius, x, y, imageWidth, imageHeight); imageCtx.clip(); imageCtx.drawImage(imageData, 0, 0, imageWidth, imageHeight); + this.createImageBorder(imageCtx, radius, x, y, imageWidth, imageHeight); + imageCtx.strokeStyle = '#303336'; + imageCtx.lineWidth = 10; + imageCtx.stroke(); ctx.drawImage(imageCanvas, 17, base1.height + linesLen, imageWidth, imageHeight); } const likes = randomRange(Math.ceil(userData.followers * 0.0015), Math.ceil(userData.followers * 0.002)); @@ -202,6 +196,21 @@ module.exports = class TweetCommand extends Command { return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'tweet.png' }] }); } + roundedPath(ctx, radius, x, y, imageHeight, imageWidth) { + ctx.beginPath(); + ctx.moveTo(x + radius, y); + ctx.lineTo(x + imageWidth - radius, y); + ctx.quadraticCurveTo(x + imageWidth, y, x + imageWidth, y + radius); + ctx.lineTo(x + imageWidth, y + imageHeight - radius); + ctx.quadraticCurveTo(x + imageWidth, y + imageHeight, x + imageWidth - radius, y + imageHeight); + ctx.lineTo(x + radius, y + imageHeight); + ctx.quadraticCurveTo(x, y + imageHeight, x, y + imageHeight - radius); + ctx.lineTo(x, y + radius); + ctx.quadraticCurveTo(x, y, x + radius, y); + ctx.closePath(); + return ctx; + } + async fillTextWithEmoji(ctx, text, x, y, maxLineLen, emojiSize) { const wrapped = wrapText(ctx, text, maxLineLen, true); const emoji = text.match(emojiRegex());