Fixed buggy gif

This commit is contained in:
loicbersier 2020-02-22 14:38:52 +01:00
parent b18c0dab88
commit c612a20036
2 changed files with 14 additions and 10 deletions

View file

@ -82,6 +82,9 @@ class memeCommand extends Command {
return message.channel.send('An error has occured, is it an image?'); return message.channel.send('An error has occured, is it an image?');
} }
let output = `${os.tmpdir()}/meme${message.id}.${format.toLowerCase()}`; 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 // Get the image size to calculate top and bottom text positions
img.size(function(err, value) { img.size(function(err, value) {
// Set text position for top and bottom // Set text position for top and bottom

View file

@ -96,7 +96,8 @@ class posterCommand extends Command {
console.error(err); console.error(err);
return message.channel.send('An error has occured, is it an image?'); 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 // Get the image size to calculate top and bottom text positions
img.size(function(err, value) { img.size(function(err, value) {
// Set text position for top and bottom // Set text position for top and bottom
@ -109,6 +110,7 @@ class posterCommand extends Command {
let BORDER_WIDTH = args.width; let BORDER_WIDTH = args.width;
let BORDER_HEIGHT = args.height; let BORDER_HEIGHT = args.height;
if (format.toLowerCase() == 'gif') img.coalesce();
// Write text on image using graphicsmagick // Write text on image using graphicsmagick
img.borderColor('black') img.borderColor('black')
@ -124,27 +126,26 @@ class posterCommand extends Command {
.drawText(0, TOP_POS, TOP_TEXT, TEXT_POS) .drawText(0, TOP_POS, TOP_TEXT, TEXT_POS)
.font(FONT, FONT_SIZE2) .font(FONT, FONT_SIZE2)
.drawText(0, BOTTOM_POS, BOTTOM_TEXT, TEXT_POS) .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 // Chop the top part of the image
let img2 = gm(output); let img2 = gm(output1);
img2.chop(0, BORDER_HEIGHT / 2) img2.chop(0, BORDER_HEIGHT / 2)
.write(output, function(err) { .write(output2, function(err) {
loadingmsg.delete(); loadingmsg.delete();
if (err) { if (err) {
console.error(err); console.error(err);
return message.channel.send('An error just occured! is it a static image?'); return message.channel.send('An error just occured! is it a static image?');
} }
message.delete(); 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(() => { .catch(() => {
return message.channel.send('The image is too big to fit on discord!'); 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?');
}
}); });
}); });
}); });