Thursday, April 14, 2011

Batch convert images with Imagemagick

When I am writing a distro review (actually, pretty much any type of article I put together), I usually spend quite a significant amount of time putting together screenshots of noteworthy features, relevant or unexpected behaviors and why not say it, bugs and errors. I believe those pictures support the text and provide elusive comments like "very cool branding" or "beautiful icon theme" with enough visual context.

Taking those screenshots is often a pretty simple and quick process. The burden comes when I have to open all of them and start saving them as JPG, in an attempt to reduce their size and make them more "Internet-compatible". What's even worse is that each of those files must also be reduced in size to provide thumbnails that I can instert in my articles. Long story short, each PNG file has to be converted into a full size JPG image, then reduced to match thumbnail size and saved as a separate JPG image.

Those of you who know about the convert command and the IMAGEMAGICK PROJECT are probably scratching your heads, wondering why I am wasting my time in something that can easily be achieved from the command line, but what can I say... I only learned about this awesome tool very recently!

CONVERT, CONVERT, CONVERT...

Alright, so if you didn't know about the convert command, just a a quick look at its help page from the command line should give you an overview of what it offers. Assuming it is installed on your machine (if not, from a terminal type sudo apt-get install imagemagick), type the following from a terminal:

convert --help

To give you a quick idea, this powerful command can pretty much perform any operation or set of operations on an image that one could do using GIMP. Here's a short list of highlights:

  • Convert image format
  • Resize
  • Crop
  • Switch to sepia or B/W.
  • Colorize
  • Change contrast and brightness balance
  • Merge layers
  • Gamma correction
  • Flip/flop image vertically/horizontally.
  • Enhance
  • Many, many more...

This is all very nice, but you may be wondering what all of this has to do with my Blog and all that time I waste manually converting images and creating thumbnails? Well, thanks to the power of the command line, I could automate the whole process, so I now get all my image conversion and thumbnail creation done with a couple clicks in just a few seconds!

PICONVERT

Let me introduce PiConvert.sh, a simple script I created to get all this image conversion business automated. Its functionality is simple and perhaps limited to my needs, but could easily be tweaked to extend it if needed. Here's how it works:

1.- After running the script, a welcome dialog appears which briefly explains how things work:



2.- If the user decides to continue, a file-selection dialog shows up, allowing for single or multiple file selection (the images that should eventually be converted).



3.- Next is a directory-selection dialog, which allows the user to select the destination where those converted files will be saved to.



The script will now proceed to convert files and create the corresponding thumbnails, all of which will be saved at the specified target location.

USE PICONVERT!

If PiConvert.sh provides functionality you think you could use yourself, here's how to use it:

1.- Download the script from HERE.
2.- Review the code to make sure it doesn't do anything that could harm your computer or privacy! (ALWAYS do it when you download a script of any kind)
3.- Grant execution rights to the script following a method of your choice.
4.- Double-click on the script to execute.

NOTE: PiConvert.sh is obviously dependent on imagemagick. The script will check for this dependency and error out if it is not met.

3 comments:

  1. Hi, perhaps you find the mogrify command in imagemagick useful as well. It's what I usually use for batch conversion. Beware though that without a new format specified it overwrites the old files.

    Keep posting, it's always a nice read :-)

    ReplyDelete
  2. Thanks Patrick! I will look into it, thanks for the tip.

    ReplyDelete
  3. Hey,
    Really this is an interesting blog post. Keep posting such an amazing blog post.

    Thanks very much!

    ReplyDelete