Published on 2009-09-01 by John Collins. Socials: YouTube - X - Spotify - Amazon Music - Apple Podcast |
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.
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.
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
From the DOS (or BASH if you are on Linux) command prompt, run the following commands:
cd pathtoMyPhotos mkdir low-res
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:
Updated 2021 : note that the above post was originally published in 2009, but is left here for archival purposes.