ImageMagick Command-line suite for creating, converting, and editing raster images

Common Operations

The everyday operations you'll reach for most: resizing, cropping, converting formats, and running the same edit across many files at once.

Resizing

magick in.jpg -resize 50% out.jpg          # scale by percentage
magick in.jpg -resize 800x600 out.jpg      # fit within a box, keep aspect ratio
magick in.jpg -resize 800x600! out.jpg     # force exact size, ignore aspect ratio
magick in.jpg -resize 800x out.jpg         # fixed width, height auto
magick in.jpg -resize 'x600' out.jpg       # fixed height, width auto
magick in.jpg -resize 800x600^ out.jpg     # fill the box, may overflow one dimension

By default -resize only ever scales down; add > after the geometry (e.g. 800x600>) to make that explicit, or < to only scale up.

Cropping

magick in.jpg -crop 400x400+100+50 out.jpg   # width x height + x-offset + y-offset
magick in.jpg -gravity center -crop 500x500+0+0 out.jpg  # crop centered

The offsets are measured from the top-left corner unless -gravity changes the anchor point.

Rotating & flipping

magick in.jpg -rotate 90 out.jpg     # rotate clockwise
magick in.jpg -rotate -90 out.jpg    # rotate counter-clockwise
magick in.jpg -flip out.jpg          # vertical flip
magick in.jpg -flop out.jpg          # horizontal flip
magick in.jpg -auto-orient out.jpg   # apply EXIF orientation, then strip it

Converting between formats

magick photo.png photo.jpg            # format is inferred from the extension
magick photo.jpg -quality 85 photo.jpg  # re-encode a JPEG at 85% quality
magick icon.png icon.ico              # works for icon/multi-frame formats too
magick animation.gif frame_%02d.png   # explode an animated GIF into numbered frames
magick frame_*.png animation.gif      # and the reverse: frames into a GIF

Compressing & re-encoding

magick in.jpg -quality 75 out.jpg          # lossy JPEG/WebP quality (0-100)
magick in.png -strip out.png               # drop EXIF/ICC metadata to shrink the file
magick in.jpg -define jpeg:extent=200KB out.jpg  # target a max file size

Watermarking & compositing

magick composite -gravity southeast -geometry +20+20 \
  watermark.png photo.jpg out.jpg
magick photo.jpg watermark.png -gravity center -composite out.jpg

Both forms overlay one image on another; -gravity picks the anchor corner and -geometry +x+y nudges it in from that anchor.

Adding text

magick photo.jpg -gravity south -pointsize 36 -fill white \
  -annotate +0+20 "Caption text" out.jpg

Batch processing with mogrify

mogrify applies an operation to many files in place (it overwrites the originals unless you pass -path to send output elsewhere) — useful for bulk resizing or re-encoding a whole folder:

magick mogrify -resize 1600x1600\> *.jpg          # shrink oversized images only
magick mogrify -format webp -path out/ *.png       # convert a folder to WebP, keep originals
magick mogrify -strip -quality 80 *.jpg            # strip metadata + recompress, in place

Always test destructive mogrify runs on a copy first, or use -path to write to a separate output directory.

Contact sheets with montage

magick montage *.jpg -tile 4x -geometry 200x200+5+5 contact-sheet.jpg

Arranges a set of images into a grid — handy for thumbnails or a quick visual index of a folder.