How to convert colours to black in images using ImageMagick

If you want to convert PNG (or similar) files containing, for example, icons which are in one colour (say green) to black, then the command below will do this. This can be especially useful for updating logos or icons on the fly in a file system, without breaking stride, over command line (SSH).

Note you will need ImageMagick installed on your server (the commands involved for doing that will vary from environment to environment – Google it! – for example “install imagemagick on AWS linux” or whatever).

convert oldfilename.png -negate -threshold 0 -negate newfilename.png

These instructions use the Threshold instruction to turn ANYTHING that isn’t white into black.

More info here.

Leave a comment below if this helped you solve your problem – ImageMagick commands are sometimes hard to come by!

Leave a comment

No links of any kind allowed in comments - if you add any links, your comment will automatically be deleted.