v7.1.2-34 Latest Stable Release

Command-line Tools: Composite

Use ImageMagick’s Composite tool to overlay, blend, and seamlessly merge images. Explore example commands, advanced options like masks and seamless blending, and learn how to create rich visual compositions.

quickstart.sh
# Install via your favorite Package Manager
$ brew install imagemagick
# Convert PNG to WebP with compression
$ magick input.png -quality 85 output.webp
# Resize image maintaining aspect ratio
$ magick input.jpg -resize 800x600^ output.jpg

Use the composite program to overlap one image over another. See Command Line Processing for advice on how to structure your composite command, or check below for usage examples.

Example Usage

We list a few examples of the composite command here to illustrate its usefulness and ease of use. To get started, let's overlay a smiley face over a rose:

composite-smiley.sh
$ magick composite -gravity center smile.gif  rose: rose-over.png

You can create a three-dimensional effect with the Atop operator:

red-ball.sh
$ magick -size 70x70 canvas:none -fill red -draw 'circle 35,35 10,30' red-circle.png
$ magick -size 70x70 canvas:none -draw "circle 35,35 35,20" -channel RGB -negate -channel A -gaussian-blur 0x8 white-highlight.png
$ magick composite -compose atop -geometry -13-17 white-highlight.png red-circle.png red-ball.png

Or suppose you want to blend a bear into a stream seamlessly. Try this command:

seamless-blend.sh
$ magick -verbose stream.jpg bear.jpg bear_mask.png \
  -define compose:args=400x0.0002+100 -compose seamless-blend \
  -geometry +30+30 -composite bear-in-stream.png

The mask marks the area around the bear to blend. Seamless blending is an iterative process. Here, we limit the iterations to 400 or less if the blending converges (residual has an RMSE of less than 0.0002). The residual value (RMSE) is printed every 100 iterations. Note that seamless blending works most effectively when the HDRI feature is enabled.

read-mask.sh
$ magick -verbose stream.jpg \( bear.jpg -read-mask only_bear.png \) bear_mask.png \
  -define compose:args=400x0.0002+100 -compose seamless-blend \
  -geometry +30+30 -composite bear-in-stream.png

Here we create a read mask that marks the foreground object from its background. No blending is applied to the foreground object, just its surroundings. The read-mask preserves the colors of the bear and prevents them from lightening as in the first example. Note that read-masks must be black on white background as opposed to normal masks, which are white on black background.

Option Summary

The composite command recognizes these options. Click on an option to get more details about how that option works.

Option Description
-affine <matrix> affine transform matrix
-alpha on, activate, off, deactivate, set, opaque, copy, transparent, extract, background, or shape the alpha channel
-authenticate <value> decrypt image with this password
-blend <geometry> blend images
-blue-primary <point> chromaticity blue primary point
-border <geometry> surround image with a border of color
-bordercolor <color> border color
-channel <type> apply option to select image channels
-colors <value> preferred number of colors in the image
-colorspace <type> set image colorspace
-comment <string> annotate image with comment
-compose <operator> set image composite operator
-compress <type> image compression type
-debug <events> display copious debugging information
-decipher <filename> convert cipher pixels to plain
-define <format:option> define one or more image format options
-density <geometry> horizontal and vertical density of the image
-depth <value> image depth
-displace <geometry> shift image pixels defined by a displacement map
-dissolve <value> dissolve the two images a given percent
-dither <method> apply error diffusion to image
-encipher <filename> convert plain pixels to cipher pixels
-encoding <type> text encoding type
-endian <type> endianness (MSB or LSB) of the image
-extract <geometry> extract area from image
-filter <type> use this filter when resizing an image
-font <name> render text with this font
-geometry <geometry> preferred size or location of the image
-gravity <type> horizontal and vertical text placement
-green-primary <point> chromaticity green primary point
-help print program options
-identify identify the format and characteristics of the image
-interlace <type> type of image interlacing scheme
-interpolate <method> pixel color interpolation method
-label <string> assign a label to an image
-level <value> adjust the level of image contrast
-limit <type value> pixel cache resource limit
-log <format> format of debugging information
-monitor monitor progress
-monochrome transform image to black and white
-negate replace each pixel with its complementary color
-page <geometry> size and location of an image canvas (setting)
-pointsize <value> font point size
-profile <filename> add, delete, or apply an image profile
-quality <value> JPEG/MIFF/PNG compression level
-quantize <colorspace> reduce image colors in this colorspace
-quiet suppress all warning messages
-red-primary <point> chromaticity red primary point
-regard-warnings pay attention to warning messages
-respect-parentheses settings remain in effect until parenthesis boundary
-rotate <degrees> apply Paeth rotation to the image
-sampling-factor <geometry> horizontal and vertical sampling factor
-scene <value> image scene number
-seed <value> seed a new sequence of pseudo-random numbers
-set <attribute value> set an image attribute
-sharpen <geometry> sharpen the image
-shave <geometry> shave pixels from the image edges
-size <geometry> width and height of image
-stegano <offset> hide watermark within an image
-stereo <geometry> combine two image to create a stereo anaglyph
-strip strip image of all profiles and comments
-swap <indexes> swap two images in the image sequence
-synchronize synchronize image to storage device
-taint mark the image as modified
-thumbnail <geometry> create a thumbnail of the image
-tile repeat composite operation across and down image
-transform affine transform image
-transparent-color <color> transparent color
-treedepth <value> color tree depth
-type <type> image type
-units <type> the units of image resolution
-unsharp <geometry> sharpen the image
-verbose print detailed information about the image
-version print version information
-virtual-pixel <method> access method for pixels outside the boundaries of the image
-watermark <geometry> percent brightness and saturation of a watermark
-white-point <point> chromaticity white point
-white-threshold <value> force all pixels above the threshold into white
-write <filename> write images to this file