Search code examples
imagemagickcomposite

Imagemagick Composite Overlay Opacity


I am using imagemagick to overlay one image over another with a blending option. I'd like to adjust the overlaying image opacity to about 60%. I would only like to adjust the foreground image, not the merged group. I Currently have:

exec("convert $img_in test_images/test_opacity.jpg -compose screen -composite $img_out");

And I'd like something like this:

exec("convert $img_in (test_images/test_opacity.jpg -opacity 0.6) -compose screen -composite $img_out");

Any help here would be much appreciated.


Solution

  • Use the +level, or -level-color options to adjust the white/black points. This will generally give the mask the effects of "dodging" or "burning"; which, compose Screen will respect.

    convert source.jpg \
            \( mask.jpg -normalize +level 0,60% \) \
            -compose screen -composite destination.jpg
    

    You can also adjust the opacity of the mask by defining an alpha channel with -alpha, -channel & -evaluate. See this question. But this wouldn't work with compose Screen as it's expecting a range between black & white.

    convert source.jpg \
            \( mask.jpg -alpha set -channel A -evaluate set 60% \) \
            -compose screen -composite \
            destination.jpg