X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=photo-tags.git;a=blobdiff_plain;f=create_thumbnails.sh;h=b652cb30f067678256f044c9c4b1facacf81fa7f;hp=61745386e441d6e4c2c9047388be5776c6cd6877;hb=6a253bce9766ec2128d27d7fd02194dd7ed4afaf;hpb=36bcd32844666ba84b2947387ce195c25d87fadd diff --git a/create_thumbnails.sh b/create_thumbnails.sh index 6174538..b652cb3 100755 --- a/create_thumbnails.sh +++ b/create_thumbnails.sh @@ -1,9 +1,11 @@ #!/bin/bash +NICE="nice -19" + # init some variables removemeta=0 -# parse ini file +# parse ini file CONFIG_FILE="config.ini" # copied and modified from http://mark.aufflick.com/blog/2007/11/08/parsing-ini-files-with-sed @@ -17,15 +19,37 @@ eval `sed -e 's/[[:space:]]*\=[[:space:]]*/=/g' \ 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 ":r" opt; do +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 @@ -54,11 +78,11 @@ done=0 offset=0 FILES="" -while [ $done -lt 200 ] ; do - echo "skipping $offset pics, getting 100 new pics to work on..." +while [ $done -lt $limit ] ; do + echo "skipping $offset pics, getting $limit new pics to work on..." # handle white space in filename correctly - FILES=`sqlite3 $LOCALDB "select replace(base_uri||'/'||filename,' ','%20') from photos limit $offset,100"` - + 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 @@ -67,29 +91,29 @@ while [ $done -lt 200 ] ; do file=${file//\%20/ } dir=`dirname "$file"` base=`basename "$file"` - + if [ ! -s "Photos-tiny/$dir/$base" ] ; then mkdir -p Photos-tiny/$dir - nice -19 convert "$dirprefix/$file" -auto-orient -resize x100 -quality 80% "Photos-tiny/$dir/$base" + $NICE convert "$dirprefix/$file" -auto-orient -resize x100 -quality 80% "Photos-tiny/$dir/$base" if [ $removemeta=1 ]; then - jhead -q -se -purejpg "Photos-tiny/$dir/$base" - jhead -q -se -dt "Photos-tiny/$dir/$base" - jhead -q -se -mkexif "Photos-tiny/$dir/$base" - 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" + $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 + fi if [ ! -s "Photos-small/$dir/$base" ] ; then mkdir -p Photos-small/$dir - nice -19 convert "$dirprefix/$file" -auto-orient -resize x600 -quality 80% "Photos-small/$dir/$base" + $NICE convert "$dirprefix/$file" -auto-orient -resize x600 -quality 80% "Photos-small/$dir/$base" if [ $removemeta=1 ]; then - jhead -q -se -purejpg "Photos-small/$dir/$base" - jhead -q -se -dt "Photos-small/$dir/$base" - jhead -q -se -mkexif "Photos-small/$dir/$base" - 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" + $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 + fi echo -n -e "$((done/2)) \r" done @@ -97,6 +121,6 @@ while [ $done -lt 200 ] ; do break; fi - #get ready to get the next 100 - offset=$((offset+100)) + #get ready to get the next photos + offset=$((offset+$limit)) done