scripts / thumbnails /
Newer Older
89 lines | 2.717kb
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
modifie stockage des infos s...
Sébastien MARQUE authored on 2022-11-19
5
shift
ajout du script utilisé pour...
Sébastien MARQUE authored on 2016-11-19
6

            
modifie stockage des infos s...
Sébastien MARQUE authored on 2022-11-19
7
declare -A imgsize width height
ajout du script utilisé pour...
Sébastien MARQUE authored on 2016-11-19
8

            
modifie stockage des infos s...
Sébastien MARQUE authored on 2022-11-19
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
ajout du script utilisé pour...
Sébastien MARQUE authored on 2016-11-19
35

            
ajout de tests
Sébastien MARQUE authored on 2017-02-12
36
if which readconf > /dev/null; then
plus besoin de galeries nomm...
Sébastien MARQUE authored on 2017-08-18
37
    eval $(readconf --conf "$thumbnailsconf" --section=mysql --section=path --case-sensitive)
ajout de tests
Sébastien MARQUE authored on 2017-02-12
38
else
39
    echo readconf needed !
40
    echo PATH = $PATH
modification de l'URL du dép...
Sébastien MARQUE authored on 2018-11-07
41
    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
42
    exit 1
43
fi
44

            
45
if ! which convert > /dev/null; then
46
    echo please install ImageMagick
47
    exit 1
48
fi
ajout du script utilisé pour...
Sébastien MARQUE authored on 2016-11-19
49

            
ajoute 3 options: IMPORT, FO...
Sébastien MARQUE authored on 2022-11-19
50
sqlcmd="select path from ${dbprefix}images
51
           where id in (
52
              select distinct image_id from ${dbprefix}image_category
53
                  where category_id in (
54
                      select id from ${dbprefix}categories where dir is ${IMPORT:+not} NULL
55
                  )
plus besoin de galeries nomm...
Sébastien MARQUE authored on 2017-08-18
56
           )"
ajout du script utilisé pour...
Sébastien MARQUE authored on 2016-11-19
57

            
multiples améliorations
Sébastien MARQUE authored on 2019-02-17
58
IFS=$'\n'
59
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
60
    format=""
61
    fnNoExt="${file%.*}"
62
    fnExt="${file##*.}"
63
    fnPath="${file%/*}"
multiples améliorations
Sébastien MARQUE authored on 2019-02-17
64
    test $fnExt = 'mp4' && continue
65
    cmd="sudo -u www-data convert \"$site/$file\" -write mpr:image +delete "
66
    count=0
modifie stockage des infos s...
Sébastien MARQUE authored on 2022-11-19
67
    for size in ${!imgsize[@]}; do
ajoute 3 options: IMPORT, FO...
Sébastien MARQUE authored on 2022-11-19
68
        if ! test -e "${destDir}/${fnNoExt}-${size:0:2}.$fnExt" -a -z "$FORCE"; then
modifie stockage des infos s...
Sébastien MARQUE authored on 2022-11-19
69
            format+="$size "
multiples améliorations
Sébastien MARQUE authored on 2019-02-17
70
            cmd+="mpr:image -filter Lanczos -auto-orient -strip -quality 95 -interlace line -sampling-factor 4:2:2 "
modifie stockage des infos s...
Sébastien MARQUE authored on 2022-11-19
71
            cmd+="-resize ${width[$size]}x${height[$size]} -write \"${destDir}/${fnNoExt}-${size:0:2}.$fnExt\" +delete "
multiples améliorations
Sébastien MARQUE authored on 2019-02-17
72
            let count++
ajout du script utilisé pour...
Sébastien MARQUE authored on 2016-11-19
73
        fi
74
    done
plus besoin de galeries nomm...
Sébastien MARQUE authored on 2017-08-18
75
    if test -n "$format"; then
76
        echo "$site/$file : $format"
ajoute 3 options: IMPORT, FO...
Sébastien MARQUE authored on 2022-11-19
77
        if test -n "$LIST"; then
78
            continue
79
        fi
plus besoin de galeries nomm...
Sébastien MARQUE authored on 2017-08-18
80
        echo -n "please wait... "
multiples améliorations
Sébastien MARQUE authored on 2019-02-17
81
        cmd=$(sed -r 's/^(.+) -write (.*) \+delete $/\1 \2/' <<< $cmd)
82
        eval $(echo -e nice -20 $cmd)
modifie stockage des infos s...
Sébastien MARQUE authored on 2022-11-19
83
        for size in ${!imgsize[@]}; do
84
            test -s "${destDir}/${fnNoExt}-${size:0:2}.$fnExt" || echo "missing extension ${size:0:2}.$fnExt"
multiples améliorations
Sébastien MARQUE authored on 2019-02-17
85
        done
86
        echo "done, sleeping..."
87
        sleep $(( 2 + $count ))
plus besoin de galeries nomm...
Sébastien MARQUE authored on 2017-08-18
88
    fi
ajout du script utilisé pour...
Sébastien MARQUE authored on 2016-11-19
89
done