Bash script to convert pictures using ImageMagick

If you have ImageMagick installed, here’s a simple bash script that allows you to convert a whole lotta pictures in a folder to a different size. Just modify the folder names to reflect where your photos are stored :

#!/usr/bin/env bash

# This program converts all the pictures that are stored in the folder To-Process to half their size
# and names the resulting photos the same but with -r added to it.
# For this, it uses the ImageMagick programs, so these need to be installed ! Either download a binary version or
# compile them yourself (but you need libjpg at a minimum compiled/installed as well.)
# The resulting photos can be imported in iPhoto.

username = <your username here>

# This processes all JPG pics that are in the folder
for photo in /Users/$username/Pictures/To-Process/*.JPG
echo “Converting $photo”
# Using the IM convert program
convert -resize 50% $photo ${photo%%.*}-r.jpg

mv /Users/$username/Pictures/To-Process/*-r.jpg /Users/$username/Pictures/Processed

Took me a hour or two to go back reading the bash manuals and tutorials and get it working right. As for ImageMagick, you can either download binaries for OS X (of for windows for that matter) or compile your own. Remember though that you also need to have libjpeg installed as IM depends on this on compile time.

Yes, of course you can do this with other programs, but this is all part of my plan for getting a workflow up and running to process and store my photos. More on this later.

One thought on “Bash script to convert pictures using ImageMagick”

Comments are closed.