imagemagickimage-editing

To tint image using red, green and other colors, and keep color balance


I need to create red, green and purple (and, if possible, yellow) versions of the following image:

enter image description here

Original image is here: https://github.com/jsx97/test/blob/main/folder.png

For this, I use

magick input.png -colorspace gray -fill red -tint 100 output-red.png
magick input.png -colorspace gray -fill green -tint 100 output-green.png
etc.

I don't know why, but the red folder is too bright. For example, here you can see a shadow:

enter image description here

But on the red image you won's see it:

enter image description here

How can I create such red, green, etc. versions with more balanced colors? Maybe we need to convert to Lab or LCH first?


Solution

  • Mark Setchell's command gives me two constant red images. The issue seems to be that ImageMagick 7 processes alpha channels different from ImageMagick 6, plus the fact that -colorize 100 just makes a constant color result. So this may be what he was trying to do.

    magick img.png \
    \( +clone -alpha extract -write mpr:alpha +delete \) \
    -alpha off -colorspace HSL -separate -delete 0,1 \
    \( +clone -fill red -colorize 100% \) -colorspace sRGB \
    -compose multiply -composite -compose over \
    mpr:alpha -alpha off -compose copy_opacity -composite result.png
    

    enter image description here

    Or using -compose softlight rather than multiply:

    magick img.png \
    \( +clone -alpha extract -write mpr:alpha +delete \) \
    -alpha off -colorspace HSL -separate -delete 0,1 \
    \( +clone -fill red -colorize 100% \) -colorspace sRGB \
    -compose softlight -composite -compose over \
    mpr:alpha -alpha off -compose copy_opacity -composite result.png
    

    enter image description here

    Or using -compose overlay:

    magick img.png \
    \( +clone -alpha extract -write mpr:alpha +delete \) \
    -alpha off -colorspace HSL -separate -delete 0,1 \
    \( +clone -fill red -colorize 100% \) -colorspace sRGB \
    -compose overlay -composite -compose over \
    mpr:alpha -alpha off -compose copy_opacity -composite result.png
    

    enter image description here

    Or -compose pegtoplight:

    magick img.png \
    \( +clone -alpha extract -write mpr:alpha +delete \) \
    -alpha off -colorspace HSL -separate -delete 0,1 \
    \( +clone -fill red -colorize 100% \) -colorspace sRGB \
    -compose pegtoplight -composite -compose over \
    mpr:alpha -alpha off -compose copy_opacity -composite result.png
    

    enter image description here