ImageMagick - Make a color semi-transparent

Viewed 775

I am trying to overlay image1 over image2. I want to make a color in image1 semi-transparent. So far I have only been able to overlay image1 over image2 using

composite -gravity north image2.png image1.png image3.png

How do I make a color (grey in this case) in image1 semi-transparent before overlaying it over image2?

I am using:

Version: ImageMagick 7.0.8-23 Q16 x86_64 2019-01-09 

Thnx

1 Answers

Let's make an overlay (image2.png) first, with 3 progressively lighter shades of grey starting with 80/255 on the left, 128/255 in the middle and 200/255 on the right:

convert -size 200x438 xc:"gray(80,80,80)" xc:gray xc:"gray(200,200,200)" +append image2.png

enter image description here

Assuming our starting image is this:

enter image description here

We can now make precisely mid-grey into semi-transparent mid-grey and overlay like this:

convert bean.jpg \( image2.png -fill "rgba(128,128,128,0.5)" -opaque gray \) -composite result.png

enter image description here

Or, if we want to also affect the grey(80), we can incorporate some fuzz:

convert bean.jpg \( image2.png -fill "rgba(128,128,128,0.5)" -fuzz 20% -opaque gray \) -composite result.png

enter image description here


Note that at Version 7 of ImageMagick, the commands changed:

Version 6       | Version 7
=================================
identify        | magick identify
convert         | magick
mogrify         | magick mogrify
composite       | magick composite
montage         | magick montage
compare         | magick compare
animate         | magick animate
stream          | magick stream

The order of parameters is also stricter, favouring:

magick [settings] INPUT [settings] [operators] OUTPUT

over:

convert [settings] [operators] INPUT [settings] [operators] OUTPUT

What I mean is that you are expected to load an image prior to applying operators to it, rather than to build up a list of operators and then load an image and hope ImageMagick remembers what you said you wanted done if you ever loaded anything.

Related