Invert colors with ImageMagick

imagemagick

How do I invert the colors of an image using the ImageMagick convert tool, so that black becomes white and white becomes black?

In other words, I want to turn this:

original

into this:

inverted

Best Answer

Use the -negate option:

convert input.png -channel RGB -negate output.png

The -negate option replaces each pixel with its complementary color. The -channel RGB option is necessary as of ImageMagick 7 to prevent the alpha channel (if present) from being negated. (Thanks to @yoya for this insight!)

See also the documentation for -negate.