Overlay an Image on Top of Another with GraphicsMagick

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

Bald Eagle

United States FlagComposite

On that note, Happy Independence Day everyone! If you have any questions or errors using the command, feel free to leave a comment.

 

Advertisements

2 thoughts on “Overlay an Image on Top of Another with GraphicsMagick

    • 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.

What are your thoughts?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s