mogrify — Batch-Edit Images In-Place with ImageMagick

Batch-process images with ImageMagick: resize, convert, optimize. Warning: mogrify overwrites originals in-place by default, unlike convert.

mogrify is ImageMagick's batch tool: it applies operations like resizing, format conversion or sharpening across entire directories at once. Unlike convert, mogrify writes the result straight back into the original file by default – so a single mogrify -resize 50% *.jpg shrinks every match irreversibly. Back up your files first or write to a separate folder with -path <dir>, and always test on a copy. On ImageMagick 7, magick mogrify is the recommended form.

Basic Usage

mogrify -resize <width>x<height> *.jpg — Resize all JPEGs in the current directory (overwrites originals).

mogrify -resize 800x600 *.jpg

mogrify -format <fmt> *.jpg — Convert all JPEGs to another format (creates new files, keeps originals).

mogrify -format png *.jpg

mogrify -path <dir> -format <fmt> *.jpg — Convert and save to a different directory.

mogrify -path converted/ -format webp *.jpg

mogrify -quality <n> *.jpg — Recompress all JPEGs with a specific quality.

mogrify -quality 85 *.jpg

Batch Resize

mogrify -resize <width>x<height> *.png — Resize to fit within dimensions (maintains aspect ratio).

mogrify -resize 1920x1080 *.png

mogrify -resize 50% *.jpg — Resize all images to 50% of original size.

mogrify -resize 50% photos/*.jpg

mogrify -resize <width>x<height>\> *.jpg — Resize only images larger than the specified dimensions (shrink only).

mogrify -resize 1920x1080\> *.jpg

mogrify -resize <width>x<height>\< *.jpg — Resize only images smaller than the specified dimensions (enlarge only).

mogrify -resize 800x600\< *.jpg

mogrify -thumbnail <width>x<height> *.jpg — Create thumbnails (strips metadata, faster).

mogrify -path thumbs/ -thumbnail 150x150 *.jpg

Batch Format Conversion

mogrify -format webp -quality 80 *.jpg — Convert all JPEGs to WebP.

mogrify -format webp -quality 80 *.jpg

mogrify -format png *.bmp — Convert all BMPs to PNG.

mogrify -format png *.bmp

mogrify -path output/ -format jpg -quality 90 *.png — Convert PNGs to JPEGs in a separate directory.

mogrify -path output/ -format jpg -quality 90 *.png

mogrify -format avif -quality 50 *.jpg — Convert all JPEGs to AVIF (requires AVIF delegate).

mogrify -format avif -quality 50 *.jpg

Batch Adjustments

mogrify -strip *.jpg — Remove all metadata from all JPEGs.

mogrify -strip *.jpg

mogrify -auto-orient *.jpg — Auto-rotate all images based on EXIF orientation.

mogrify -auto-orient photos/*.jpg

mogrify -colorspace Gray *.jpg — Convert all images to grayscale.

mogrify -colorspace Gray *.jpg

mogrify -normalize *.jpg — Auto-normalize contrast on all images.

mogrify -normalize *.jpg

mogrify -sharpen 0x1 *.jpg — Sharpen all images.

mogrify -sharpen 0x1 *.jpg

mogrify -rotate <degrees> *.jpg — Rotate all images by specified degrees.

mogrify -rotate 90 *.jpg

Web Optimization

mogrify -sampling-factor 4:2:0 -quality 85 -strip -interlace Plane *.jpg — Optimize all JPEGs for web delivery.

mogrify -sampling-factor 4:2:0 -quality 85 -strip -interlace Plane *.jpg

mogrify -path web/ -resize 1200x1200\> -quality 80 -strip *.jpg — Create web-optimized copies with max dimensions.

mogrify -path web/ -resize 1200x1200\> -quality 80 -strip *.jpg

mogrify -path retina/ -resize 200% *.png — Create 2x retina versions of images.

mogrify -path retina/ -resize 200% icons/*.png

mogrify -depth 8 -colors 256 *.png — Reduce PNG color palette for smaller file sizes.

mogrify -depth 8 -colors 256 icons/*.png

Common Patterns

mkdir -p output && mogrify -path output/ -resize 800x600 -format webp -quality 80 *.jpg — Resize, convert, and save to output directory in one command.

mkdir -p output && mogrify -path output/ -resize 800x600 -format webp -quality 80 *.jpg

mogrify -resize 800x600 -auto-orient -strip -quality 85 photos/*.jpg — Resize, fix orientation, strip metadata, and recompress.

mogrify -resize 800x600 -auto-orient -strip -quality 85 photos/*.jpg

find . -name '*.png' -exec mogrify -format webp -quality 80 {} \; — Recursively convert all PNGs to WebP in subdirectories.

find . -name '*.png' -exec mogrify -format webp -quality 80 {} \;

mogrify -crop <width>x<height>+<x>+<y> *.jpg — Crop all images to the same region.

mogrify -crop 800x600+100+50 screenshots/*.jpg

Conclusion

mogrify is hard to beat when you need to process dozens or hundreds of images in one sweep – size, format, quality and metadata in a single command. The price is caution: mogrify overwrites the originals in-place by default, so a wrong glob or a forgotten backup costs you the source files irreversibly. When in doubt, write to a separate directory with -path <dir>, test on a copy, and check the result on a handful of files before you unleash it on *.jpg. The one exception: -format creates new files with a new extension and leaves the originals untouched. On ImageMagick 7, prefer magick mogrify.

Further Reading

  • convert – the sibling command that writes the result to a new file instead of in-place
  • identify – read the format, dimensions and metadata of images
  • composite – overlay and combine two images