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();
|
message.channel.sendTyping();
|
||||||
const image = await require("../utils/imagedetect.js")(message);
|
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!`;
|
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("", {
|
return message.channel.createMessage("", {
|
||||||
file: buffer,
|
file: buffer,
|
||||||
name: "jpeg.jpg"
|
name: "jpeg.jpg"
|
||||||
|
@ -15,4 +15,4 @@ exports.run = async (message) => {
|
||||||
|
|
||||||
exports.aliases = ["needsmorejpeg", "jpegify", "magik2", "morejpeg", "jpg"];
|
exports.aliases = ["needsmorejpeg", "jpegify", "magik2", "morejpeg", "jpg"];
|
||||||
exports.category = 5;
|
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 = promisify(gm.prototype.toBuffer);
|
||||||
gm.prototype.bufferPromise = function(format, type) {
|
gm.prototype.bufferPromise = function(format, type) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.out(type !== "sonic" ? "-layers" : "", type !== "sonic" ? "optimize" : "").stream(format, (err, stdout, stderr) => {
|
if (format) {
|
||||||
if (err) return reject(err);
|
console.log(format);
|
||||||
const chunks = [];
|
this.out(type !== "sonic" ? "-layers" : "", type !== "sonic" ? "optimize" : "").stream(format, (err, stdout, stderr) => {
|
||||||
stdout.on("data", (chunk) => {
|
if (err) return reject(err);
|
||||||
chunks.push(chunk);
|
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,
|
} else {
|
||||||
// but this is a promise so you'll have to deal with them one at a time
|
this.out(type !== "sonic" ? "-layers" : "", type !== "sonic" ? "optimize" : "").stream((err, stdout, stderr) => {
|
||||||
stdout.once("end", () => {
|
if (err) return reject(err);
|
||||||
resolve(Buffer.concat(chunks));
|
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
|
// tweet stuff
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue