Command
gm composite -resize 1920x1080 -dissolve 40 overlay_image.jpg base_image.jpg result_image.jpg
Break Down
The resize option resizes the overlay to the specified dimensions. You can specify just the height with x1080 or just the width with 1920. Typically you would want this to be the same width as the base image.
Dissolve is what actually does the overlaying part. The number specified is the opacity percentage of the overlay, where higher means more opaque and lower means more transparent. Play around with this number to get an end result you like.
Example
gm composite -resize x700 -dissolve 30 flag.jpg eagle.jpg combined.jpg
On that note, Happy Independence Day everyone! If you have any questions or errors using the command, feel free to leave a comment.
How would this code work in a js scenerio?
Depends. If you are using JavaScript client-side (i.e., in a browser), you’ll have to set up some backend script to do this for you and return the result to the browser. ImageMagick/GraphicsMagick are Operating System libraries, not programming language ones.
If you are using JavaScript server-side, such as with NodeJS, you’ll need to find the appropriate node library to interface with ImageMagick/GraphicsMagick first. Check out the npm repository in that case.