v7.1.2-34 Latest Stable Release

Command-line Tools: Conjure

Learn how to use ImageMagick’s conjure program to run custom image processing workflows using XML-based Magick Scripting Language (MSL) scripts.

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

The conjure program gives you the ability to perform custom image processing tasks from a script written in the Magick Scripting Language (MSL). MSL is XML-based and consists of action statements with attributes. Actions include reading an image, processing an image, getting attributes from an image, writing an image, and more. An attribute is a key/value pair that modifies the behavior of an action. See Command Line Processing for advice on how to structure your conjure command or explore the examples below.

Example Usage

We list a few examples of the conjure command here to illustrate its usefulness and ease of use. To get started, here is a simple conjure command:

$ magick conjure -dimensions 400x400 msl:incantation.msl

The MSL script incantation.msl used above is shown here:

<?xml version="1.0" encoding="UTF-8"?>
<image>
  <read filename="image.gif" />
  <get width="base-width" height="base-height" />
  <resize geometry="%[dimensions]" />
  <get width="resize-width" height="resize-height" />
  <print output="Image sized from %[base-width]x%[base-height] to %[resize-width]x%[resize-height].\n" />
  <write filename="image.png" />
</image>

In this example, a family stayed home for their vacation, but as far as their friends are concerned, they went to a beautiful beach in the Caribbean:

<?xml version="1.0" encoding="UTF-8"?>
<group>
    <image id="family">
        <read filename="family.gif"/>
        <resize geometry="300x300"/>
    </image>
    <image id="palm-trees">
        <read filename="palm-trees.gif"/>
        <resize geometry="300x100"/>
    </image>
    <image>
        <read filename="beach.jpg"/>
        <composite image="family" geometry="+30+40"/>
        <composite image="palm-trees" geometry="+320+90"/>
    </image>
    <write filename="family-vacation.png"/>
</group>

Here we display the width in pixels of text for a particular font and pointsize:

<?xml version="1.0" encoding="UTF-8"?>
<image>
  <query-font-metrics text="ImageMagick" font="helvetica" pointsize="48" />
  <print output="Text width is %[msl:font-metrics.width] pixels.\n" />
</image>

The query-font-metrics tag supports these properties:

msl:font-metrics.pixels_per_em.x
msl:font-metrics.pixels_per_em.y
msl:font-metrics.ascent
msl:font-metrics.descent
msl:font-metrics.width
msl:font-metrics.height
msl:font-metrics.max_advance
msl:font-metrics.bounds.x1
msl:font-metrics.bounds.y1
msl:font-metrics.bounds.x2
msl:font-metrics.bounds.y2
msl:font-metrics.origin.x
msl:font-metrics.origin.y

MSL supports most methods and attributes discussed in the Perl API for ImageMagick.

In addition, MSL supports the swap element with a single indexes element.

Option Summary

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

Option Description
-debug events display copious debugging information
-help print program options
-log format format of debugging information
-monitor monitor progress
-quiet suppress all warning messages
-regard-warnings pay attention to warning messages
-seed value seed a new sequence of pseudo-random numbers
-verbose print detailed information about the image
-version print version information

Magick Scripting Language (MSL)

The conjure command recognizes these MSL elements. Any element with a strike-through is not supported yet.

Method Parameters Description
adaptiveblur geometry="geometry", radius="double", sigma="double", bias="double", channel="..." adaptively blur the image with a Gaussian operator of the given radius and standard deviation (sigma). Decrease the effect near edges.
adaptiveresize geometry="geometry", width="integer", height="integer", filter="...", support="double", blur="double" adaptively resize image using data dependant triangulation. Specify blur > 1 for blurry or < 1 for sharp
adaptivesharpen geometry="geometry", radius="double", sigma="double", bias="double", channel="..." adaptively sharpen the image with a Gaussian operator of the given radius and standard deviation (sigma). Increase the effect near edges.
adaptivethreshold geometry="geometry", width="integer", height="integer", offset="integer" local adaptive thresholding.
addnoise noise="...", attenuate="double", channel="..." add noise to an image
affinetransform affine="...", translate="...", scale="...", rotate="...", skewX="...", skewY="...", interpolate="...", background="..." affine transform image
affinity image="image-handle", method="..." choose a particular set of colors from this image
<annotate> text="string", font="string", family="string", style="...", pointsize="integer", fill="color name", ... annotate an image with text. See QueryFontMetrics to get font metrics without rendering any text.
autogamma channel="..." automagically adjust gamma level of image
autolevel channel="..." automagically adjust color levels of image
autoorient adjusts an image so that its orientation is suitable for viewing (i.e. top-left orientation)
blackthreshold threshold="string", channel="..." force all pixels below the threshold intensity into black
blueshift factor="double" simulate a scene at nighttime in the moonlight. Start with a factor of 1.5.
<blur> geometry="geometry", radius="double", sigma="double", bias="double", channel="..." reduce image noise and reduce detail levels with a Gaussian operator of the given radius and standard deviation (sigma).
<border> geometry="geometry", width="integer", height="integer", bordercolor="color name", compose="..." surround the image with a border of color
<charcoal> geometry="geometry", radius="double", sigma="double" simulate a charcoal drawing
<chop> geometry="geometry", width="integer", height="integer", x="integer", y="integer" chop an image
clamp channel="..." set each pixel whose value is below zero to zero and any pixel whose value is above the quantum range to the quantum range.
clip id="name", inside="true, false" apply along a named path from the 8BIM profile.
clipmask mask="image-handle" clip image as defined by the image mask
clut image="image-handle", interpolate="...", channel="..." apply a color lookup table to an image sequence
coalesce merge a sequence of images
color color="color name" set the entire image to this color.
colordecisionlist filename="string" color correct with a color decision list.
<colorize> fill="color name", blend="string" colorize the image with the fill color
colormatrix matrix="..." apply color correction to the image.
<comment> string add a comment to your image
comparelayers method="..." compares each image with the next in a sequence and returns the minimum bounding region of any pixel differences.
<composite> image="image-handle", compose="...", geometry="..." composite one image onto another. Use the rotate parameter in concert with the tile parameter.
<contrast> sharpen="True, False" enhance or reduce the image contrast
contraststretch levels="..." improve the contrast in an image by 'stretching' the range of intensity values
convolve coefficients="..." apply a convolution kernel to the image.
<crop> geometry="geometry", width="integer", height="integer", x="integer", y="integer" crop an image
cyclecolormap amount="integer" displace image colormap by amount
decipher passphrase="string" convert cipher pixels to plain pixels
deconstruct break down an image sequence into constituent parts
deskew geometry="..." straighten the image
<despeckle> reduce the speckles within an image
difference image="image-handle" compute the difference metrics between two images
distort points="..." distort image
<draw> primitive="..." annotate an image with one or more graphic primitives.
encipher passphrase="string" convert plain pixels to cipher pixels
<edge> radius="double" enhance edges within the image with a convolution filter of the given radius.
<emboss> geometry="geometry", radius="double", sigma="double" emboss the image with a convolution filter of the given radius and standard deviation (sigma).
<enhance> apply a digital filter to enhance a noisy image
<equalize> channel="..." perform histogram equalization to the image
extent geometry="..." set the image size
evaluate value="double", operator="..." apply an arithmetic, relational, or logical expression to the image
filter kernel="..." apply a convolution kernel to the image.
<flip> reflect the image scanlines in the vertical direction
<flop> reflect the image scanlines in the horizontal direction
floodfillpaint geometry="..." changes the color value of any pixel that matches the color of the target pixel and is a neighbor.
forwardfouriertransform magnitude="True, False" implements the forward discrete Fourier transform (DFT)
<frame> geometry="..." surround the image with an ornamental border
function parameters="..." apply a function to the image
<gamma> gamma="string" gamma correct the image
gaussianblur geometry="..." reduce image noise and reduce detail levels with a Gaussian operator.
getpixel x="integer", y="integer" get a single pixel.
getpixels width="integer", height="integer" get image pixels as defined by the map.
grayscale channel="..." convert image to grayscale
haldclut image="image-handle" apply a Hald color lookup table to an image sequence
identify file="file" identify the attributes of an image
<implode> amount="double" implode image pixels about the center
inversediscretefouriertransform magnitude="True, False" implements the inverse discrete Fourier transform (DFT)
<label> string assign a label to an image
layers method="..." compare each image the GIF disposed forms of the previous image in the sequence.
<level> levels="string" adjust the level of image contrast
levelcolors invert="True, False" level image with the given colors
linearstretch levels="..." linear with saturation stretch
liquidresize geometry="..." rescale image with seam-carving.
<magnify> double the size of the image with pixel art scaling
mask mask="image-handle" composite image pixels as defined by the mask
mattefloodfill geometry="..." changes the matte value of any pixel that matches the color of the target pixel and is a neighbor.
medianfilter geometry="..." replace each pixel with the median intensity pixel of a neighborhood.
<minify> half the size of an image
mode geometry="..." make each pixel the "predominant color" of the neighborhood.
<modulate> factor="geometry" vary the brightness, saturation, and hue of an image by the specified percentage
morphology kernel="..." apply a morphology method to the image.
motionblur geometry="..." reduce image noise with a Gaussian operator at the given angle.
<negate> gray="True, False" replace each pixel with its complementary color
<normalize> channel="..." transform image to span the full range of color values
oilpaint radius="integer" simulate an oil painting
<opaque> color="color name", fill="color name" change this color to the fill color within the image
ordereddither threshold="..." order dither image
perceptible epsilon="double" set each pixel whose value is less than |epsilon| to -epsilon or epsilon.
polaroid caption="string" simulate a Polaroid picture.
posterize levels="integer" reduce the image to a limited number of color level
<profile> name="string", profile="blob" add or remove ICC or IPTC image profile.
<quantize> colors="integer", colorspace="..." preferred number of colors in the image
radialblur geometry="..." radial blur the image.
<raise> geometry="..." lighten or darken image edges to create a 3-D effect
reducenoise geometry="..." reduce noise in the image with a noise peak elimination filter
remap image="image-handle" replace the colors of an image with the closest color from a reference image.
<resample> density="..." resample image to desired resolution.
<resize> geometry="..." scale image to desired size.
<roll> geometry="..." roll an image vertically or horizontally
<rotate> degrees="double" rotate an image
<sample> geometry="..." scale image with pixel sampling.
<scale> geometry="..." scale image to desired size
<segment> colorspace="..." segment an image by analyzing histograms of color components
selectiveblur geometry="..." selectively blur pixels within a contrast threshold.
separate channel="..." separate a channel from the image into a grayscale image
<shade> azimuth="double", elevation="double" shade the image using a distant light source
setpixel x="integer", y="integer" set a single pixel.
<shadow> geometry="..." simulate an image shadow
<sharpen> geometry="..." sharpen the image with a Gaussian operator.
<shave> geometry="..." shave pixels from the image edges
<shear> geometry="..." shear the image along the X or Y axis
sigmoidalcontrast geometry="..." sigmoidal non-linearity contrast control.
<signature> generate an SHA-256 message digest for the image pixel stream
sketch geometry="..." sketch the image with a Gaussian operator.
<solarize> threshold="double" negate all pixels above the threshold level
sparsecolor points="..." interpolate the image colors around the supplied points
splice geometry="..." splice an image
<spread> radius="double" displace image pixels by a random amount
statistic geometry="..." replace each pixel with corresponding statistic from the neighborhood.
<stegano> image="image-handle" hide a digital watermark within the image
<stereo> image="image-handle" composites two images and produces a single stereo pair image
<strip> strip an image of all profiles and comments.
<swirl> degrees="double" swirl image pixels about the center
texture texture="image-handle" name of texture to tile onto the image background
thumbnail geometry="..." changes the size of an image and removes profiles.
<threshold> threshold="string" threshold the image
tint fill="color name" tint the image with the fill color.
<transparent> color="color name" make this color transparent within the image
transpose flip image vertically and rotate 90 degrees
transverse flop image horizontally and rotate 270 degrees
<trim> remove edges that are the background color from the image
unsharpmask geometry="..." sharpen the image with the unsharp mask algorithm.
vignette geometry="..." offset the edges of the image in vignette style
wave geometry="..." alter an image along a sine wave
whitethreshold threshold="string" force all pixels above the threshold intensity into white