ImageMagick Cheatsheet

A collection of ImageMagick commands for common image editing tasks.

What is ImageMagick?

Imagemagick is a fanstastic open-source CLI tool used for editing and manipulating digital images. It is written in C and can be used on a variety of operating systems, including Linux, Windows, and macOS

If you’re on MacOS (like me) and already have Homebrew installed on your system, you can easily install the latest binary with brew install imagemagick

Basic Image Operations

Convert an image format

Convert an image from one format to another:

magick input.jpg output.png

Resize an image (maintain aspect ratio)

Resizes an image to a specific size while maintaining its aspect ratio:

magick input.jpg -resize 800x600 output.jpg

Crop an image

Crop an image to a specific size and position:

magick input.jpg -crop 400x400+50+50 output.jpg

Rotate an image

Rotate an image by 90 degrees:

magick input.jpg -rotate 90 output.jpg

Image Enhancement & Effects

Convert to grayscale

Convert an image to black & white (grayscale):

magick input.jpg -colorspace Gray output.jpg

Adjust brightness & contrast

Increase brightness by 10 and contrast by 20:

magick input.jpg -brightness-contrast 10x20 output.jpg

Blur an image

Apply a Gaussian blur effect:

magick input.jpg -blur 0x5 output.jpg

Sharpen an image

Sharpen an image using an Unsharp Mask:

magick input.jpg -unsharp 0x2 output.jpg

Compression & Optimization

Reduce file size (JPEG)

Compress a JPEG image by adjusting quality:

magick input.jpg -quality 75 output.jpg

Convert & compress to WebP

Convert and optimize an image in WebP format:

magick input.jpg -resize 800x600 -quality 75 output.webp

Strip metadata (EXIF data)

Remove all metadata (such as camera details and location info):

magick input.jpg -strip output.jpg

Transparency & Layering

Make a specific color transparent

Make all white areas transparent:

magick input.png -transparent white output.png

Add a watermark

Overlay a watermark image at the bottom-right corner:

magick input.jpg watermark.png -gravity southeast -composite output.jpg

Text & Graphics

Add text to an image

Overlay text on an image at a specific position:

magick input.jpg -fill white -pointsize 36 -draw "text 50,50 'Hello World'" output.jpg

Add a border

Add a 10-pixel black border to an image:

magick input.jpg -bordercolor black -border 10 output.jpg

Working with Multiple Images

Merge images (side by side)

Horizontally merge two images:

magick convert image1.jpg image2.jpg +append output.jpg

Create an animated GIF

Generate a GIF from multiple images:

magick -delay 50 -loop 0 frame1.jpg frame2.jpg frame3.jpg output.gif

Extract frames from a GIF

Extract individual frames from an animated GIF:

magick input.gif -coalesce frame_%03d.png

Batch Processing

Convert all PNGs in a folder to JPG

magick mogrify -format jpg *.png

Generate thumbnails for all images

Create smaller versions of all images in a folder:

magick mogrify -resize 150x150 *.jpg