Back to homepage

ImageMagick quick command reference

This page is not really a tutorial but a quick command reference for ImageMagick.


ImageMagick is a set of command line programs useful for image transformations.
You may think that at this day and age nobody has any need for command line tools, 
especially for image transformations. 
If you are of that opinion, consider a case where you need to resize 1000 images. 
If you do it manually in Photoshop, GIMP or in some other graphical user interface program, 
it will take you a week or more. Using ImageMagick, you can convert them all in few minutes. 

Incredible array of transformations are possible: format change, flipping, resizing,
cutting, animation creation...

If you think that nobody needs to convert 1000's of images, think again. 
If you are doing stop-motion animation for example, your digital camera images are of too 
high resolution to use in animation, so you need to resize them. 

If you are doing web site work, and you do not resize images that you put on your website 
(or at least use thumbnails), you can easily hit website bandwidth limit that your provider sets. 
In addition, pages will take a long time to load, even if your visitors have a broadband internet.

With case for ImageMagick given, some examples will be presented. Those
will be added to occasionally.

Change image size

Convert image to smaller size:

convert 0001.JPG -resize 25% 0001s.JPG

This will retain your original 0001.JPG image and create smaller 0001s.JPG image, 
only 25% size of original.

convert Imagemagick-logo.png -resize 50% Imagemagick-logo-small.gif

This creates smaller version of ImageMagick logo but now in different image format as well (gif).
Size of new image is only 50% of the old one.

Replace all current jpg images in directory (folder) with their smaller versions. 
DANGEROUS, use only with copies of your originals in separate directory!

mogrify -resize 320x240 *.jpg

Rename all files in a directory (Linux BASH shell)

This in not related to ImageMagick, but may come in handy. 
For example let's say you want to convert hundreds of images to thumbnails, 
but you also need them to have different names from the originals. 

1. Place copies of your original images in a separate directory. 
In my case they all had names like dscf0123.jpg, dscf0124.jpg, dscf0125.jpg, ...

2. Now say you want to rename all of those "dscf****.jpg" images into "thumb****.jpg". 
In Linux BASH command line type:

for f in *;do mv $f ${f/dscf/thumb};done

and press Enter. 
Note: there is a space between $f and following $ in the above line.

Now your files have names like: thumb0123.jpg, thumb0124.jpg,
thumb0125.jpg, ... etc.

3. Now you are ready to convert them all to smaller size. 
This is DESTRUCTIVE resizing to 10% of original size. 

Use only with copies of your images in a separate directory!

mogrify -resize 10% *.jpg

It takes few minutes on a Pentium 4 with 70 ten-megapixel images to be converted.

Change image formats

We can convert all of our PNG images to the JPEG format. 
PNG originals remain in directory.

mogrify -format jpg *.png


Converts series of gifs (with names from 0001.gif ... 9999.gif) to gif animation, 
with 400 ms delay between frames, with resolution 800x600, without looping the video.

convert -delay 40 -size 800x600 -loop 1 ????.gif animation.gif

If you want the video to loop, use -loop 0 option. 
Four ???? can be replaced with three ??? if your images run from 001.gif up to 999.gif,
with two ?? if your images run from 01.gif to 99.gif, etc. 
Option -delay 40 means 400 ms delay between the final video frames, it is not a mistake.


Use at your own risk, with copies of your images in a separate directory. 
If you don't know what you are doing, don't do it.

ImageMagick website

Back to homepage