Archive of TideArt content.

Thu, Nov 8 2012 2:01:01 UTC

Why every content creator needs ImageMagick

There are software programs that are well known, and that any artist or designer has in his or her toolbox. Adobe Photoshop comes to mind, being the most popular digital graphics software by far. One name you may not know much about however is ImageMagick. Yet, this small, free and open source application can be used to make your life much easier by automating tasks that would otherwise be very hard or time consuming to do. Here's why you may want to get to know ImageMagick.

ImageMagick is one of these rare tools that few people know about, but the ones who do always consider it an invaluable resource. The reason is because this isn't a fancy graphics program, in fact there's no graphical user interface at all, it's a command line tool. But while that may be daunting at first, ImageMagick is actually fairly easy to use, and the fact that it is run from a command line means you can also integrate it into scripts, which is what many people end up doing.

The first thing you should do in order to get started is go to the download page and get the software. They have a binary for almost every platform, with a Windows installer near the bottom of the page. Getting it installed on your system is simple, usually a matter of a few clicks. The site explains what to do for every platform that they support.

Now that it's installed, we can see examples of things you can do with this tool. Let's say you have an image in PNG format and you want to convert it to JPEG. Simply open up a command line by typing cmd in the search bar of your Start menu, then navigate to whichever folder your files are in, for example:

cd C:\my files

Once that's done, you can use the convert command to convert your image into a new format:

convert image.png newimage.jpg

Now obviously, if this is all you wanted to do, then you may be thinking that this would be a lot faster if you simply opened the image in Photoshop, or even Paint. But this is just the beginning. Let's say you wanted to resize the image by 50% also:

convert image.png -resize 50% newimage.jpg

That's more useful, but again it could still be done easily in a graphics application. But let's say you have 100 images, and you need to quickly create a series of thumbnails for them, at 40x40 resolution. Simply place them all inside of a folder, then use:

convert *.jpg -size 40x40 thumb.jpg

This will create your 100 thumbnails with names starting with thumb, and the whole process will take seconds. Try to do that in Paint! If you're going to do a lot of batch processing, another command you should know about is mogrify. You may have noticed the previous command created a series of thumbnails with the names thumb-0, thumb-1, and so on. But what if you wanted the images to simply be resized onto themselves, without changing the file name? This is what mogrify is for. As such, you need to be careful, because it will overwrite any existing file without asking for confirmation. So always back your original files up. Here is the command to convert every JPEG in the folder into 40x40 thumbnails:

mogrify -thumbnail 40x40 *.jpg

Similarly, you can also use the command to convert every JPEG into PNG files. This time it will write new files of the same name but with a different extension, overwriting any existing file with that extension:

mogrify -format png *.jpg

So as you can see, if you deal with a large number of images, chances are that at some point you will need to apply a filter, resize, change format, or do something to a bunch of them, and that's where ImageMagick comes into use. But we're just scratching the surface. The site has thousands of examples of things you can do with this software, but here are a couple of useful commands. Let's say you have a batch of JPEG images, and you want to send them to someone. A good way to do this is by converting them into a PDF. Here's how to do it:

convert *.jpg myimages.pdf

You can also crop an image so that you only see a rectangle of 40x40, starting at 20 pixels from the top, and 15 pixels from the left:

convert image.jpg -crop 40x40+15+20 newimage.jpg

Now let's add some blur, with a radius of 2 and sigma of 2:

convert image.jpg -blur 2x2 newimage.jpg

You can even draw things on an image, such as a line or text. The following command will draw a small circle centered at 10x10:

convert image.jpg -draw 'circle 10,10 50,50' newimage.jpg

Finally, you can create an animated GIF with ImageMagick. This command will make a looping animation with a series of JPEG image files, with 30 hundredths of a second delay between each frame:

convert -delay 30 -loop 0 *.jpg myanimation.gif

These examples could go on forever, but hopefully by now you realize just how powerful ImageMagick is. And because everything is done through the command line, it's very easy to integrate these commands into scripts or whatever workflow you use. Hopefully, next time you're trying to make a change to an image that your graphics program can't easily do, or want to do batch processing of some kind, you will know where to go.

Back to index

© 2007-2019 Patrick Lambert - All resources on this site are provided under the MIT License - You can contact me at: contact@dendory.net