Removed format argument from jpeg, modified bufferPromise function a bit
This commit is contained in:
parent
d1792d8885
commit
b7aeacdf66
2 changed files with 37 additions and 15 deletions
|
@ -6,7 +6,7 @@ exports.run = async (message) => {
|
|||
message.channel.sendTyping();
|
||||
const image = await require("../utils/imagedetect.js")(message);
|
||||
if (image === undefined) return `${message.author.mention}, you need to provide an image to add more JPEG!`;
|
||||
const buffer = await gm(image.path).setFormat("jpeg").quality(1).bufferPromise("jpeg");
|
||||
const buffer = await gm(image.path).setFormat("jpeg").quality(1).bufferPromise();
|
||||
return message.channel.createMessage("", {
|
||||
file: buffer,
|
||||
name: "jpeg.jpg"
|
||||
|
@ -15,4 +15,4 @@ exports.run = async (message) => {
|
|||
|
||||
exports.aliases = ["needsmorejpeg", "jpegify", "magik2", "morejpeg", "jpg"];
|
||||
exports.category = 5;
|
||||
exports.help = "Adds max JPEG compression to an image";
|
||||
exports.help = "Adds max JPEG compression to an image";
|
|
@ -49,22 +49,44 @@ module.exports = async () => {
|
|||
//gm.prototype.bufferPromise = promisify(gm.prototype.toBuffer);
|
||||
gm.prototype.bufferPromise = function(format, type) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.out(type !== "sonic" ? "-layers" : "", type !== "sonic" ? "optimize" : "").stream(format, (err, stdout, stderr) => {
|
||||
if (err) return reject(err);
|
||||
const chunks = [];
|
||||
stdout.on("data", (chunk) => {
|
||||
chunks.push(chunk);
|
||||
if (format) {
|
||||
console.log(format);
|
||||
this.out(type !== "sonic" ? "-layers" : "", type !== "sonic" ? "optimize" : "").stream(format, (err, stdout, stderr) => {
|
||||
if (err) return reject(err);
|
||||
const chunks = [];
|
||||
stdout.on("data", (chunk) => {
|
||||
console.log(chunk);
|
||||
chunks.push(chunk);
|
||||
});
|
||||
// these are 'once' because they can and do fire multiple times for multiple errors,
|
||||
// but this is a promise so you'll have to deal with them one at a time
|
||||
stdout.once("end", () => {
|
||||
console.log(Buffer.concat(chunks));
|
||||
resolve(Buffer.concat(chunks));
|
||||
});
|
||||
stderr.once("data", (data) => {
|
||||
reject(data.toString());
|
||||
});
|
||||
});
|
||||
// these are 'once' because they can and do fire multiple times for multiple errors,
|
||||
// but this is a promise so you'll have to deal with them one at a time
|
||||
stdout.once("end", () => {
|
||||
resolve(Buffer.concat(chunks));
|
||||
} else {
|
||||
this.out(type !== "sonic" ? "-layers" : "", type !== "sonic" ? "optimize" : "").stream((err, stdout, stderr) => {
|
||||
if (err) return reject(err);
|
||||
const chunks = [];
|
||||
stdout.on("data", (chunk) => {
|
||||
chunks.push(chunk);
|
||||
});
|
||||
// these are 'once' because they can and do fire multiple times for multiple errors,
|
||||
// but this is a promise so you'll have to deal with them one at a time
|
||||
stdout.once("end", () => {
|
||||
resolve(Buffer.concat(chunks));
|
||||
});
|
||||
stderr.once("data", (data) => {
|
||||
reject(data.toString());
|
||||
});
|
||||
});
|
||||
stderr.once("data", (data) => {
|
||||
reject(data.toString());
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
// tweet stuff
|
||||
|
|
Loading…
Reference in a new issue