xtr33me
xtr33me

Reputation: 1106

How do I get Node.js graphicsmagick color reduction to work?

I am in a cloud9 environment on c9.io and I have sucessfully installed graphicsmagick and the node.js gm module. I have been successful in calling a number of methods however some I have not. One specific one I am having a problem with is the color reduction method (colors).

Has anyone successfully been able to call colors and get it to reduce the colors in the source image? The documentation states the usage is: gm("img.png").colors(int) but I can't seem to get it to work and was wondering if anyone has successfully used this.

I have provided a reduced code block to give an idea as to how I'm using it in hopes that someone will see what I am perhaps doing wrong. In the data event handler, I still have way more colors being shown in the passed "chunk" param then my reduced amount of 8 in this case.

Thanks!

    var img = gm(sourceFilename),
    tmpFilename = temp.path({ suffix: '.miff' });

    return img.noProfile().bitdepth(8).colors(8).scale(Math.ceil(wh.height / ratio),   MAX_W).write('histogram:' + tmpFilename, function (err) {
    var histogram, rs;
    histogram = '';
    rs = fs.createReadStream(tmpFilename, {encoding: 'utf8'});

    rs.addListener('data', function (chunk) {
    console.log("Data: ", chunk);
    });
    });

Upvotes: 0

Views: 914

Answers (1)

xtr33me
xtr33me

Reputation: 1106

Ok issue seems to be with "scale". At this time it seems that scale and resize (I tested) are both not working correctly. When I removed scale from the line as shown below, I am now getting the color reduced histogram data I was expecting.

return img.noProfile().bitdepth(8).colors(8).write('histogram:' + tmpFilename, function (err)

Upvotes: 1

Related Questions