forked from ed-asriyan/lottie-converter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtgs_to_png.sh
87 lines (77 loc) · 1.76 KB
/
tgs_to_png.sh
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# required bash variables
# $HEIGHT
# $WIDTH
# $FPS
# $OUTPUT_EXTENSION
# $QUALITY
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
function print_help() {
echo "usage: $(basename "$0") [--help] [--output OUTPUT] [--height HEIGHT] [--width WIDTH] [--fps FPS] path"
echo
echo "Animated sticker for Telegram (*.tgs) to animated $OUTPUT_EXTENSION converter"
echo
echo "Positional arguments:"
echo " path Path to .tgs file to convert"
echo
echo "Optional arguments:"
echo " -h, --help show this help message and exit"
echo " --output OUTPUT Output file path"
echo " --height HEIGHT Output image height. Default: $HEIGHT"
echo " --width WIDTH Output image width. Default: $WIDTH"
echo " --fps FPS Output frame rate. Default: $FPS"
echo " --quality FPS Output quality. Default: $QUALITY"
}
while [[ $# -gt 0 ]]; do
case $1 in
-h|--height)
HEIGHT="$2"
shift
shift
;;
-w|--width)
WIDTH="$2"
shift
shift
;;
-f|--fps)
FPS="$2"
shift
shift
;;
-q|--quality)
QUALITY="$2"
shift
shift
;;
-o|--output)
OUTPUT="$2"
shift
shift
;;
--help)
print_help
exit 1
;;
*)
POSITIONAL_ARG=$1
shift
;;
esac
done
if [[ -z "$POSITIONAL_ARG" ]]; then
print_help
exit 1
fi
TGS_PATH=$POSITIONAL_ARG
if [[ -z "$OUTPUT" ]]; then
OUTPUT=${TGS_PATH}${OUTPUT_EXTENSION}
fi
PNG_PATH=${OUTPUT}.tmp
mkdir $PNG_PATH
$SCRIPT_DIR/bin/tgs_to_png --width $WIDTH --height $HEIGHT --fps $FPS --output $PNG_PATH $TGS_PATH
PNG_FILES=$(find $PNG_PATH -type f -name '*.png' | sort -k1)
function cleanup {
rm -fr $PNG_PATH
}
trap cleanup EXIT
trap cleanup SIGINT