Created
August 25, 2015 02:46
-
-
Save steverichey/f78ccea9024b1fe5c815 to your computer and use it in GitHub Desktop.
A shell script to convert a single image of arbitrary size to an ICNS file in OS X.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# exit on error | |
set -e | |
if [ "$#" -ne 1 ]; then | |
echo "Usage: icns myicon.png" | |
exit 0 | |
fi | |
if [ ! -f "$1" ]; then | |
echo "File not found: $1" | |
exit 0 | |
fi | |
filename=$(basename "$1") | |
filename="${filename%.*}" | |
if [ -d "$filename.iconset" ]; then | |
rm -r $filename.iconset | |
fi | |
mkdir $filename.iconset | |
echo "Creating $filename.icns..." | |
convert $1 -resize 16x16 -background transparent -gravity center -extent 16x16 $filename.iconset/icon_16x16.png | |
convert $1 -resize 32x32 -background transparent -gravity center -extent 32x32 $filename.iconset/[email protected] | |
convert $1 -resize 32x32 -background transparent -gravity center -extent 32x32 $filename.iconset/icon_32x32.png | |
convert $1 -resize 64x64 -background transparent -gravity center -extent 64x64 $filename.iconset/[email protected] | |
convert $1 -resize 128x128 -background transparent -gravity center -extent 128x128 $filename.iconset/icon_128x128.png | |
convert $1 -resize 256x256 -background transparent -gravity center -extent 256x256 $filename.iconset/[email protected] | |
convert $1 -resize 256x256 -background transparent -gravity center -extent 256x256 $filename.iconset/icon_256x256.png | |
convert $1 -resize 512x512 -background transparent -gravity center -extent 512x512 $filename.iconset/[email protected] | |
convert $1 -resize 512x512 -background transparent -gravity center -extent 512x512 $filename.iconset/icon_512x512.png | |
convert $1 -resize 1024x1024 -background transparent -gravity center -extent 1024x1024 $filename.iconset/[email protected] | |
iconutil -c icns $filename.iconset | |
rm -R $filename.iconset | |
echo "Done!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment