-
Notifications
You must be signed in to change notification settings - Fork 22
/
editSprite.sh
executable file
·111 lines (91 loc) · 2.74 KB
/
editSprite.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/bash
SCRIPT_DIR=$(dirname "$0")
DEFAULT_RESIZE=32
DEFAULT_EXTENT=32
DEFAULT_DELAY='50'
DEFAULT_PATH=${SCRIPT_DIR}'/src/main/resources/com/kagof/intellij/plugins/pokeprogress/sprites'
checkExitCode() {
exitCode="$?"
if [ "$exitCode" -ne "0" ]; then
echo
echo $1
exit "$exitCode"
fi
}
usage() {
echo "
Utility for creating animated sprites from still PNGs.
usage:
editSprite.sh --help
Show this message
editSprite.sh spriteName [resize] [extent] [delay] [path]
- spriteName: the name of the sprite. There should be matching spriteName_1.png, spriteName_2.png, ... files in the path.
NOTE: existing files named spriteName.gif, spriteName_r.gif [email protected], [email protected] in the path will be overwritten
- resize: shrink/expand each image before conversion.
DEFAULT: ${DEFAULT_RESIZE}
- extent: expand the resulting gif post conversion, by padding the border with transparency.
DEFAULT: ${DEFAULT_EXTENT}
- delay: timing between frames, in ms.
DEFAULT: ${DEFAULT_DELAY}
- path: path of the sprites to create & use.
DEFAULT: ${DEFAULT_PATH}
"
}
if ! command -v magick &>/dev/null; then
echo "This script requires ImageMagick (https://imagemagick.org/script/index.php)"
exit 1
elif [ "$1" = '--help' ]; then
usage
exit 0
fi
[ -z "$1" ] && usage && exit 2
spriteName=$1
resize=${2:-${DEFAULT_RESIZE}}
resize2=$(( 2 * resize ))
extent=${3:-${DEFAULT_EXTENT}}
extent2=$(( 2 * extent ))
delay=${4:-${DEFAULT_DELAY}}
path=${5:-${DEFAULT_PATH}}
# create initial gif
magick convert \
-interpolate Integer \
-filter point \
-delay "$delay" \
-dispose Background \
-resize "${resize}x${resize}" \
-background none \
-gravity center \
-extent "${extent}x${extent}" \
"${path}/${spriteName}_*.png" \
"${path}/${spriteName}.gif"
checkExitCode 'unable to convert sprite (run editSprite.sh --help for usage)'
# create @2x gif
magick convert \
-interpolate Integer \
-filter point \
-delay "$delay" \
-dispose Background \
-resize "${resize2}x${resize2}" \
-background none \
-gravity center \
-extent "${extent2}x${extent2}" \
"${path}/${spriteName}_*.png" \
"${path}/${spriteName}@2x.gif"
checkExitCode 'unable to convert @2x sprite (run editSprite.sh --help for usage)'
# create reversed gif
magick convert \
-interpolate Integer \
-filter point \
-flop \
"${path}/${spriteName}.gif" \
"${path}/${spriteName}_r.gif"
checkExitCode 'unable to create reversed sprite (run editSprite.sh --help for usage)'
# create reversed @2x gif
magick convert \
-interpolate Integer \
-filter point \
-flop \
"${path}/${spriteName}@2x.gif" \
"${path}/${spriteName}[email protected]"
checkExitCode 'unable to create reversed @2x sprite (run editSprite.sh --help for usage)'
exit 0