83 lines
2.3 KiB
Bash
Executable File
83 lines
2.3 KiB
Bash
Executable File
#!/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
|