command-line-interfacegimpcolorize

Changing a color in an image via the command line / colorizing the image


I have a set of images that need a color dynamically applied to them to "colorize" them. The image itself is the "white" representation and certain colors need to be applied dynamically.

GIMP does a wonderful job of that by going to "Colors" -> "Colorize" and then I can enter the target RGB color and it will be applied. However I need something like this in CLI mode (for Windows).

I have tried "BIMP" and its colorify plugin and it does the same thing - but again not in CLI mode. I also checked if Inkscape can accomplish this (as I am using this successfully for other use cases) but I did not find a solution.

I also tried ImageMagick, but my search did not turn up anything of use. Also I checked the WA2L tools (which helped a lot in a different use case -> svg2png) but again: nothing

Do any of you have a pointer (or maybe even a full solution) to colorize the image as required.

The idea is that I have a picture of a white part and we offer that part in any color but we do not want to save thousands of copies of the same image just to have it in different colors. Example input: enter image description here

Example output after colorizing it via BIMP with RGB color 161/143/131 (a brown shade): enter image description here


Solution

  • In Imagemagick 7, you can try, (change tan to your exact color)

    magick image.png -channel rgb -fill tan -colorize 100 result1.png
    

    enter image description here

    or probably better

    magick image.png \( -clone 0 -channel rgb -fill tan -colorize 100 \) +swap -compose multiply -composite result2.png
    

    enter image description here