scripts / thumbnails /
Newer Older
76 lines | 2.547kb
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

            
ajout de tests
Sébastien MARQUE authored on 2017-02-12
20
if which readconf > /dev/null; then
plus besoin de galeries nomm...
Sébastien MARQUE authored on 2017-08-18
21
    eval $(readconf --conf "$thumbnailsconf" --section=mysql --section=path --case-sensitive)
ajout de tests
Sébastien MARQUE authored on 2017-02-12
22
else
23
    echo readconf needed !
24
    echo PATH = $PATH
modification de l'URL du dép...
Sébastien MARQUE authored on 2018-11-07
25
    echo get readconf at https://seb.lautre.net/git/seb/scripts/raw/master/readconf
ajout de tests
Sébastien MARQUE authored on 2017-02-12
26
    exit 1
27
fi
28

            
29
if ! which convert > /dev/null; then
30
    echo please install ImageMagick
31
    exit 1
32
fi
ajout du script utilisé pour...
Sébastien MARQUE authored on 2016-11-19
33

            
plus besoin de galeries nomm...
Sébastien MARQUE authored on 2017-08-18
34
sqlcmd="select path, rotation from ${dbprefix}images \
35
           where id in ( \
plusieurs albums pour une mê...
Sébastien MARQUE authored on 2017-08-30
36
              select distinct image_id from ${dbprefix}image_category \
plus besoin de galeries nomm...
Sébastien MARQUE authored on 2017-08-18
37
                  where category_id in ( \
38
                      select id from ${dbprefix}categories where dir is NULL \
39
                  ) \
40
           )"
ajout du script utilisé pour...
Sébastien MARQUE authored on 2016-11-19
41

            
plus besoin de galeries nomm...
Sébastien MARQUE authored on 2017-08-18
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"
44
    format=""
45
    fnNoExt="${file%.*}"
46
    fnExt="${file##*.}"
47
    fnPath="${file%/*}"
48
    mkdir -p $destDir/$fnPath
49
    cmd="convert $site/$file -write mpr:image +delete "
50
    for ((i=0; i<${#imgsize[@]}; i+=3)); do
51
        if ! test -e ${destDir}/${fnNoExt}-${imgsize[i]:0:2}.$fnExt; then
52
            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 "
ajout du script utilisé pour...
Sébastien MARQUE authored on 2016-11-19
56
            fi
plus besoin de galeries nomm...
Sébastien MARQUE authored on 2017-08-18
57
            cmd+="-resize ${imgsize[i+1]}x${imgsize[i+2]} -write ${destDir}/${fnNoExt}-${imgsize[i]:0:2}.$fnExt +delete "
ajout du script utilisé pour...
Sébastien MARQUE authored on 2016-11-19
58
        fi
59
    done
plus besoin de galeries nomm...
Sébastien MARQUE authored on 2017-08-18
60
    cmd=$(awk '{for (i=1; i<=NF - 3; i++) printf("%s ", $i); printf("%s", $(NF-1))}' <<< $cmd)
61
    if test -n "$format"; then
62
        echo "$site/$file : $format"
63
        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
75
    fi
ajout du script utilisé pour...
Sébastien MARQUE authored on 2016-11-19
76
done