I found myself wanting to batch convert a load of psd files to jpegs today, so I went about looking for a way to do it via the command line.

The tool I chose was Imagemagick. At first I was going to use the tool ‘mogrify’ but it doesnt seem to support the -flatten parameter even though it says it does in the manual… hmmm. The flatten param is needed when converting a psd because of course the psd is multi layer so if you try convert to jpeg without flattening it will generate a jpeg for each layer.

I opted for the standard ‘convert’ command with a little bash magic. The following little script will process all psd files in a folder to jpeg files. You could easily change it to pass in more parameteres etc.

#!/bin/bash

if [ -z “$1″ ]
then
echo “Usage: please specify a base directory”
exit $E_NOARGS
fi for file in $1/*; do
/usr/bin/convert -quality 80 -flatten $file ${file/psd/jpg}
done