aboutsummaryrefslogtreecommitdiff
path: root/mkicns.sh
blob: 98a0d02a651708824032e22e1b8066c78d3fb50a (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/sh

set -e

PROGPATH="$0"

usage() {
	cat <<-_EOT
	Usage: $PROGPATH <OPTIONS>

	Options:
	    --source  PNG source (should be 1024x1024)
	    --output  iconset name, will be created in current directory
	_EOT
	exit
}

error() {
    echo "error: $@" >&2
    exit 1
}

SOURCE=
OUTPUT=

while :; do
	case $1 in
		--source)
			if [ -n "$2" ]; then
				SOURCE="$2"
				shift
			else
				error "$q requires an argument"
			fi
			;;

		--output)
			if [ -n "$2" ]; then
				OUTPUT="$2"
				shift
			else
				error "$q requires an argument"
			fi
			;;

		--)
			shift
			break
			;;

		-?*)
			error "unknown option: %s" "$1"
            ;;

        *)
            break
	esac
	shift
done

[ -z "$SOURCE" ] && usage
[ -z "$OUTPUT" ] && usage
[ ! -f "$SOURCE" ] && error "source file '$SOURCE' does not exists"

mkdir $OUTPUT.iconset || error "failed to create temporary iconset directory"

convert -background none -resize 16x16     -gravity center -extent 16x16     $SOURCE $OUTPUT.iconset/icon_16x16.png
convert -background none -resize 32x32     -gravity center -extent 32x32     $SOURCE $OUTPUT.iconset/icon_16x16@2x.png
convert -background none -resize 32x32     -gravity center -extent 32x32     $SOURCE $OUTPUT.iconset/icon_32x32.png
convert -background none -resize 64x64     -gravity center -extent 64x64     $SOURCE $OUTPUT.iconset/icon_32x32@2x.png
convert -background none -resize 64x64     -gravity center -extent 64x64     $SOURCE $OUTPUT.iconset/icon_64x64.png
convert -background none -resize 128x128   -gravity center -extent 128x128   $SOURCE $OUTPUT.iconset/icon_64x64@2x.png
convert -background none -resize 128x128   -gravity center -extent 128x128   $SOURCE $OUTPUT.iconset/icon_128x128.png
convert -background none -resize 256x256   -gravity center -extent 256x256   $SOURCE $OUTPUT.iconset/icon_128x128@2x.png
convert -background none -resize 256x256   -gravity center -extent 256x256   $SOURCE $OUTPUT.iconset/icon_256x256.png
convert -background none -resize 512x512   -gravity center -extent 512x512   $SOURCE $OUTPUT.iconset/icon_256x256@2x.png
convert -background none -resize 512x512   -gravity center -extent 512x512   $SOURCE $OUTPUT.iconset/icon_512x512.png
convert -background none -resize 1024x1024 -gravity center -extent 1024x1024 $SOURCE $OUTPUT.iconset/icon_512x512@2x.png

iconutil --convert icns $OUTPUT.iconset

rm -R $OUTPUT.iconset