3

I have a large number of monochrome PNGs that are black on transparent. I would like to invert them to be white on transparent. I've tried using XnConvert but it doesn't maintain the transparency.

1
  • since "transparency" is another word for "alpha channel" and alpha is a greyscale image, and your source is "black and white", you can try compositing a white image with the source image specified as the alpha mask. Imagemagik (command line) may be able to handle this via the -compose switch (?). GIMP is open source and allows for batch commands as well.
    – Yorik
    Mar 3, 2016 at 21:51

2 Answers 2

1

ImageMagick will do it:

for a single image:

convert black.png -negate white.png

for a directory full of images:

mogrify -negate *.png

The "-negate" option only affects the pixel color components and doesn't change the alpha (transparency).

3
  • 2
    Are you sure about that? I just ran the command and it has flipped the alpha and non-alpha channel. So rather than black-on-transparent, it's now transparent-on-white Sep 5, 2017 at 9:41
  • I ran some tests and ImageMagick 6 works as I described, but ImageMagick 7 seems to be buggy. Sep 7, 2017 at 0:08
  • Ahhh interesting! I wonder if it's a bug or intentional? Thanks for taking the time Sep 7, 2017 at 6:28
4

For ImageMagic7 you can disable the negation of the alpha channel like this:

mogrify -alpha deactivate -negate *.png
1
  • I had to use: magick convert *.png -alpha deactivate -negate -set filename:fname '%t-inv' '%[filename:fname].png'
    – kongo09
    Jan 18, 2022 at 10:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .