blob: b652cb30f067678256f044c9c4b1facacf81fa7f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
#!/bin/bash
NICE="nice -19"
# init some variables
removemeta=0
# parse ini file
CONFIG_FILE="config.ini"
# copied and modified from http://mark.aufflick.com/blog/2007/11/08/parsing-ini-files-with-sed
eval `sed -e 's/[[:space:]]*\=[[:space:]]*/=/g' \
-e 's/;.*$//' \
-e 's/\[.*\]//' \
-e 's/[[:space:]]*$//' \
-e 's/^[[:space:]]*//' \
-e "s/^\(.*\)=\([^\"']*\)$/\1=\"\2\"/" \
< $CONFIG_FILE `
LOCALDB=$fspotdb
dbprefix=${dbprefix//\//\\\/}
limit=`$NICE sqlite3 $LOCALDB "select count(*) from photos"`
function usage()
{
echo "Usage: $0 [OPTIONS]"
echo " Options:"
echo " -r remove metadata from pictures"
echo " -l NUMBER only process NUMBER pictures"
}
# parse command line
while getopts ":rl:h" opt; do
case $opt in
r)
removemeta=1
;;
l)
limit=$OPTARG
;;
h)
usage
exit 0
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
#make sure we are in the correct directory
#make sure we can access the database
if [ ! -s $LOCALDB ] ; then
echo "Can't find database...exiting."
exit 1
fi
#create directories, iff they don't exist
if [ ! -d "Photos-small" ] ; then
echo "creating local directory to store photos of reduced size"
mkdir Photos-small
fi
if [ ! -d "Photos-tiny" ] ; then
echo "creating local directory to store thumbnails"
mkdir Photos-tiny
fi
done=0
offset=0
FILES=""
while [ $done -lt $limit ] ; do
echo "skipping $offset pics, getting $limit new pics to work on..."
# handle white space in filename correctly
FILES=`$NICE sqlite3 $LOCALDB "select replace(base_uri||'/'||filename,' ','%20') from photos limit $offset,$limit"`
if [ "x$FILES" != "x" ] ; then
#found some files, process them
for file in $FILES; do
# handle white space in file names
file=${file/file:\/\/$dbprefix/}
file=${file//\%20/ }
dir=`dirname "$file"`
base=`basename "$file"`
if [ ! -s "Photos-tiny/$dir/$base" ] ; then
mkdir -p Photos-tiny/$dir
$NICE convert "$dirprefix/$file" -auto-orient -resize x100 -quality 80% "Photos-tiny/$dir/$base"
if [ $removemeta=1 ]; then
$NICE jhead -q -se -purejpg "Photos-tiny/$dir/$base"
$NICE jhead -q -se -dt "Photos-tiny/$dir/$base"
$NICE jhead -q -se -mkexif "Photos-tiny/$dir/$base"
$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"
fi
done=$((done+1))
fi
if [ ! -s "Photos-small/$dir/$base" ] ; then
mkdir -p Photos-small/$dir
$NICE convert "$dirprefix/$file" -auto-orient -resize x600 -quality 80% "Photos-small/$dir/$base"
if [ $removemeta=1 ]; then
$NICE jhead -q -se -purejpg "Photos-small/$dir/$base"
$NICE jhead -q -se -dt "Photos-small/$dir/$base"
$NICE jhead -q -se -mkexif "Photos-small/$dir/$base"
$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"
fi
done=$((done+1))
fi
echo -n -e "$((done/2)) \r"
done
else
break;
fi
#get ready to get the next photos
offset=$((offset+$limit))
done
|