3 # copyright 2012,2013 Arun Persaud <arun@nubati.net>
5 # This file is part of photo-tags.
7 # Photo-tags is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # Photo-tags is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Photo-tags. If not, see <http://www.gnu.org/licenses/>.
26 CONFIG_FILE="config.ini"
28 # copied and modified from http://mark.aufflick.com/blog/2007/11/08/parsing-ini-files-with-sed
29 eval `sed -e 's/[[:space:]]*\=[[:space:]]*/=/g' \
32 -e 's/[[:space:]]*$//' \
33 -e 's/^[[:space:]]*//' \
34 -e "s/^\(.*\)=\([^\"']*\)$/\1=\"\2\"/" \
38 dbprefix=${dbprefix//\//\\\/}
39 limit=`$NICE sqlite3 $LOCALDB "select count(*) from photos"`
44 echo "Usage: $0 [OPTIONS]"
46 echo " -r remove metadata from pictures"
47 echo " -l NUMBER only process NUMBER pictures"
51 while getopts ":rl:h" opt; do
64 echo "Invalid option: -$OPTARG" >&2
68 echo "Option -$OPTARG requires an argument." >&2
75 #make sure we are in the correct directory
77 #make sure we can access the database
78 if [ ! -s $LOCALDB ] ; then
79 echo "Can't find database...exiting."
83 #create directories, iff they don't exist
84 if [ ! -d "Photos-small" ] ; then
85 echo "creating local directory to store photos of reduced size"
89 if [ ! -d "Photos-tiny" ] ; then
90 echo "creating local directory to store thumbnails"
98 while [ $done -lt $limit ] ; do
99 echo "skipping $offset pics, getting $limit new pics to work on..."
100 # handle white space in filename correctly
101 FILES=`$NICE sqlite3 $LOCALDB "select replace(base_uri||'/'||filename,' ','%20') from photos limit $offset,$limit"`
103 if [ "x$FILES" != "x" ] ; then
104 #found some files, process them
105 for file in $FILES; do
106 # handle white space in file names
107 file=${file/file:\/\/$dbprefix/}
109 dir=`dirname "$file"`
110 base=`basename "$file"`
112 if [ ! -s "Photos-tiny/$dir/$base" ] ; then
113 mkdir -p Photos-tiny/$dir
114 $NICE convert "$dirprefix/$file" -auto-orient -resize x100 -quality 80% "Photos-tiny/$dir/$base"
115 if [ $removemeta=1 ]; then
116 $NICE jhead -q -se -purejpg "Photos-tiny/$dir/$base"
117 $NICE jhead -q -se -dt "Photos-tiny/$dir/$base"
118 $NICE jhead -q -se -mkexif "Photos-tiny/$dir/$base"
119 $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"
123 if [ ! -s "Photos-small/$dir/$base" ] ; then
124 mkdir -p Photos-small/$dir
125 $NICE convert "$dirprefix/$file" -auto-orient -resize x600 -quality 80% "Photos-small/$dir/$base"
126 if [ $removemeta=1 ]; then
127 $NICE jhead -q -se -purejpg "Photos-small/$dir/$base"
128 $NICE jhead -q -se -dt "Photos-small/$dir/$base"
129 $NICE jhead -q -se -mkexif "Photos-small/$dir/$base"
130 $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"
135 echo -n -e "$((done/2)) \r"
141 #get ready to get the next photos
142 offset=$((offset+$limit))