Search code examples
imagemagickimagemagick-convert

Imagemagick - Inverse


I've a png image containing transparent pixels and colored pixels (mainly white).

I'd like to transform all transparent pixels to white pixels and all white pixels to transparent pixels within a given rectangle.

My idea would be to

  1. convert the white pixels to red
  2. the transparent colors to white
  3. and the red colors to transparent

. Here' s my code:

1) convert ldl_0.png -fuzz 10% -fill red -opaque white lx.png
2) convert lx.png -background white -alpha remove -alpha off lx2.png

However I can' t figure out how do I transform red colors to transparent. How do I do that?

Also how can I force to do this only within a given rectangle?

Thank You.

-----Test Image


Solution

  • Try this in ImageMagick. Negate the alpha channel and turn the whole RGB channels to white.

    convert in.png -channel a -negate +channel -fill white -colorize 100 out.png