0

I'm stuck in the middle of the process of calculating the average color of an image via gm's subclass imagemagick. After resizing the image into a 1x1 image, I need to return the image information by "txt:-" so therefore im using the .out() command of gm. But now I don't know where and how to handle the callback ...

var gm     = require('gm').subClass({
  imageMagick: true
});

gm(IMAGEPATH).resize('1x1!').out('txt:-').... // how to get the string back ?
sami_analyst
  • 1,751
  • 5
  • 24
  • 43
  • Did you ever figure this out. I'm having the same issue. I'm using `.command('convert')` but then looking to retrieve `out(':info')` but piping to `stream()` - It's returning the image data. – Ecropolis Feb 09 '18 at 15:34

1 Answers1

1

i wasn't able to understand it properly let me know if i am wrong

You can try to save response to buffer and then read it's properties like below

var fs = require('fs'),
gm = require('gm').subClass({
    imageMagick: true
});

// output all available image properties
gm('20.png').resize(1, 1)
    .toBuffer('PNG', function(err, buffer) {
        gm(buffer, 'image.png').identify(function(err, data) {
            if (!err) console.log(data)
                console.log(data)
        });
    });