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.– YorikMar 3, 2016 at 21:51
Add a comment
|
2 Answers
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).
-
2Are 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
For ImageMagic7 you can disable the negation of the alpha channel like this:
mogrify -alpha deactivate -negate *.png
-
I had to use:
magick convert *.png -alpha deactivate -negate -set filename:fname '%t-inv' '%[filename:fname].png'
– kongo09Jan 18, 2022 at 10:21