aheckmann / gm

GraphicsMagick for node
http://aheckmann.github.com/gm/
6.95k stars 615 forks source link

Get dominant color #440

Open noam3127 opened 9 years ago

noam3127 commented 9 years ago

The following command is specified in the IM docs as a simple way to extract the dominant color from an image:

convert image.jpg -scale 1x1\! -format '%[pixel:s]' info:-

This yields the following result for my image: srgb(129,109,85).

Now I'm trying to do this same command using gm, but I'm getting a very different color. I'm obviously doing something wrong. Here is what I tried:

 gm('image.jpg').scale(1, 1, '!').identify('%[pixel:s]', function(err, info) {
    console.log(info); // srgb(77,100,32)
 });

I have a feeling that the .identify() method is getting called on the original image rather than the post-scaled image. If so, what's the best way to correct this and have identify called on the result of the scale? Would it require writing it first to a file/buffer then reading it? Any help would be appreciated. Thanks.

rwky commented 9 years ago

Yes writing it to a file/buffer is the best way.