diff --git a/commands/edit-image-text/tweet.js b/commands/edit-image-text/tweet.js index 307a6a38..685e481e 100644 --- a/commands/edit-image-text/tweet.js +++ b/commands/edit-image-text/tweet.js @@ -83,25 +83,27 @@ module.exports = class TweetCommand extends Command { const imageData = await loadImage(body); const imageHeightRatio = 740 / imageData.width; imageHeight = imageData.height * imageHeightRatio; + const imageCanvas = createCanvas(740, imageHeight); + const imageCtx = imageCanvas.getContext('2d'); canvas.height += imageHeight + 15; ctx.fillRect(0, base1.height, canvas.width, linesLen + imageHeight + 15); const x = 17; const y = base1.height + linesLen; const imageWidth = 740; const radius = 10; - 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(); - ctx.clip(); - ctx.drawImage(imageData, x, y, imageWidth, imageHeight); + 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(); + imageCtx.clip(); + ctx.drawImage(imageCanvas, x, y, imageWidth, imageHeight); } const likes = randomRange(Math.ceil(userData.followers * 0.0015), Math.ceil(userData.followers * 0.002)); const retweets = randomRange(Math.ceil(userData.followers * 0.00015), Math.ceil(userData.followers * 0.0002));