aboutsummaryrefslogtreecommitdiff
path: root/images/genTile.sh
blob: c1d7089750b5880cdac4520e148111b7fd5c6a2e (plain)
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
#!/bin/sh

# genTile.sh: Create a framed tile in the specified color
#
# Usage: genTile.sh [-s SIZE] COLOR

usageMessage="Usage: ${0} [-s SIZE] COLOR"

error() {
	printf '%s error: %s\n' "$0" "$*" >&2
}

errorAndUsage() {
	printf '%s error: %s\n%s\n' "$0" "$*" "$usageMessage" >&2
}

clean() {
	[ -f "$tmpFile" ] && rm "$tmpFile"
}

size=64
borderSize=2

# Process options
while getopts ':s:' opt; do
	case $opt in

		's' )
			size="$OPTARG"
			;;

		'?' )
			printf '%s\n' "$usageMessage" >&2
			exit 1

	esac
done
shift $((OPTIND - 1))

borderlessSize=$(( size - (borderSize * 2) ))
color="$1"
tmpFile="/tmp/${color}Temp.png"
outputFile="${color}.png"

[ -z "$color" ] && errorAndUsage "No color specified." && exit 1

magick -size "${borderlessSize}x${borderlessSize}" "canvas:${color}" "$tmpFile" || exit 2
convert "$tmpFile" -bordercolor black -border "${borderSize}x${borderSize}" "$outputFile" || clean && exit 2