scripts / thumbnails /
Newer Older
70 lines | 2.299kb
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

            
multiples améliorations
Sébastien MARQUE authored on 2019-02-17
34
sqlcmd="select path from ${dbprefix}images \
plus besoin de galeries nomm...
Sébastien MARQUE authored on 2017-08-18
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

            
multiples améliorations
Sébastien MARQUE authored on 2019-02-17
42
IFS=$'\n'
43
for file in $(mysql -N -u $dbuser -p${dbpasswd} $dbname <<< $sqlcmd); do
plus besoin de galeries nomm...
Sébastien MARQUE authored on 2017-08-18
44
    format=""
45
    fnNoExt="${file%.*}"
46
    fnExt="${file##*.}"
47
    fnPath="${file%/*}"
multiples améliorations
Sébastien MARQUE authored on 2019-02-17
48
    test $fnExt = 'mp4' && continue
49
    cmd="sudo -u www-data convert \"$site/$file\" -write mpr:image +delete "
50
    count=0
plus besoin de galeries nomm...
Sébastien MARQUE authored on 2017-08-18
51
    for ((i=0; i<${#imgsize[@]}; i+=3)); do
multiples améliorations
Sébastien MARQUE authored on 2019-02-17
52
        if ! test -e "${destDir}/${fnNoExt}-${imgsize[i]:0:2}.$fnExt"; then
plus besoin de galeries nomm...
Sébastien MARQUE authored on 2017-08-18
53
            format+="${imgsize[i]} "
multiples améliorations
Sébastien MARQUE authored on 2019-02-17
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++
ajout du script utilisé pour...
Sébastien MARQUE authored on 2016-11-19
57
        fi
58
    done
plus besoin de galeries nomm...
Sébastien MARQUE authored on 2017-08-18
59
    if test -n "$format"; then
60
        echo "$site/$file : $format"
61
        echo -n "please wait... "
multiples améliorations
Sébastien MARQUE authored on 2019-02-17
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 ))
plus besoin de galeries nomm...
Sébastien MARQUE authored on 2017-08-18
69
    fi
ajout du script utilisé pour...
Sébastien MARQUE authored on 2016-11-19
70
done