How to Blend Two Images with Opacity in ImageMagick?

This article provides a straightforward guide on how to blend two images together using a specific opacity level via the ImageMagick convert command. You will learn the exact syntax required to layer a foreground image over a background image, control the transparency of the top layer, and save the final composite result. Whether you are automating graphics processing or working from the command line, these methods will help you achieve precise image blending.

The Basic Blending Command

To blend two images together where the top image has a specific opacity, you use the composite operator within the ImageMagick toolset. The most efficient way to achieve this is by using the -blend flag, which defines the percentage of opacity for the images being overlaid.

Here is the standard command structure:

magick convert background.jpg foreground.png -blend 30 blended_output.jpg

Note: If you are using ImageMagick v7 or newer, the modern syntax uses magick instead of magick convert, though convert is still widely supported for backwards compatibility.

Breaking Down the Syntax

Controlling Advanced Opacity and Layering

If you need more granular control over how both images behave relative to each other, you can pass comma-separated percentage values to the -blend argument. This tells ImageMagick exactly how much visual weight to give to the first image versus the second image.

magick convert background.jpg foreground.png -blend 40x60 blended_output.jpg

In this variation, 40x60 instructs ImageMagick to retain 40% of the background image’s intensity and mix it with 60% of the foreground image’s intensity.

Handling Dissolve for Alpha Channels

If your foreground image already contains transparent elements (like a PNG with an alpha channel) and you want to reduce its overall opacity further, the -dissolve option is often preferred over -blend.

magick convert background.jpg foreground.png -define composite:args=50 -composite blended_output.jpg

Using -define composite:args=50 -composite ensures that the original transparency of the PNG is respected while cleanly fading the entire top layer by 50% opacity onto the background.