aboutsummaryrefslogtreecommitdiff
path: root/images/genTile.sh
blob: 66c89c05ed8cb393c6049356cf97c02d268ec198 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/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
}

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" || exit 2


#!/bin/sh

# template.sh: A template for sh scripts
#
# Usage: template.sh [-ac] [-b OPTARG] FILE...

usageMessage="Usage: ${0} [-ac] [-b OPTARG] FILE..."

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

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