9 CONFIG_FILE="config.ini"
11 # copied and modified from http://mark.aufflick.com/blog/2007/11/08/parsing-ini-files-with-sed
12 eval `sed -e 's/[[:space:]]*\=[[:space:]]*/=/g' \
15 -e 's/[[:space:]]*$//' \
16 -e 's/^[[:space:]]*//' \
17 -e "s/^\(.*\)=\([^\"']*\)$/\1=\"\2\"/" \
21 dbprefix=${dbprefix//\//\\\/}
22 limit=`$NICE sqlite3 $LOCALDB "select count(*) from photos"`
27 echo "Usage: $0 [OPTIONS]"
29 echo " -r remove metadata from pictures"
30 echo " -l NUMBER only process NUMBER pictures"
34 while getopts ":rl:h" opt; do
47 echo "Invalid option: -$OPTARG" >&2
51 echo "Option -$OPTARG requires an argument." >&2
58 #make sure we are in the correct directory
60 #make sure we can access the database
61 if [ ! -s $LOCALDB ] ; then
62 echo "Can't find database...exiting."
66 #create directories, iff they don't exist
67 if [ ! -d "Photos-small" ] ; then
68 echo "creating local directory to store photos of reduced size"
72 if [ ! -d "Photos-tiny" ] ; then
73 echo "creating local directory to store thumbnails"
81 while [ $done -lt $limit ] ; do
82 echo "skipping $offset pics, getting $limit new pics to work on..."
83 # handle white space in filename correctly
84 FILES=`$NICE sqlite3 $LOCALDB "select replace(base_uri||'/'||filename,' ','%20') from photos limit $offset,$limit"`
86 if [ "x$FILES" != "x" ] ; then
87 #found some files, process them
88 for file in $FILES; do
89 # handle white space in file names
90 file=${file/file:\/\/$dbprefix/}
93 base=`basename "$file"`
95 if [ ! -s "Photos-tiny/$dir/$base" ] ; then
96 mkdir -p Photos-tiny/$dir
97 $NICE convert "$dirprefix/$file" -auto-orient -resize x100 -quality 80% "Photos-tiny/$dir/$base"
98 if [ $removemeta=1 ]; then
99 $NICE jhead -q -se -purejpg "Photos-tiny/$dir/$base"
100 $NICE jhead -q -se -dt "Photos-tiny/$dir/$base"
101 $NICE jhead -q -se -mkexif "Photos-tiny/$dir/$base"
102 $NICE jhead -q -se -cl "This photo belongs to $admin and was taken from $webbase. If you want to use this photo, please contact him." "Photos-tiny/$dir/$base"
106 if [ ! -s "Photos-small/$dir/$base" ] ; then
107 mkdir -p Photos-small/$dir
108 $NICE convert "$dirprefix/$file" -auto-orient -resize x600 -quality 80% "Photos-small/$dir/$base"
109 if [ $removemeta=1 ]; then
110 $NICE jhead -q -se -purejpg "Photos-small/$dir/$base"
111 $NICE jhead -q -se -dt "Photos-small/$dir/$base"
112 $NICE jhead -q -se -mkexif "Photos-small/$dir/$base"
113 $NICE jhead -q -se -cl "This photo belongs to $admin and was taken from $webbase. If you want to use this photo, please contact him." "Photos-small/$dir/$base"
118 echo -n -e "$((done/2)) \r"
124 #get ready to get the next photos
125 offset=$((offset+$limit))