-
Notifications
You must be signed in to change notification settings - Fork 4
/
webp-thumbnailer
executable file
·54 lines (45 loc) · 1.39 KB
/
webp-thumbnailer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
set -euo pipefail
# See https://askubuntu.com/questions/617047/how-to-preview-dds-and-webp-images-on-nautilus
# Note: this is obsoleted by package webp-pixbuf-loader in Ubuntu >= 22.04
if [ $# -eq 0 ]; then
cat >&2 <<EOM
usage: $(basename "$0") --install
usage: $(basename "$0") INFILE MAX_DIMENSION OUTFILE
Note: this is obsoleted by package webp-pixbuf-loader
EOM
exit 1
fi
if [[ $1 == --install ]]; then
set -x
sudo cp -v "$0" /usr/local/bin/webp-thumbnailer
# mkdir -vp ~/.local/share/thumbnailers
#tee ~/.local/share/thumbnailers/webp.thumbnailer <<EOM
tee /usr/share/thumbnailers/webp.thumbnailer <<EOM
[Thumbnailer Entry]
Exec=/usr/local/bin/webp-thumbnailer %i %s %o
MimeType=image/webp;
EOM
set +x
echo "OK, installed"
exit
fi
run() {
echo >&2 "+ $*"
"$@"
}
strInFile="$1"
nMaxDimension="$2"
strOutFile="$3"
strInfo="$(run webpinfo "$strInFile")"
strSize="$(echo "$strInfo" | grep Canvas | sed -r 's"Canvas size (.*) x (.*)"\1\t\2"')"
nWidth="$(echo "$strSize" | cut -f1)"
nHeight="$(echo "$strSize" | cut -f2)"
if ((nWidth>nHeight)); then
nNewWidth=$nMaxDimension
nNewHeight=$(bc <<< "scale=10;f=$nHeight*($nNewWidth/$nWidth);scale=0;f/1")
else
nNewHeight=$nMaxDimension
nNewWidth=$(bc <<< "scale=10;f=$nWidth*($nNewHeight/$nHeight);scale=0;f/1")
fi
run dwebp "$strInFile" -scale "$nNewWidth" "$nNewHeight" -o "$strOutFile"