-
Notifications
You must be signed in to change notification settings - Fork 22
/
create2xSprite.sh
executable file
·62 lines (51 loc) · 1.58 KB
/
create2xSprite.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
#!/bin/bash
# This tool is for migrating existing sprites to @2x versions. In order to use it
# simply measure the size of the non-transparent part of the original PNG image,
# and the same size on the gif that was created from it.
DEFAULT_EXTENT=32
SCRIPT_DIR=$(dirname "$0")
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
}
if ! command -v magick &>/dev/null; then
echo "This script requires ImageMagick (https://imagemagick.org/script/index.php)"
exit 1
fi
[ -z "$1" ] && usage && exit 2
[ -z "$2" ] && usage && exit 2
[ -z "$3" ] && usage && exit 2
spriteName=$1
originalHeight=$2 # the height of the non-transparent part of the original PNG image
newHeight=$3 # the height of the non-transparent part of the resulting GIF image
percentage=$(bc -l <<<"2*100*${newHeight}/${originalHeight}")
extent=${4:-${DEFAULT_EXTENT}}
extent2=$((2 * extent))
delay=${4:-${DEFAULT_DELAY}}
path=${5:-${DEFAULT_PATH}}
# create @2x gif
convert \
-interpolate Integer \
-filter point \
-delay "$delay" \
-dispose Background \
-resize "${percentage}%" \
-background none \
-gravity center \
-extent "${extent2}x${extent2}" \
"${path}/${spriteName}_*.png" \
"${path}/${spriteName}@2x.gif"
checkExitCode 'unable to create @2x sprite'
# create reversed @2x gif
convert \
-flop \
"${path}/${spriteName}@2x.gif" \
"${path}/${spriteName}[email protected]"
checkExitCode 'unable to create reversed @2x sprite'
exit 0