Back to Imagemagick

ImageMagick

www/composite.html

7.1.2-2110.1 KB
Original Source

Example UsageOption Summary

Use the composite program to overlap one image over another. See Command Line Processing for advice on how to structure your composite command or see below for example usages of the command.

Example Usage

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

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

You can create three-dimensional effect with the Atop:

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:

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, seamless blending works most effectively when the HDRI feature is enabled.

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

You can find additional examples of using composite in Examples of ImageMagick Usage. You can find out more about them and the mathematics by looking at SVG Alpha Compositing

Option Summary

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

OptionDescription
-affine matrixaffine transform matrix
-alphaon, activate, off, deactivate, set, opaque, copy", transparent, extract, background, or shape the alpha channel
-authenticate valuedecrypt image with this password
-blend geometryblend images
-blue-primary pointchromaticity blue primary point
-border geometrysurround image with a border of color
-bordercolor colorborder color
-channel typeapply option to select image channels
-colors valuepreferred number of colors in the image
-colorspace typeset image colorspace
-comment stringannotate image with comment
-compose operatorset image composite operator
-compress typeimage compression type
-debug eventsdisplay copious debugging information
-decipher filenameconvert cipher pixels to plain
-define format:optiondefine one or more image format options
-density geometryhorizontal and vertical density of the image
-depth valueimage depth
-displace geometryshift image pixels defined by a displacement map
-dissolve valuedissolve the two images a given percent
-dither methodapply error diffusion to image
-encipher filenameconvert plain pixels to cipher pixels
-encoding typetext encoding type
-endian typeendianness (MSB or LSB) of the image
-extract geometryextract area from image
-filter typeuse this filter when resizing an image
-font namerender text with this font
-geometry geometrypreferred size or location of the image
-gravity typehorizontal and vertical text placement
-green-primary pointchromaticity green primary point
-helpprint program options
-identifyidentify the format and characteristics of the image
-interlace typetype of image interlacing scheme
-interpolate methodpixel color interpolation method
-label stringassign a label to an image
-level valueadjust the level of image contrast
-limit type valuepixel cache resource limit
-log formatformat of debugging information
-monitormonitor progress
-monochrometransform image to black and white
-negatereplace each pixel with its complementary color
-page geometrysize and location of an image canvas (setting)
-pointsize valuefont point size
-profile filenameadd, delete, or apply an image profile
-quality valueJPEG/MIFF/PNG compression level
-quantize colorspacereduce image colors in this colorspace
-quietsuppress all warning messages
-red-primary pointchromaticity red primary point
-regard-warningspay attention to warning messages.
-respect-parenthesessettings remain in effect until parenthesis boundary.
-rotate degreesapply Paeth rotation to the image
-sampling-factor geometryhorizontal and vertical sampling factor
-scene valueimage scene number
-seed valueseed a new sequence of pseudo-random numbers
-set attribute valueset an image attribute
-sharpen geometrysharpen the image
-shave geometryshave pixels from the image edges
-size geometrywidth and height of image
-stegano offsethide watermark within an image
-stereo geometrycombine two image to create a stereo anaglyph
-stripstrip image of all profiles and comments
-swap indexesswap two images in the image sequence
-synchronizesynchronize image to storage device
-taintmark the image as modified
-thumbnail geometrycreate a thumbnail of the image
-tilerepeat composite operation across and down image
-transformaffine transform image
-transparent-color colortransparent color
-treedepth valuecolor tree depth
-type typeimage type
-units typethe units of image resolution
-unsharp geometrysharpen the image
-verboseprint detailed information about the image
-versionprint version information
-virtual-pixel methodaccess method for pixels outside the boundaries of the image
-watermark geometrypercent brightness and saturation of a watermark
-white-point pointchromaticity white point
-white-threshold valueforce all pixels above the threshold into white
-write filenamewrite images to this file

About ImageMagick