Skip to content

yangboz/imagemagick-cheatsheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 

Repository files navigation

ImageMagick Cheat Sheet

Want to improve this cheat sheet? See the Contributing section!

Table of Contents

Why ImageMagick

Use ImageMagick® to create, edit, compose, or convert bitmap images. It can read and write images in a variety of formats (over 200) including PNG, JPEG, GIF, HEIC, TIFF, DPX, EXR, WebP, Postscript, PDF, and SVG. Use ImageMagick to resize, flip, mirror, rotate, distort, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and Bézier curves.

The functionality of ImageMagick is typically utilized from the command-line or you can use the features from programs written in your favorite language. Choose from these interfaces: G2F (Ada), MagickCore (C), MagickWand (C), ChMagick (Ch), ImageMagickObject (COM+), Magick++ (C++), JMagick (Java), JuliaIO (Julia), L-Magick (Lisp), Lua (LuaJIT), NMagick (Neko/haXe), Magick.NET (.NET), PascalMagick (Pascal), PerlMagick (Perl), MagickWand for PHP (PHP), IMagick (PHP), PythonMagick (Python), magick (R), RMagick (Ruby), or TclMagick (Tcl/TK). With a language interface, use ImageMagick to modify or create images dynamically and automagically.

Prerequisites

ColorSpace

Understanding color spaces like RGB, CMYK, sRGB is helpful when working with ImageMagick.

Image Processing

Basic knowledge of image processing concepts helps when using the more advanced features.

Image Format

Familiarity with different image formats and their properties.

Installation

Linux (Debian/Ubuntu)

apt-get install imagemagick

Linux (RHEL/CentOS)

yum install imagemagick

MacOS

brew install imagemagick

Memory Constraints

For memory-related issues: https://github.com/google/sanitizers/wiki/AddressSanitizer

Basic Commands

Show ImageMagick Info

convert -version
identify -list all

Verify Installation

convert logo: logo.png

Format Conversion

TIFF to PNG

mogrify -background black -format png -depth 8 *.tiff

SVG to PNG

mogrify -background black -format png -depth 8 *.svg

JPG to jpg (Normalize Extension)

mogrify -format jpg *.JPG

WebP to JPG

convert input.webp output.jpg
mogrify -format jpg *.webp

DICOM to JPG

convert *.DCM output.jpg

Multiple Images to PDF

convert *.jpg document.pdf

PDF to Images (One Per Page)

convert -density 300 document.pdf page%03d.jpg

note: PDF to Images (One Per Page) The convert command is deprecated in IMv7, use "magick" instead of "convert" or "magick convert"

High-Quality JPEG Conversion

convert input.png -quality 92 -sampling-factor 4:2:0 output.jpg

Resizing and Transformations

Resize by Percentage

mogrify -resize 50% *.png

Resize to Exact Dimensions (Ignoring Aspect Ratio)

mogrify -resize 750x750\! *.jpg

Create a Thumbnail (Preserving Aspect Ratio)

convert input.jpg -thumbnail 150x150 thumbnail.jpg

Rotate Image

mogrify -rotate 90 *.jpg

Flip (Vertical Mirror)

convert input.jpg -flip output.jpg

Flop (Horizontal Mirror)

convert input.jpg -flop output.jpg

Add Border

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

Crop Image

convert input.jpg -crop 300x200+50+50 output.jpg

Split Large Image into Tiles

convert -crop 512x512 +repage large.tif tiles/image_%d.tif

Create a 3D Rotation Effect

# Requires additional scripts
# See: http://www.fmwconcepts.com/imagemagick/rotate3D/index.php

Color Adjustments

Convert to Grayscale

convert input.jpg -colorspace Gray output.jpg
for file in *.png; do convert $file -colorspace Gray $file; done

Convert from Grayscale to RGB

mogrify -type TrueColorMatte -define png:color-type=6 *.png

Colorspace Conversion

convert input.tif -colorspace RGB output.tif

Apply Color Profile Conversion

convert input.jpg -profile sRGB.icc -profile AdobeRGB.icc output.jpg

Adjust Brightness and Contrast

convert input.jpg -brightness-contrast 10x15 output.jpg

Invert Colors (Create Negative)

convert input.jpg -negate negative.jpg

Make Background Transparent

convert input.jpg -transparent white output.png

Apply Sepia Tone Effect

convert input.jpg -sepia-tone 80% sepia-output.jpg

Image Composition

Append Images Horizontally

convert *.jpg +append horizontally_appended.jpg

Append Images Vertically

convert *.jpg -append vertically_appended.jpg

Create a Montage

montage *.jpg -geometry 200x200+5+5 -background lightblue montage.jpg

Create Composite with Overlay

composite -gravity center overlay.png base.jpg output.jpg

Create Before/After Comparison

convert before.jpg after.jpg +append comparison.jpg

Text and Annotations

Add Text to Image

convert input.jpg -fill white -pointsize 24 -gravity southeast -annotate +10+10 'Copyright 2025' output.jpg

Add Watermark

convert input.jpg -gravity southeast -stroke '#FFFFFF' -strokewidth 2 -annotate +5+5 'Watermark' -stroke none -fill '#FFFFFF88' -annotate +5+5 'Watermark' output.jpg

Special Effects

Apply Blur Effect

convert input.jpg -blur 0x8 blurred-output.jpg

Create a Vignette Effect

convert input.jpg -vignette 0x20 vignette.jpg

Apply Charcoal Sketch Effect

convert input.jpg -charcoal 2 sketch.jpg

Create Polaroid-Style Image

convert input.jpg -bordercolor white -border 10 -background black -rotate 6 -background white -polaroid 10 polaroid.jpg

Apply Fisheye Effect

# Requires additional scripts
# See: http://www.fmwconcepts.com/imagemagick/fisheye2rect/index.php

Batch Processing

Convert All Images in a Folder

mogrify -format jpg *.png

Apply Same Edit to Multiple Images

mogrify -resize 800x600 -quality 85 *.jpg

Batch Resize and Add Watermark

for file in *.jpg; do
  convert "$file" -resize 1024x768 -fill white -pointsize 20 -gravity southeast \
  -annotate +10+10 'Copyright 2025' "watermarked_$file"
done

Rename Files with Prefix

for filename in *.png; do mv "$filename" "prefix_$filename"; done

Rename Files by Pattern

for f in *.jpg; do mv "$f" "$(echo "$f" | sed s/IMG/VACATION/)"; done

Reduce JPEG Filesize

convert -resize 100% -strip -quality 90 input.jpg output.jpg

Create PNG with Transparency

convert -resize 100% -transparent -strip -quality 90 input.png output.png

Animation and GIFs

Create GIF from Sequence of Images

convert -delay 20 -loop 0 frame*.jpg animated.gif

Extract Frames from Animated GIF

convert animated.gif -coalesce frame%03d.png

Optimize GIF Filesize

convert input.gif -layers optimize optimized.gif

Resize Animated GIF

convert input.gif -coalesce -resize 50% -layers optimize output.gif

Image Analysis

Get Basic Image Information

identify image.jpg

Get Detailed Image Properties

identify -format '%w X %h %[channels] %[bit-depth] %x x %y\n' input.jpeg

Show Verbose Image Information

identify -verbose image.jpg

Calculate Image Statistics

convert image.jpg -format "%[mean] %[standard-deviation]" info:

Check Image Histogram

convert image.jpg -define histogram:unique-colors=true histogram:info:

Advanced Operations

SVG Fill Replacement

find ./ -type f -name '*.svg' | xargs -I{} sed -i_old -n -e 's/polygon fill="none"/polygon fill="white"/g;p;' {}

Limit Output Filesize

mogrify -define jpeg:extent=5100kb *.png

Create Mosaic of Images

montage -geometry 200x200+5+5 -background lightblue *.jpg mosaic.jpg

Best Practices

  • Use GraphicsMagick for faster processing when applicable
  • Use appropriate colorspace for your target medium
  • Be mindful of memory usage for large images
  • Set appropriate quality when saving to lossy formats

Tips

  • Use -strip to remove metadata and reduce file size
  • When working with transparency, use PNG rather than JPG
  • For complex scripts, consider using ImageMagick with shell scripting
  • Use mogrify for in-place edits and convert for creating new files

Troubleshooting

Contributing

Here's how to contribute to this cheat sheet:

  1. Fork the repository
  2. Open README.md
  3. Make your changes
  4. Submit a pull request

Your contributions will be greatly appreciated!

References

About

ImageMagick Cheat Sheet

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published