Skip to content

Instantly share code, notes, and snippets.

@steverichey
Created August 25, 2015 02:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steverichey/f78ccea9024b1fe5c815 to your computer and use it in GitHub Desktop.
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.
#!/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/icon_16x16@2x.png
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/icon_32x32@2x.png
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/icon_128x128@2x.png
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/icon_256x256@2x.png
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/icon_512x512@2x.png
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