0

I want to run the following task:

// getting the average color of the mask area
convert demp.png \( demo_mask.png -negate \) -compose copyopacity 
-composite -scale 1x1! -format "%[pixel:u.p{0,0}]" info:

via nodejs gm module using the imagemagick subclass. I can't find any good documentation/tutorial about the gm module, so I'm kind of stucked in the middle of an important task.

  gm("demo_mask.png").negative(function(err, maskImg){
    if(err) return Promise.reject(err);
    gm("demo.png").compose("CopyOpacity")
      .command("composite")
      .scale(1,1)
      .command('format').in('%[pixel:u.p{0,0}]')
       // HOW TO GO ON HERE ? HOW TO RETURN THE INFO NOW ?

  });

The problem starts with the first braces where I have to first negate a mask image before I can compose it. I'm not sure If it works if I first negate the mask and inside the callback feed that into the composition.. But the bigger problem is, how can I return infos as text ... ?

sami_analyst
  • 1,751
  • 5
  • 24
  • 43
  • 1
    You need to add -alpha off after -scale 1x1!. So the command should be `convert demp.png \( demo_mask.png -negate \) -compose copyopacity -composite -scale 1x1! -alpha off -format "%[pixel:u.p{0,0}]" info:`. Sorry, I cannot help on the gm code. – fmw42 Oct 25 '17 at 16:33
  • alright, still thanks a lot ! – sami_analyst Oct 25 '17 at 16:40

1 Answers1

0

I do not know if this will help with converting to gm code. But you could also do:

convert logo: -transparent white -alpha extract mask.png

convert logo: mask.png -compose copyopacity -composite -scale 1x1! -alpha off txt:

# ImageMagick pixel enumeration: 1,1,65535,srgb
0,0: (25752,20939,25349)  #645163  srgb(100,81,99)


Then parse the output for the srgb(100,81,99)

Note that it is important to have ! suffix on the -scale 1x1!, if your image is not square.

fmw42
  • 46,825
  • 10
  • 62
  • 80