Showing 1 changed files with 17 additions and 23 deletions
+17 -23
thumbnails
... ...
@@ -31,7 +31,7 @@ if ! which convert > /dev/null; then
31 31
     exit 1
32 32
 fi
33 33
 
34
-sqlcmd="select path, rotation from ${dbprefix}images \
34
+sqlcmd="select path from ${dbprefix}images \
35 35
            where id in ( \
36 36
               select distinct image_id from ${dbprefix}image_category \
37 37
                   where category_id in ( \
... ...
@@ -39,38 +39,32 @@ sqlcmd="select path, rotation from ${dbprefix}images \
39 39
                   ) \
40 40
            )"
41 41
 
42
-for image in $(mysql -N -u $dbuser -p${dbpasswd} $dbname <<< $sqlcmd | awk '{printf("file=%s;rotation=%s\n",$1,$2*90)}'); do
43
-    eval "$image"
42
+IFS=$'\n'
43
+for file in $(mysql -N -u $dbuser -p${dbpasswd} $dbname <<< $sqlcmd); do
44 44
     format=""
45 45
     fnNoExt="${file%.*}"
46 46
     fnExt="${file##*.}"
47 47
     fnPath="${file%/*}"
48
-    mkdir -p $destDir/$fnPath
49
-    cmd="convert $site/$file -write mpr:image +delete "
48
+    test $fnExt = 'mp4' && continue
49
+    cmd="sudo -u www-data convert \"$site/$file\" -write mpr:image +delete "
50
+    count=0
50 51
     for ((i=0; i<${#imgsize[@]}; i+=3)); do
51
-        if ! test -e ${destDir}/${fnNoExt}-${imgsize[i]:0:2}.$fnExt; then
52
+        if ! test -e "${destDir}/${fnNoExt}-${imgsize[i]:0:2}.$fnExt"; then
52 53
             format+="${imgsize[i]} "
53
-            cmd+="mpr:image -filter Lanczos -strip -quality 95 -interlace line -sampling-factor 4:2:2 "
54
-            if test $rotation -ne 0; then
55
-                cmd+="-rotate -$rotation -orient top-left "
56
-            fi
57
-            cmd+="-resize ${imgsize[i+1]}x${imgsize[i+2]} -write ${destDir}/${fnNoExt}-${imgsize[i]:0:2}.$fnExt +delete "
54
+            cmd+="mpr:image -filter Lanczos -auto-orient -strip -quality 95 -interlace line -sampling-factor 4:2:2 "
55
+            cmd+="-resize ${imgsize[i+1]}x${imgsize[i+2]} -write \"${destDir}/${fnNoExt}-${imgsize[i]:0:2}.$fnExt\" +delete "
56
+            let count++
58 57
         fi
59 58
     done
60
-    cmd=$(awk '{for (i=1; i<=NF - 3; i++) printf("%s ", $i); printf("%s", $(NF-1))}' <<< $cmd)
61 59
     if test -n "$format"; then
62 60
         echo "$site/$file : $format"
63 61
         echo -n "please wait... "
64
-        if test -z "$2"; then
65
-            eval "$(echo -e sudo -u www-data nice -20 $cmd)"
66
-            for ((i=0; i<${#imgsize[@]}; i+=3)); do
67
-                test -s ${destDir}/${fnNoExt}-${imgsize[i]:0:2}.$fnExt || echo "missing extension ${imgsize[i]:0:2}.$fnExt"
68
-            done
69
-            echo "done, sleeping..."
70
-            sleep 10
71
-        else
72
-            echo $cmd
73
-            echo
74
-        fi
62
+        cmd=$(sed -r 's/^(.+) -write (.*) \+delete $/\1 \2/' <<< $cmd)
63
+        eval $(echo -e nice -20 $cmd)
64
+        for ((i=0; i<${#imgsize[@]}; i+=3)); do
65
+            test -s "${destDir}/${fnNoExt}-${imgsize[i]:0:2}.$fnExt" || echo "missing extension ${imgsize[i]:0:2}.$fnExt"
66
+        done
67
+        echo "done, sleeping..."
68
+        sleep $(( 2 + $count ))
75 69
     fi
76 70
 done