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"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -49,7 +49,27 @@ 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) => {
 | 
				
			||||||
 | 
					      if (format) {
 | 
				
			||||||
 | 
					        console.log(format);
 | 
				
			||||||
        this.out(type !== "sonic" ? "-layers" : "", type !== "sonic" ? "optimize" : "").stream(format, (err, stdout, stderr) => {
 | 
					        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());
 | 
				
			||||||
 | 
					          });
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					      } else {
 | 
				
			||||||
 | 
					        this.out(type !== "sonic" ? "-layers" : "", type !== "sonic" ? "optimize" : "").stream((err, stdout, stderr) => {
 | 
				
			||||||
          if (err) return reject(err);
 | 
					          if (err) return reject(err);
 | 
				
			||||||
          const chunks = [];
 | 
					          const chunks = [];
 | 
				
			||||||
          stdout.on("data", (chunk) => {
 | 
					          stdout.on("data", (chunk) => {
 | 
				
			||||||
| 
						 | 
					@ -64,7 +84,9 @@ module.exports = async () => {
 | 
				
			||||||
            reject(data.toString());
 | 
					            reject(data.toString());
 | 
				
			||||||
          });
 | 
					          });
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // tweet stuff
 | 
					  // tweet stuff
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue