4

I'm trying to replace all non-transparent pixels to a given color using GraphicsMagick for Node.

Using a composite image is not an option, I simply need to change every non-transparent pixel to a given color.

Original image:

Original image

Goal:

enter image description here

Transparent pixels should stay transparent. I'm trying to achieve Photoshop's Color Overlay effect:

enter image description here

Adriaan Meuris
  • 351
  • 2
  • 12

2 Answers2

7

This is a bit simpler. In ImageMagick do the following:

convert 84xHk.png -fill "#E91FCB" +opaque none result.png

enter image description here

fmw42
  • 46,825
  • 10
  • 62
  • 80
  • works perfect with ImageMagick - but would like to execute this using GraphicsMagick, however the same commands (`gm convert 84xHk.png -fill "#E91FCB" +opaque none result.png`) gives this output: `gm convert: Unable to open file (none) [No such file or directory].` – Adriaan Meuris May 26 '17 at 07:39
  • Sorry, I do not know GraphicsMagick. It was an early spin off of Imagemagick and may not have all the same features or they use different names for those features. My guess is that it does not understand +opaque. You may have to use one of emcconville's methods. – fmw42 May 26 '17 at 17:14
2

I'm not familiar with Node's GraphicsMagick library, but there are a few methods to achieve this. Here's a few I can think of...

Extract alpha, and replace colors

convert 84xHk.png -alpha extract \
        -negate -fill '#E91FCB' -fuzz 50% \
        -opaque black output.png

First Example

Create solid color image, and copy alpha channel

convert 84xHk.png \
       \( +clone -alpha off \
          -fill '#E91FCB' \
          -draw 'color 0,0 reset' \
       \) +swap -compose CopyOpacity -composite output.png

Second Example

Use FX expressions

 convert 84xHk.png -fx 'p.a==1?#E91FCBFF:#E91FCB00' output.png

Third Example

emcconville
  • 23,800
  • 4
  • 50
  • 66