diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2021-02-24 23:35:34 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2021-02-24 23:35:34 +0300 |
commit | e71ddecd350a9c72be01b6730bc1369b03e4d46e (patch) | |
tree | d1e38084e963fa6219fa5b5f8b2b4be90a9b6488 |
-rw-r--r-- | README | 16 | ||||
-rwxr-xr-x | mkicns.sh | 82 |
2 files changed, 98 insertions, 0 deletions
@@ -0,0 +1,16 @@ +mkicns.sh is script that automates creating icns bundle from single PNG image. + +REQUIREMENTS + + - macOS + - convert utility from imagemagick + +USAGE + + mkicns.sh --source icon.png --output icon + + As a result of above command, icon.icns will be created. + +LICENSE + + BSD-2c diff --git a/mkicns.sh b/mkicns.sh new file mode 100755 index 0000000..98a0d02 --- /dev/null +++ b/mkicns.sh @@ -0,0 +1,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 |