# 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.

Source: https://www.jpkc.com/db/en/cheatsheets/images-media/mogrify/

<!-- PROSE:intro -->
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.
<!-- PROSE:intro:end -->

## Basic Usage

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

```bash
mogrify -resize 800x600 *.jpg
```

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

```bash
mogrify -format png *.jpg
```

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

```bash
mogrify -path converted/ -format webp *.jpg
```

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

```bash
mogrify -quality 85 *.jpg
```

## Batch Resize

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

```bash
mogrify -resize 1920x1080 *.png
```

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

```bash
mogrify -resize 50% photos/*.jpg
```

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

```bash
mogrify -resize 1920x1080\> *.jpg
```

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

```bash
mogrify -resize 800x600\< *.jpg
```

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

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

## Batch Format Conversion

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

```bash
mogrify -format webp -quality 80 *.jpg
```

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

```bash
mogrify -format png *.bmp
```

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

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

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

```bash
mogrify -format avif -quality 50 *.jpg
```

## Batch Adjustments

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

```bash
mogrify -strip *.jpg
```

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

```bash
mogrify -auto-orient photos/*.jpg
```

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

```bash
mogrify -colorspace Gray *.jpg
```

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

```bash
mogrify -normalize *.jpg
```

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

```bash
mogrify -sharpen 0x1 *.jpg
```

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

```bash
mogrify -rotate 90 *.jpg
```

## Web Optimization

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

```bash
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.

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

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

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

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

```bash
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.

```bash
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.

```bash
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.

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

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

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

<!-- PROSE:outro -->
## 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](https://imagemagick.org/script/mogrify.php) – official reference for the mogrify command and its options
- [Wikipedia: ImageMagick](https://en.wikipedia.org/wiki/ImageMagick) – overview of the image-processing suite
<!-- PROSE:outro:end -->

## Related Commands

- [convert](https://www.jpkc.com/db/en/cheatsheets/images-media/convert/) – the sibling command that writes the result to a new file instead of in-place
- [identify](https://www.jpkc.com/db/en/cheatsheets/images-media/identify/) – read the format, dimensions and metadata of images
- [composite](https://www.jpkc.com/db/en/cheatsheets/images-media/composite/) – overlay and combine two images

