better display of description and time for a single photo
[photo-tags.git] / create_thumbnails.sh
index 6bae6bbdc01836cc09518d9b85407ad58f25ba60..3a6ad69872484d06c43dbf4c6824a38751781430 100755 (executable)
@@ -1,9 +1,28 @@
 #!/bin/bash
 
+#    copyright 2012,2013 Arun Persaud <arun@nubati.net>
+#
+#    This file is part of photo-tags.
+#
+#    Photo-tags is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation, either version 3 of the License, or
+#    (at your option) any later version.
+#
+#    Photo-tags is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with Photo-tags.  If not, see <http://www.gnu.org/licenses/>.
+
+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 +36,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 +95,11 @@ done=0
 offset=0
 FILES=""
 
-while [ $done -lt 100 ] ; do
-   echo "skipping $offset pics, getting 50 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 +108,29 @@ while [ $done -lt 100 ] ; 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 +138,6 @@ while [ $done -lt 100 ] ; do
        break;
    fi
 
-   #get ready to get the next 100
-   offset=$((offset+50))
+   #get ready to get the next photos
+   offset=$((offset+$limit))
 done