Bulk resizing multiple images with GraphicsMagick

Tutorial on how to bulk resize multiple images in the same directory using the GraphicsMagick command line utility.


Recently I have started to use a D-SLR for taking photographs. The images it stores are 14 mega pixel, or 4672x3104 pixels in size. While these are great for printing, they are much too large for uploading onto websites like Facebook or Flickr. Resizing them with a tool like PhotoShop is an option, but if you have many files to resize this can become cumbersome and time consuming.

Introduction to GraphicsMagick

GraphicsMagick is an open source command line tool for creating and manipulating images. According to their website:

"GraphicsMagick is the swiss army knife of image processing. Comprised of 259K physical lines (according to David A. Wheeler's SLOCCount) of source code in the base package (or 900K including 3rd party libraries) it provides a robust and efficient collection of tools and libraries which support reading, writing, and manipulating an image in over 88 major formats including important formats like DPX, GIF, JPEG, JPEG-2000, PNG, PDF, PNM, and TIFF."

GraphicsMagick is useful for performing bulk operations on images in the same directory. In this tutorial, I will show you how to use it to bulk resize all of the images in a directory to make them 25% the size of the original versions. The new smaller versions will be placed in a sub-directory called low-res.

Step 1: download GraphicsMagick and install

I am using Windows on my laptop, so I downloaded one of the Windows binaries and installed it (there are other versions for different operating systems):

Windows binaries of GraphicsMagick

Step 2: navigate to the images directory in DOS, then create a new low-res directory

From the DOS (or BASH if you are on Linux) command prompt, run the following commands:

cd pathtoMyPhotos
mkdir low-res

Step 3: use the mogrify command supplied with GraphicsMagick to resize the images

Now from within your MyPhotos directory, run the following from the command line:

gm mogrify -output-directory low-res -resize 25% *.JPG

The command will use GraphicsMagick's mogrify command to create copies of each file ending with a .JPG extension in the low-res directory, which are exactly 25% the size (pixel-wise) of the source images. The source images will remain unchanged.


GraphicsMagick, like it's predecessor ImageMagick, is a very powerful tool with many options. I am using it here for a very simple task, but it is capable of doing much more provided you are comfortable working at the command line. Check the FAQ for more examples:

GraphicsMagick FAQ

John Collins

I have been writing about web technology and software development since 2001. I am the developer of the Alpha Framework for PHP, and the five.today personal productivity app. I love open source, technology, and economics.