jump to navigation

Shell script to prepare photos for the web July 9, 2007

Posted by maxmil in : bash , trackback

Just needed to optimize a folder of jpg’s for the Web. I needed to:

1) Reduce their dimensions so that their longest dimension was at most 700px.
2) Reduce their quality to 75%

Using the convert command that forms part of imagemagick this was easy. The script takes two parameters, an input directory and an output directory. Both without slashes.


#!/bin/bash
if [ $# -ne 2 ]
then
echo "usage: $0 [input directory] [output directory]" >&2
fi
for file in $1/*
do
convert $file -resize 700x700 -quality 75 $2/`basename $file`
done

Comments»

no comments yet - be the first?