-
Notifications
You must be signed in to change notification settings - Fork 0
/
to-webp
executable file
·45 lines (40 loc) · 953 Bytes
/
to-webp
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
#!/bin/bash
LS='ls -lh'
if [ -f /usr/bin/lsd ]; then
LS='lsd --icon=never -lh'
fi
# Shitty arg parsing
RM='rm -i'
case $1 in
"--rm")
RM="rm"
shift
;;
"--norm")
RM="true"
shift
;;
esac
# Enable/disable multi-treading based on ENV
MT_ARG="-mt"
if [ "$MT" == "no" ]; then
echo "disabling multi-threading"
MT_ARG=""
fi
for FILE in "$@"; do
if [ "${FILE##*.}" == "gif" ]; then
ffmpeg -i "$FILE" -c:v libwebp -lossless 1 -loop 0 -compression_level 6 -quality 100 "${FILE%.*}.webp"
# cwebp -lossless -z 9 -mt "$FILE" -o "${FILE%.*}.webp"
else
cwebp -lossless -z 9 "${MT_ARG}" "$FILE" -o "${FILE%.*}.webp" 2>&1
fi
touch -r "$FILE" "${FILE%.*}.webp"
done
for FILE in "$@"; do
${LS} "$FILE" "${FILE%.*}.webp"
if webpinfo -quiet "${FILE%.*}.webp"; then
${RM} "$FILE"
else
echo "Invalid webp file! Not deleting"
fi
done