Gautam
Gautam

Reputation: 2753

Overlay images and set transparency R

I have two images and I want to overlay one on top of the other such that the top layer is transparent and allows the features in the below layer to show to some extent.

I am searching for this functionality within magic and imager packages but can't seem to get it done. Found a good example at this link but it seems to be using some geographical packages (raster formatting) but the end result is what I want.

Image 1:

enter image description here

Image 2

enter image description here

Desired Result

enter image description here

Upvotes: 2

Views: 1632

Answers (1)

GeeMack
GeeMack

Reputation: 5395

With ImageMagick you can start with "input1.png" and overlay "input2.png" with a particular amount of transparency. This command in *nix shell format shows the basics...

magick input1.png \
   \( input2.png -channel A -evaluate multiply 0.5 +channel \) \
   -gravity center -composite result.png

First that reads in the base image. Then inside the parentheses it reads in the overlay image and reduces its alpha channel opacity to 50% with "-evaluate multiply 0.5". Then it composites the semi-transparent overlay onto the base image.

In that command the overlay will be centered. Setting the "-gravity ..." and specifying a horizontal and vertical offset with "-geometry +H+V" just before the composite allows you place the overlay anywhere you like on the base image.

To use this command from a Windows command line, the backslashes that escape the parentheses "\(...\)" should be removed "(...)", and the continued-line backslashes "\" need to be changed to carets "^".

Upvotes: 1

Related Questions