Batch-processing Image Files
Now, let’s say that you have a whole directory full of image files that you need to manipulate all in the same way. Using a GUI-type graphics program will be quite tedious, because you’ll only be able to work with one file at a time. With ImageMagick, just write a simple script to do the work for you. For example, let’s look at the resize.sh
script:
#!/bin/bash
for picture in *.jpg; do
convert -resize 15% "$picture" "${picture%.jpg}_small.jpg"
done
As you see, it’s really not that much different from the rename_extension.sh
script that I’ve already shown you. Just a simple for
loop and a bit of variable expansion is all you need. And of course, you can replace this -resize
command with any other ImageMagick command you want.
Okay, this pretty much does it for the simple stuff. Let’s move on to the more complex stuff.