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 *.jpgmogrify -format <fmt> *.jpg — Convert all JPEGs to another format (creates new files, keeps originals).
mogrify -format png *.jpgmogrify -path <dir> -format <fmt> *.jpg — Convert and save to a different directory.
mogrify -path converted/ -format webp *.jpgmogrify -quality <n> *.jpg — Recompress all JPEGs with a specific quality.
mogrify -quality 85 *.jpgBatch Resize
mogrify -resize <width>x<height> *.png — Resize to fit within dimensions (maintains aspect ratio).
mogrify -resize 1920x1080 *.pngmogrify -resize 50% *.jpg — Resize all images to 50% of original size.
mogrify -resize 50% photos/*.jpgmogrify -resize <width>x<height>\> *.jpg — Resize only images larger than the specified dimensions (shrink only).
mogrify -resize 1920x1080\> *.jpgmogrify -resize <width>x<height>\< *.jpg — Resize only images smaller than the specified dimensions (enlarge only).
mogrify -resize 800x600\< *.jpgmogrify -thumbnail <width>x<height> *.jpg — Create thumbnails (strips metadata, faster).
mogrify -path thumbs/ -thumbnail 150x150 *.jpgBatch Format Conversion
mogrify -format webp -quality 80 *.jpg — Convert all JPEGs to WebP.
mogrify -format webp -quality 80 *.jpgmogrify -format png *.bmp — Convert all BMPs to PNG.
mogrify -format png *.bmpmogrify -path output/ -format jpg -quality 90 *.png — Convert PNGs to JPEGs in a separate directory.
mogrify -path output/ -format jpg -quality 90 *.pngmogrify -format avif -quality 50 *.jpg — Convert all JPEGs to AVIF (requires AVIF delegate).
mogrify -format avif -quality 50 *.jpgBatch Adjustments
mogrify -strip *.jpg — Remove all metadata from all JPEGs.
mogrify -strip *.jpgmogrify -auto-orient *.jpg — Auto-rotate all images based on EXIF orientation.
mogrify -auto-orient photos/*.jpgmogrify -colorspace Gray *.jpg — Convert all images to grayscale.
mogrify -colorspace Gray *.jpgmogrify -normalize *.jpg — Auto-normalize contrast on all images.
mogrify -normalize *.jpgmogrify -sharpen 0x1 *.jpg — Sharpen all images.
mogrify -sharpen 0x1 *.jpgmogrify -rotate <degrees> *.jpg — Rotate all images by specified degrees.
mogrify -rotate 90 *.jpgWeb 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 *.jpgmogrify -path web/ -resize 1200x1200\> -quality 80 -strip *.jpg — Create web-optimized copies with max dimensions.
mogrify -path web/ -resize 1200x1200\> -quality 80 -strip *.jpgmogrify -path retina/ -resize 200% *.png — Create 2x retina versions of images.
mogrify -path retina/ -resize 200% icons/*.pngmogrify -depth 8 -colors 256 *.png — Reduce PNG color palette for smaller file sizes.
mogrify -depth 8 -colors 256 icons/*.pngCommon 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 *.jpgmogrify -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/*.jpgfind . -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
- ImageMagick: mogrify – official reference for the mogrify command and its options
- Wikipedia: ImageMagick – overview of the image-processing suite