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.

  • 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 '16 at 21:51

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).

  • 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 – Matt Fletcher Sep 5 '17 at 9:41
  • I ran some tests and ImageMagick 6 works as I described, but ImageMagick 7 seems to be buggy. – Glenn Randers-Pehrson Sep 7 '17 at 0:08
  • Ahhh interesting! I wonder if it's a bug or intentional? Thanks for taking the time – Matt Fletcher Sep 7 '17 at 6:28

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

mogrify -alpha deactivate -negate *.png

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.