scripts / thumbnails /
Newer Older
61 lines | 2.202kb
ajout du script utilisé pour...
Sébastien MARQUE authored on 2016-11-19
1
#!/bin/bash
2

            
3
thumbnailsconf=${1:-${0##*/}.conf}
4
test -r "$thumbnailsconf" || exit 1
5

            
6
function set_imgsize () {
7
    imgsize[${#imgsize[@]}]=$1
8
    imgsize[${#imgsize[@]}]=$2
9
    imgsize[${#imgsize[@]}]=$3
10
}
11

            
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
19
set_imgsize '2small' 144 144
20
set_imgsize 'thumb' 120 120
21

            
22
eval $(readconf --conf "$thumbnailsconf" -s mysql -s galeries -s path --case-sensitive --array=galerie)
23

            
24
for ((g=0; g<${#galerie[@]}; g++)); do
25
    sqlcmd="select concat('file=', path, ';rotation=', rotation * 90) from piwigo_images \
26
               where id in ( \
27
                  select image_id from piwigo_image_category \
28
                      where category_id in ( \
29
                          select id from piwigo_categories where name = '${galerie[$g]}' \
30
                      ) \
31
               )"
32

            
33
    for image in $(mysql -N -u $dbuser -p${dbpasswd} $dbname <<< $sqlcmd); do
34
        eval "$image"
35
        format=""
36
        file=${file/$sourceDir}
37
        fnNoExt="${file%.*}"
38
        fnExt="${file##*.}"
39
        fnPath="${file%/*}"
40
        fnPath="${fnPath#$sourceDir}"
41
        fnNoExt="${fnNoExt#$sourceDir}"
42
        mkdir -p $destDir/$sourceDir/$fnPath
43
        cmd="nice -n20 convert $site/$file -write mpr:image +delete "
44
        for ((i=0; i<${#imgsize[@]}; i+=3)); do
45
            if ! test -e ${destDir}/${sourceDir}/${fnNoExt}-${imgsize[i]:0:2}.$fnExt; then
46
                format+="${imgsize[i]} "
47
                cmd+="mpr:image -filter Lanczos -strip -quality 95 -interlace line -sampling-factor 4:2:2 "
48
                if test $rotation -ne 0; then
49
                    cmd+="-rotate -$rotation -orient top-left "
50
                fi
51
                cmd+="-resize ${imgsize[i+1]}x${imgsize[i+2]} -write ${destDir}/${sourceDir}/${fnNoExt}-${imgsize[i]:0:2}.$fnExt +delete "
52
            fi
53
        done
54
        cmd=$(sed 's/\s*+delete\s*$//' <<< $cmd)
55
        if test -n "$format"; then
56
            echo "$site/$file : $format"
57
            eval "$(echo -e $cmd)"
58
            sleep 30
59
        fi
60
    done
61
done