#!/bin/bash

# Copy this into a folder with all of your photos and it will create 
# smaller numbered photos for your gallery.  

# To run this, type ./prepare.sh into your terminal
# Warning!  There is nothing optimized about this script and it runs pretty slowly

# When you're done, you'll have 3 folders inside this one--photos, pics, and 
# thumbs.  Only copy the pics and thumbs directories onto your website.  The
# photos directory will be too big, but you may want to keep these original
# higher quality photos for yourself elsewhere.

# After using this script, run generate.py to create the gallery.

function echo_run() { echo $*; $*; }

mkdir photos
mkdir pics
mkdir thumbs
mv *.jpg photos
ls *.JPG *.png *.PNG *.gif *.GIF | sort -n | while read line ; do
convert $line photos/${line%.*}.jpg; done
ls *.JPG *.png *.PNG *.gif *.GIF | sort -n | while read line ; do rm $line; done
cd photos
number=0
for file in *; do mv "$file" `echo $file | sed -e 's/  */_/g' -e 's/_-_/-/g'`; done
ls | sort -n | while read line ; do number=$(($number+1)) ; mv $line $number.jpg ; done
for i in `ls` ; do echo_run convert -resize x480 -quality 80% $i ../pics/${i}; done
for i in `ls` ; do echo_run convert -resize x75 $i ../thumbs/$i; done
