added cap
This commit is contained in:
parent
699fb5fd02
commit
469320c31a
86
client.js
86
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<parts.length; i++){
|
||||
|
||||
tmp_text_old = tmp_text;
|
||||
tmp_text += parts[i];
|
||||
|
||||
var metrics = ctx.measureText(tmp_text.trim());
|
||||
|
||||
if(
|
||||
metrics.width >= 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" +
|
||||
|
|
Loading…
Reference in New Issue