Picture Resizer Script
From Notes
Use this script to process a directory of pictures.
#/bin/bash
if [ ! -d $1 ]; then
echo "$1 is not a directory"
exit
fi
# set up directory names
dir=$1
picDir="gallery/$dir/pics"
thumbDir="gallery/$dir/thumbs"
albumDir="gallery/$dir/album"
album="$albumDir/album.png"
if [ -f $album ]; then
rm -f $album
fi
if [ ! -d $picDir ]; then
mkdir -p $picDir
fi
if [ ! -d $thumbDir ]; then
mkdir -p $thumbDir
fi
if [ ! -d $albumDir ]; then
mkdir -p $albumDir
fi
for i in $dir/*; do
# make a temp for the thumbnail
temp=`mktemp`
# get extension (type) of file
ext=`echo $i | awk -F. '{print $NF;}'`
# get the filename
basename=`basename $i .$ext`
# define pic, thumbnail and album picture names
pic="$picDir/$basename.$ext"
thumb="$thumbDir/$basename.$ext"
# Make thumbnail
echo "Thumbnail: $thumb"
convert $i -thumbnail 33856@ -gravity center -background transparent -extent 184x184 $temp
convert -page +4+4 $temp -matte \( +clone -background black -shadow 90x4+4+4 \) +swap -background none -mosaic $thumb
# Make the album pic, if not already exists.
if [ ! -f $album ]; then
echo "Album: $album"
convert $temp -bordercolor white -border 6 -bordercolor grey60 -border 1 -bordercolor none -background none \( -clone 0 -rotate `convert null: -format '%[fx:rand()*30-15]' info:` \) \( -clone 0 -rotate `convert null: -format '%[fx:rand()*30-15]' info:` \) \( -clone 0 -rotate `convert null: -format '%[fx:rand()*30-15]' info:` \) \( -clone 0 -rotate `convert null: -format '%[fx:rand()*30-15]' info:` \) -delete 0 -border 100x80 -gravity center -crop 240x240+0+0 +repage -flatten -trim +repage -background black \( +clone -shadow 60x4+4+4 \) +swap -background none -flatten $album
fi
rm -f $temp
# Make picture
echo "Picture: $pic"
convert $i -resize "660>" $pic
done

