Showing 1 changed files with 34 additions and 18 deletions
+34 -18
thumbnails
... ...
@@ -2,20 +2,36 @@
2 2
 
3 3
 thumbnailsconf=${1:-${0##*/}.conf}
4 4
 test -r "$thumbnailsconf" || exit 1
5
+shift
5 6
 
6
-function set_imgsize () {
7
-    imgsize[${#imgsize[@]}]=$1
8
-    imgsize[${#imgsize[@]}]=$2
9
-    imgsize[${#imgsize[@]}]=$3
10
-}
7
+declare -A imgsize width height
11 8
 
12
-#set_imgsize 'custom' 1656 1242
13
-set_imgsize 'xxlarge' 1224 918
14
-set_imgsize 'xlarge' 1008 756
15
-set_imgsize 'large' 792 594
16
-set_imgsize 'medium' 576 432
17
-set_imgsize 'small' 432 324
18
-set_imgsize 'xsmall' 240 240
9
+imgsize[xxlarge]="1656 1242"
10
+imgsize[xlarge]=" 1224  918"
11
+imgsize[large]="  1008  756"
12
+imgsize[medium]=" 792   594"
13
+imgsize[small]="  576   432"
14
+imgsize[xsmall]=" 432   324"
15
+imgsize[2small]=" 240   180"
16
+
17
+if test $# -gt 0; then
18
+    filter=$(echo $@ | sed 's/ /|/g')
19
+    for size in ${!imgsize[@]}; do
20
+        if ! [[ $size =~ ^(${filter})$ ]]; then
21
+            unset imgsize[$size]
22
+        else
23
+            geometry=(${imgsize[$size]})
24
+            width[$size]=${geometry[0]}
25
+            height[$size]=${geometry[1]}
26
+        fi
27
+    done
28
+fi
29
+
30
+for size in ${!imgsize[@]}; do
31
+    geometry=(${imgsize[$size]})
32
+    width[$size]=${geometry[0]}
33
+    height[$size]=${geometry[1]}
34
+done
19 35
 
20 36
 if which readconf > /dev/null; then
21 37
     eval $(readconf --conf "$thumbnailsconf" --section=mysql --section=path --case-sensitive)
... ...
@@ -48,11 +64,11 @@ for file in $(mysql -N -u $dbuser -p${dbpasswd} $dbname <<< $sqlcmd); do
48 64
     test $fnExt = 'mp4' && continue
49 65
     cmd="sudo -u www-data convert \"$site/$file\" -write mpr:image +delete "
50 66
     count=0
51
-    for ((i=0; i<${#imgsize[@]}; i+=3)); do
52
-        if ! test -e "${destDir}/${fnNoExt}-${imgsize[i]:0:2}.$fnExt"; then
53
-            format+="${imgsize[i]} "
67
+    for size in ${!imgsize[@]}; do
68
+        if ! test -e "${destDir}/${fnNoExt}-${size:0:2}.$fnExt"; then
69
+            format+="$size "
54 70
             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 "
71
+            cmd+="-resize ${width[$size]}x${height[$size]} -write \"${destDir}/${fnNoExt}-${size:0:2}.$fnExt\" +delete "
56 72
             let count++
57 73
         fi
58 74
     done
... ...
@@ -61,8 +77,8 @@ for file in $(mysql -N -u $dbuser -p${dbpasswd} $dbname <<< $sqlcmd); do
61 77
         echo -n "please wait... "
62 78
         cmd=$(sed -r 's/^(.+) -write (.*) \+delete $/\1 \2/' <<< $cmd)
63 79
         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"
80
+        for size in ${!imgsize[@]}; do
81
+            test -s "${destDir}/${fnNoExt}-${size:0:2}.$fnExt" || echo "missing extension ${size:0:2}.$fnExt"
66 82
         done
67 83
         echo "done, sleeping..."
68 84
         sleep $(( 2 + $count ))