ImageMagick command recipes
Forty-five commands, each one executed on a real ImageMagick install before it was published here. Search, filter, copy.
All 45 commands
The tool above is searchable and filterable by category, and follows the IM7/IM6 switch. Here is the full list.
Resize
Resize to a max width, never enlarging
The standard safe transform for user uploads: big images come down, small ones pass through untouched.
magick input.jpg -resize '1600x1600>' -quality 85 output.jpgExact-size square thumbnail, no distortion
Scale to cover, then trim the overflow from the centre.
magick input.jpg -resize '400x400^' -gravity center -extent 400x400 output.jpgFit into a box and pad with white
Exact canvas size with nothing cropped — the usual requirement for marketplace product images.
magick input.jpg -resize 800x800 -background white -gravity center -extent 800x800 output.jpgScale by percentage
Halve both dimensions.
magick input.jpg -resize 50% output.jpgResize for pixel art, no smoothing
Point sampling keeps hard pixel edges instead of blurring them.
magick input.png -filter Point -resize 800% output.pngCrop
Crop a rectangle at an offset
WxH+X+Y, measured from the top-left corner.
magick input.jpg -crop 400x400+100+50 +repage output.jpgSlice an image into a grid of tiles
No offset means “cut the whole thing up”. The %02d counter is required.
magick input.jpg -crop 400x400 +repage tile_%02d.jpgAuto-trim a white border off a scan
Without -fuzz this silently does nothing on real scans, because the border is never perfectly uniform.
magick input.jpg -fuzz 8% -trim +repage output.jpgFormat
Optimise a JPEG for the web
Strip metadata, render progressively, subsample chroma. Typically 40–60% smaller with no visible loss.
magick input.jpg -strip -interlace Plane -sampling-factor 4:2:0 -quality 82 output.jpgConvert to WebP at the smallest setting
method=6 is the slowest and smallest of the WebP effort levels.
magick input.jpg -quality 80 -define webp:method=6 output.webpTransparent PNG to JPEG without going black
JPEG has no alpha. Without these flags every transparent pixel becomes black.
magick input.png -background white -alpha remove -alpha off output.jpgSqueeze a PNG down
Lossless. For bigger wins, add -colors 256 to make it a PNG8.
magick input.png -strip -define png:compression-level=9 output.pngCheck whether your build supports a format
If AVIF, HEIC or WebP is missing from this list, no flag will make it work — the delegate was not compiled in.
magick -list formatPDF to PNG at print resolution
-density must come before the input. Requires Ghostscript and an unblocked policy.xml.
magick -density 300 input.pdf -background white -alpha remove -quality 100 page-%02d.pngExtract only the first page
The bracket index is zero-based and must be quoted so the shell does not treat it as a glob.
magick -density 300 'input.pdf[0]' -quality 100 cover.pngCombine images into a multi-page PDF
Zero-pad your filenames — the shell sorts them as text, so page-10 comes before page-2.
magick page-*.jpg -quality 92 output.pdfFind the policy file that is blocking PDF
Prints the path to policy.xml along with every active rule.
magick -list policyWatermark
Semi-transparent logo in the corner
The parenthesised sub-expression applies the opacity to the logo only.
magick input.jpg '(' logo.png -alpha set -channel A -evaluate multiply 0.4 +channel ')' -gravity southeast -geometry +24+24 -composite output.jpgText watermark that stays readable
Drawn twice, dark then light, so it never disappears into the photo.
magick input.jpg -gravity southeast -pointsize 42 -fill black -annotate +26+22 '© 2026' -fill white -annotate +24+24 '© 2026' output.jpgTranslucent box behind a caption
-undercolor accepts 8-digit hex, so the last two characters are the alpha.
magick input.jpg -gravity south -pointsize 36 -undercolor '#00000080' -fill white -annotate +0+24 'Caption text' output.jpgEffect
Rounded corners with real transparency
There is no -round-corners operator; this builds the mask by mirroring one drawn corner.
magick input.png '(' +clone -alpha extract -draw 'fill black polygon 0,0 0,40 40,0 fill white circle 40,40 40,0' '(' +clone -flip ')' -compose Multiply -composite '(' +clone -flop ')' -compose Multiply -composite ')' -alpha off -compose CopyOpacity -composite output.pngDrop shadow behind a transparent PNG
-shadow replaces the image with its shadow, so it has to run on a clone.
magick input.png '(' +clone -background black -shadow 60x12+0+8 ')' +swap -background none -layers merge +repage output.pngPixelate a region for privacy
Down then up with -scale, which uses nearest neighbour and produces hard blocks.
magick input.jpg -scale 5% -scale 2000% output.jpgMake one colour transparent
Works on logos and flat graphics. On photographs it will punch holes everywhere.
magick input.png -fuzz 15% -transparent white output.pngColour
Proper weighted black and white
Uses luminance weighting, unlike -modulate 100,0 which simply zeroes saturation.
magick input.jpg -colorspace Gray output.jpgRescue a flat, hazy photo
Auto levels, a gentle saturation and contrast lift, then light sharpening.
magick input.jpg -auto-level -modulate 102,112,100 -unsharp 0x0.8+0.7+0.01 output.jpgSharpen after downscaling
Every downscale softens edges. This is a conservative amount that avoids halos.
magick input.jpg -resize 1200 -unsharp 0x0.75+0.75+0.008 output.jpgGif
Build a GIF from numbered frames
-delay and -loop must appear before the input frames.
magick -delay 8 -loop 0 frame_*.png +dither -colors 128 -layers Optimize output.gifResize an animated GIF correctly
Without -coalesce the partial frames get scrambled into visual garbage.
magick input.gif -coalesce -resize 320x -layers Optimize output.gifShrink an oversized GIF
Cutting the palette and storing only changed regions are the two big levers.
magick input.gif +dither -colors 64 -layers Optimize output.gifExplode a GIF into frames
-coalesce gives you what the animation looks like, not the stored difference frames.
magick input.gif -coalesce frame_%03d.pngCombine
Stack images into a vertical strip
-append is vertical, +append is horizontal.
magick shot1.png shot2.png shot3.png -append output.pngContact sheet with filenames
montage is a separate binary; on IM7 write it as `magick montage`.
montage *.jpg -tile 4x -geometry 300x300+8+8 -label %f -background white sheet.jpgSide-by-side before/after
Resize both to a common height first if they differ.
magick before.jpg after.jpg +append comparison.jpgIcon
Multi-resolution favicon.ico
Packs every size into one file. Start from a square source of at least 256px.
magick logo.png -background none -define icon:auto-resize=16,32,48,64,128,256 favicon.icoInfo
One-line summary of every image in a folder
Reads headers only, so it is fast even across thousands of files.
identify -format '%f %wx%h %m %b\n' *.jpgRead EXIF without any extra tool
Dumps every EXIF tag the file carries.
identify -format '%[EXIF:*]' input.jpgCount the pages in a PDF or frames in a GIF
Prints the number of images inside the file.
identify -format '%n\n' input.gifWhich version am I actually running?
If `magick -version` fails but `convert -version` works, you are on ImageMagick 6.
magick -versionCreate
Solid colour placeholder
-size must come before the xc: source.
magick -size 1200x630 xc:'#0d9488' output.pngLinear gradient
Also available: radial-gradient:, plasma:, pattern:.
magick -size 1200x630 gradient:'#0d9488'-'#0b1015' output.pngPlaceholder with its size written on it
Handy for mocking up layouts without hunting for stock photos.
magick -size 800x600 xc:'#334155' -gravity center -pointsize 72 -fill white -annotate 0 '800x600' output.pngBatch
Resize every JPEG in place
mogrify overwrites the originals. Copy the folder first — there is no undo.
mogrify -resize '1600x1600>' -quality 85 *.jpgConvert a folder to WebP, keeping originals
-path writes into another directory, which must already exist. This is the safe form of mogrify.
mogrify -path out -format webp -quality 80 *.jpgLoop over files in bash
More control than mogrify, and it never touches the originals.
mkdir -p out && for f in *.jpg; do magick "$f" -resize 1200 "out/$f"; done
What "verified" means here
Every command in this library was run against a real ImageMagick 6.9 install with Ghostscript, on real test images, and its exit status checked. Commands that failed were fixed, not published with a caveat.
That is a low bar, and it is remarkable how much published ImageMagick content does not clear it. Most of the wrong commands circulating online are wrong in the same few ways: they use IM6 syntax on IM7, they forget to quote geometry, or they omit -coalesce when touching an animated GIF.
They follow the version switch
The IM7/IM6 toggle in the header rewrites every recipe on this page. If you are following a tutorial written for the other version and something will not run, flip the switch and compare.