scripts / thumbnails /
Newer Older
111 lines | 3.167kb
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

            
diverses améliorations
Sébastien MARQUE authored on 2024-02-13
50
sqlcmd="select distinct path from ${dbprefix}images
ajoute 3 options: IMPORT, FO...
Sébastien MARQUE authored on 2022-11-19
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

            
diverses améliorations
Sébastien MARQUE authored on 2024-02-13
58
function get_ext_fn () {
59
    fnNoExt="${1%.*}"
60
    fnExt="${1##*.}"
61
    fnPath="${1%/*}"
62
}
63

            
64
function get_formats () {
65
    local IFS=$'\n'
66
    for file in $(mysql -N -u $dbuser -p${dbpasswd} $dbname <<< $sqlcmd); do
67
        get_ext_fn "$file"
68
        test $fnExt = 'mp4' && continue
69
        for size in ${!imgsize[@]}; do
70
            if ! test -e "${destDir}/${fnNoExt}-${size:0:2}.$fnExt" -a -z "$FORCE"; then
71
                formats[$file]+="$size "
72
                let total_ext++
73
            fi
74
        done
ajout du script utilisé pour...
Sébastien MARQUE authored on 2016-11-19
75
    done
diverses améliorations
Sébastien MARQUE authored on 2024-02-13
76
}
77

            
78
function calc_left () {
79
    local format=(${formats[$file]})
80
    unset formats[$file]
81
    total_ext=$(( $total_ext - ${#format[@]} ))
82
}
83

            
84
declare -A formats
85
get_formats
86

            
87
if test -n "$LIST"; then
88
    for file in ${!formats[@]}; do
89
        echo "[${#formats[@]}/$total_ext] $file : ${formats[$file]}"
90
        calc_left
91
    done
92
else
93
    for file in ${!formats[@]}; do
94
        unset cmd sleep_duration
95
        get_ext_fn "$file"
96
        for size in ${formats[$file]}; do
97
            cmd+=(mpr:image -resize ${width[$size]}x${height[$size]} -write "${destDir}/${fnNoExt}-${size:0:2}.$fnExt" +delete)
98
            let sleep_duration++
99
        done
100
        printf "\r\033[K[${#formats[@]}/$total_ext] $file : ${formats[$file]}"
101
        cmd[-1]="null:"
102
        sudo -u www-data nice -20 convert \
103
            -filter Lanczos -strip -auto-orient -quality 95 -interlace line -sampling-factor 4:2:2 \
104
            "$site/$file" +write ${cmd[@]}
modifie stockage des infos s...
Sébastien MARQUE authored on 2022-11-19
105
        for size in ${!imgsize[@]}; do
diverses améliorations
Sébastien MARQUE authored on 2024-02-13
106
            test -s "${destDir}/${fnNoExt}-${size:0:2}.$fnExt" || echo -e "\nmissing extension ${size:0:2}.$fnExt"
multiples améliorations
Sébastien MARQUE authored on 2019-02-17
107
        done
diverses améliorations
Sébastien MARQUE authored on 2024-02-13
108
        sleep $sleep_duration
109
        calc_left
110
    done
111
fi