From 469320c31aa53c9bddc253b0ce7b23a237fe6dff Mon Sep 17 00:00:00 2001 From: lolcat Date: Mon, 30 Dec 2024 22:45:03 -0500 Subject: [PATCH] added cap --- client.js | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 84 insertions(+), 2 deletions(-) diff --git a/client.js b/client.js index 68ea1f5..baa3a46 100644 --- a/client.js +++ b/client.js @@ -6,6 +6,7 @@ const formdata = require("form-data"); const he = require("he"); const cheerio = require("cheerio"); const sharp = require("sharp"); +const { createCanvas, loadImage } = require("canvas"); var mmm = require("mmmagic"); var Magic = mmm.Magic; @@ -679,7 +680,7 @@ deek.on("login", function(channel){ }); // @TODO remove -var last_image = "https://deek.chat/storage/files/Dek1873481580533551104.png"; +var last_image = "https://deek.chat/storage/files/Dek1873923025157525504.jpg"; deek.on("message", async function(msg, user){ @@ -1685,6 +1686,86 @@ deek.on("message", async function(msg, user){ } break; + case "caption": + case "cap": + + if(value.trim() == ""){ + + send(msg, "you need to give me a caption you moron"); + return; + } + + try{ + + var image = + await sharp( + await fetch_image(last_image) + ).png() + .flatten( + { + background: "#282828" + } + ) + .toBuffer(); + }catch(error){ + + send(msg, "go open gimp you lazy fuck"); + } + + var image = await(loadImage(image)); + var canvas = createCanvas(image.width, image.height); + + const ctx = canvas.getContext("2d"); + ctx.drawImage(image, 0, 0, image.width, image.height); + + var fontsize = Math.floor(image.width * 0.08); + ctx.font = fontsize + "px Impact"; + ctx.fillStyle = "white"; + ctx.strokeStyle = "black"; + ctx.lineWidth = image.width * 0.01; + ctx.textAlign = "center"; + ctx.textBaseline = "top"; + + var parts = value.replace(/ +/g, " ").split(""); + var tmp_text = ""; + var tmp_text_old = ""; + var text_to_add = ""; + var line = 0; + for(var i=0; i= image.width || + parts.length - 1 === i + ){ + // draw + if(metrics.width >= image.width){ + + // put text on next line since it overflows + tmp_text_old = tmp_text_old.trim(); + tmp_text = parts[i]; + + text_to_add = tmp_text_old; + }else{ + + text_to_add = tmp_text; + } + + var textheight = metrics.actualBoundingBoxAscent + metrics.actualBoundingBoxDescent; + + ctx.strokeText(text_to_add, image.width / 2, textheight * line); + ctx.fillText(text_to_add, image.width / 2, textheight * line); + line++; + } + } + + send(msg, "", canvas.toBuffer("image/jpeg")); + break; + case "help": case "h": if(value == "image"){ @@ -1693,7 +1774,8 @@ deek.on("message", async function(msg, user){ msg, "== image manipulation help menu ==\n\n" + ".help image => lol idk\n" + - ".rotatify (deg) => Ro ta te\n" + + ".caption => fr fr\n" + + ".rotatify => Ro ta te\n" + ".flip => gucci flip flops\n" + ".flop => make it kick rocks\n" + ".deepfry => Make images look better\n" +