# convert — Convert and Edit Images (ImageMagick)

> Practical guide to convert: transform images between formats, resize, crop, rotate, adjust colors and apply effects with ImageMagick (in v7: magick).

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

<!-- PROSE:intro -->
convert is the Swiss Army knife of ImageMagick: a single command that transforms images between dozens of formats, scales, crops, rotates, adjusts colors, applies effects and even renders PDF pages. In ImageMagick 7, `convert` is deprecated in favor of `magick` – `magick input.png output.jpg` is the modern form, and the classic `convert` calls it internally and stays compatible for now. This guide walks you through the invocations you actually reach for daily, from a quick format swap to web optimization.
<!-- PROSE:intro:end -->

## Format Conversion

`convert <input> <output>` — Convert an image to another format (determined by extension).

```bash
convert photo.png photo.jpg
```

`convert <input> -quality <n> <output>` — Convert with specific quality (1-100, for JPEG/WebP).

```bash
convert photo.png -quality 85 photo.jpg
```

`convert <input> -define webp:lossless=true <output>` — Convert to lossless WebP.

```bash
convert photo.png -define webp:lossless=true photo.webp
```

`convert <input> -define png:compression-level=9 <output>` — Convert to PNG with maximum compression.

```bash
convert photo.bmp -define png:compression-level=9 photo.png
```

`convert <input>[0] <output>` — Extract first frame/page from multi-frame image or PDF.

```bash
convert animation.gif[0] first-frame.png
```

## Resize & Scale

`convert <input> -resize <width>x<height> <output>` — Resize to fit within dimensions (maintains aspect ratio).

```bash
convert photo.jpg -resize 800x600 thumb.jpg
```

`convert <input> -resize <width>x<height>! <output>` — Force exact dimensions (ignores aspect ratio).

```bash
convert photo.jpg -resize 800x600! stretched.jpg
```

`convert <input> -resize <width>x<height>^ <output>` — Resize to fill dimensions (may exceed one dimension).

```bash
convert photo.jpg -resize 800x600^ -gravity center -extent 800x600 cover.jpg
```

`convert <input> -resize 50% <output>` — Resize by percentage.

```bash
convert photo.jpg -resize 50% half.jpg
```

`convert <input> -resize <width> <output>` — Resize to a specific width (auto height).

```bash
convert photo.jpg -resize 800 resized.jpg
```

`convert <input> -resize x<height> <output>` — Resize to a specific height (auto width).

```bash
convert photo.jpg -resize x600 resized.jpg
```

`convert <input> -thumbnail <width>x<height> <output>` — Create a thumbnail (strips metadata, faster than resize).

```bash
convert photo.jpg -thumbnail 150x150 thumb.jpg
```

## Crop & Trim

`convert <input> -crop <width>x<height>+<x>+<y> <output>` — Crop a region at specific offset.

```bash
convert photo.jpg -crop 400x300+100+50 cropped.jpg
```

`convert <input> -gravity center -crop <width>x<height>+0+0 <output>` — Crop from the center of the image.

```bash
convert photo.jpg -gravity center -crop 400x300+0+0 center.jpg
```

`convert <input> -trim <output>` — Remove borders/whitespace around the image.

```bash
convert logo.png -trim trimmed.png
```

`convert <input> -fuzz <n>% -trim <output>` — Trim with color tolerance for near-matching borders.

```bash
convert logo.png -fuzz 10% -trim trimmed.png
```

`convert <input> -shave <x>x<y> <output>` — Remove pixels from all edges.

```bash
convert photo.jpg -shave 20x20 shaved.jpg
```

## Rotate & Flip

`convert <input> -rotate <degrees> <output>` — Rotate the image by specified degrees.

```bash
convert photo.jpg -rotate 90 rotated.jpg
```

`convert <input> -auto-orient <output>` — Auto-rotate based on EXIF orientation data.

```bash
convert photo.jpg -auto-orient corrected.jpg
```

`convert <input> -flip <output>` — Flip vertically (top to bottom).

```bash
convert photo.jpg -flip flipped.jpg
```

`convert <input> -flop <output>` — Flip horizontally (left to right).

```bash
convert photo.jpg -flop flopped.jpg
```

`convert <input> -transpose <output>` — Mirror along top-left to bottom-right diagonal.

```bash
convert photo.jpg -transpose transposed.jpg
```

## Color Adjustments

`convert <input> -colorspace Gray <output>` — Convert to grayscale.

```bash
convert photo.jpg -colorspace Gray grayscale.jpg
```

`convert <input> -modulate <brightness>,<saturation>,<hue> <output>` — Adjust brightness, saturation, and hue (100 = unchanged).

```bash
convert photo.jpg -modulate 120,130,100 vibrant.jpg
```

`convert <input> -brightness-contrast <b>x<c> <output>` — Adjust brightness and contrast (-100 to +100).

```bash
convert photo.jpg -brightness-contrast 10x20 adjusted.jpg
```

`convert <input> -negate <output>` — Invert all colors (create a negative).

```bash
convert photo.jpg -negate negative.jpg
```

`convert <input> -level <black>%,<white>% <output>` — Adjust levels (set black/white points).

```bash
convert photo.jpg -level 10%,90% adjusted.jpg
```

`convert <input> -normalize <output>` — Auto-stretch contrast to full range.

```bash
convert photo.jpg -normalize normalized.jpg
```

`convert <input> -equalize <output>` — Equalize histogram for better contrast.

```bash
convert photo.jpg -equalize equalized.jpg
```

`convert <input> -colorspace CMYK <output>` — Convert to CMYK colorspace (for print).

```bash
convert photo.jpg -colorspace CMYK print-ready.tiff
```

## Effects & Filters

`convert <input> -blur 0x<sigma> <output>` — Apply Gaussian blur.

```bash
convert photo.jpg -blur 0x3 blurred.jpg
```

`convert <input> -sharpen 0x<sigma> <output>` — Sharpen the image.

```bash
convert photo.jpg -sharpen 0x1.5 sharp.jpg
```

`convert <input> -unsharp <radius>x<sigma>+<amount>+<threshold> <output>` — Apply unsharp mask for precise sharpening.

```bash
convert photo.jpg -unsharp 0x1+1+0.05 sharp.jpg
```

`convert <input> -sepia-tone 80% <output>` — Apply a sepia tone effect.

```bash
convert photo.jpg -sepia-tone 80% sepia.jpg
```

`convert <input> -vignette 0x<sigma> <output>` — Add a vignette (darkened edges).

```bash
convert photo.jpg -vignette 0x20 vignette.jpg
```

`convert <input> -charcoal <radius> <output>` — Apply a charcoal sketch effect.

```bash
convert photo.jpg -charcoal 2 sketch.jpg
```

`convert <input> -edge <radius> <output>` — Detect edges in the image.

```bash
convert photo.jpg -edge 1 edges.jpg
```

`convert <input> -emboss <radius> <output>` — Apply an emboss effect.

```bash
convert photo.jpg -emboss 2 embossed.jpg
```

## Text & Annotations

`convert <input> -gravity south -annotate +0+10 "<text>" <output>` — Add text annotation at a position.

```bash
convert photo.jpg -gravity south -fill white -pointsize 24 -annotate +0+10 "© 2026" annotated.jpg
```

`convert -size <w>x<h> xc:<color> -font <font> -pointsize <n> -fill <color> -annotate +<x>+<y> "<text>" <output>` — Create an image from text.

```bash
convert -size 400x100 xc:white -font Arial -pointsize 36 -fill black -annotate +10+50 "Hello World" text.png
```

`convert <input> -fill <color> -draw "rectangle <x1>,<y1> <x2>,<y2>" <output>` — Draw a filled rectangle on the image.

```bash
convert photo.jpg -fill "rgba(0,0,0,0.5)" -draw "rectangle 0,400 800,500" overlay.jpg
```

## Metadata & Optimization

`convert <input> -strip <output>` — Remove all metadata (EXIF, ICC profiles, comments).

```bash
convert photo.jpg -strip clean.jpg
```

`convert <input> -interlace Plane <output>` — Create a progressive/interlaced image.

```bash
convert photo.jpg -interlace Plane progressive.jpg
```

`convert <input> -sampling-factor 4:2:0 -quality 85 -strip <output>` — Optimize JPEG for web (smaller file size).

```bash
convert photo.jpg -sampling-factor 4:2:0 -quality 85 -interlace Plane -strip optimized.jpg
```

`convert <input> -colors <n> <output>` — Reduce the number of colors.

```bash
convert photo.png -colors 256 reduced.png
```

`convert <input> -depth <bits> <output>` — Set the bit depth (8, 16, etc.).

```bash
convert photo.png -depth 8 8bit.png
```

## Create & Generate

`convert -size <w>x<h> xc:<color> <output>` — Create a solid color canvas.

```bash
convert -size 800x600 xc:#336699 canvas.png
```

`convert -size <w>x<h> gradient:<from>-<to> <output>` — Create a vertical gradient.

```bash
convert -size 800x600 gradient:blue-white gradient.png
```

`convert -size <w>x<h> plasma: <output>` — Create a random plasma fractal.

```bash
convert -size 800x600 plasma: plasma.jpg
```

`convert -size <w>x<h> pattern:<name> <output>` — Create a tiled pattern (checkerboard, hexagons, etc.).

```bash
convert -size 800x600 pattern:checkerboard checkers.png
```

`convert <input> -alpha set -background none -channel A -evaluate set <n>% <output>` — Set uniform transparency level.

```bash
convert logo.png -alpha set -background none -channel A -evaluate set 50% semi-transparent.png
```

## Animation (GIF)

`convert -delay <ticks> <frame1> <frame2> ... <output>` — Create an animated GIF from frames (delay in 1/100s).

```bash
convert -delay 20 frame-*.png animation.gif
```

`convert <input> -coalesce <output>` — Reconstruct all frames to full images (undo optimizations).

```bash
convert animation.gif -coalesce frames.gif
```

`convert <input> -layers Optimize <output>` — Optimize GIF animation for smaller file size.

```bash
convert animation.gif -layers Optimize optimized.gif
```

`convert <input> -loop <n> <output>` — Set GIF loop count (0 = infinite).

```bash
convert -delay 50 frame-*.png -loop 0 animation.gif
```

<!-- PROSE:outro -->
## Conclusion

convert covers nearly every image operation you need on the command line – batch conversion, resizing for the web or quick effects. Keep in mind that the classic `convert` is deprecated under ImageMagick 7: for new scripts, `magick input.png output.jpg` is the recommended form, and `magick mogrify` edits whole directories in place. `convert` overwrites the destination file silently, so never accidentally pass the same path as both input and output. Use `-strip` to remove metadata (EXIF, GPS, ICC) before publishing. Security note: processing PDF, PS and SVG files historically relied on Ghostscript and has repeatedly been an attack surface, which is why ImageMagick restricts risky formats via `policy.xml`. Handle untrusted image files with care and only loosen the policy deliberately.

## Further Reading

- [ImageMagick: Command-line Tools](https://imagemagick.org/script/command-line-tools.php) – official reference for convert, magick and mogrify
- [ImageMagick: Command-line Options](https://imagemagick.org/script/command-line-options.php) – full list of options such as -resize, -quality and -strip
- [Wikipedia: ImageMagick](https://en.wikipedia.org/wiki/ImageMagick) – overview of features, history and supported formats
<!-- PROSE:outro:end -->

## Related Commands

- [mogrify](https://www.jpkc.com/db/en/cheatsheets/images-media/mogrify/) – batch-edit and convert images in place
- [identify](https://www.jpkc.com/db/en/cheatsheets/images-media/identify/) – read format, dimensions and metadata of images
- [composite](https://www.jpkc.com/db/en/cheatsheets/images-media/composite/) – overlay and merge images into one

