From c612a2003603d88372f119a7ec273ca0b3f5e1df Mon Sep 17 00:00:00 2001 From: loicbersier Date: Sat, 22 Feb 2020 14:38:52 +0100 Subject: [PATCH] Fixed buggy gif --- commands/images/meme.js | 3 +++ commands/images/poster.js | 21 +++++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/commands/images/meme.js b/commands/images/meme.js index 1256edb..9b6242e 100644 --- a/commands/images/meme.js +++ b/commands/images/meme.js @@ -82,6 +82,9 @@ class memeCommand extends Command { return message.channel.send('An error has occured, is it an image?'); } let output = `${os.tmpdir()}/meme${message.id}.${format.toLowerCase()}`; + + if (format.toLowerCase() == 'gif') img.coalesce(); + // Get the image size to calculate top and bottom text positions img.size(function(err, value) { // Set text position for top and bottom diff --git a/commands/images/poster.js b/commands/images/poster.js index dd2283b..27021e0 100644 --- a/commands/images/poster.js +++ b/commands/images/poster.js @@ -96,7 +96,8 @@ class posterCommand extends Command { console.error(err); return message.channel.send('An error has occured, is it an image?'); } - let output = `${os.tmpdir()}/poster${message.id}.${format.toLocaleLowerCase()}`; + let output1 = `${os.tmpdir()}/poster${message.author.id}.${format.toLowerCase()}`; + let output2 = `${os.tmpdir()}/poster${message.id}.${format.toLowerCase()}`; // Get the image size to calculate top and bottom text positions img.size(function(err, value) { // Set text position for top and bottom @@ -109,6 +110,7 @@ class posterCommand extends Command { let BORDER_WIDTH = args.width; let BORDER_HEIGHT = args.height; + if (format.toLowerCase() == 'gif') img.coalesce(); // Write text on image using graphicsmagick img.borderColor('black') @@ -124,27 +126,26 @@ class posterCommand extends Command { .drawText(0, TOP_POS, TOP_TEXT, TEXT_POS) .font(FONT, FONT_SIZE2) .drawText(0, BOTTOM_POS, BOTTOM_TEXT, TEXT_POS) - .write(output, function(err) { + .write(output1, function(err) { + if (err) { + console.error(err); + return message.channel.send('An error just occured! is it a static image?'); + } // Chop the top part of the image - let img2 = gm(output); + let img2 = gm(output1); img2.chop(0, BORDER_HEIGHT / 2) - .write(output, function(err) { + .write(output2, function(err) { loadingmsg.delete(); if (err) { console.error(err); return message.channel.send('An error just occured! is it a static image?'); } message.delete(); - return message.channel.send(`Made by ${message.author.username}`,{files: [output]}) + return message.channel.send(`Made by ${message.author.username}`,{files: [output2]}) .catch(() => { return message.channel.send('The image is too big to fit on discord!'); }); }); - - if (err) { - console.error(err); - return message.channel.send('An error just occured! is it a static image?'); - } }); }); });