Created
December 11, 2017 16:55
-
-
Save warrenburton/e9d1952d888377ac3780ef6b4af1fef1 to your computer and use it in GitHub Desktop.
generate ICNS file from master PNG image
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/bash | |
#Usage: | |
#generate_icns.sh /path/to/mastericon.png | |
if [ $# -ne 1 ]; then | |
echo "error: $# arguments expected 1" | |
echo "usage: generate_icns.sh /path/to/mastericon.png" | |
exit 1 | |
fi | |
icon=$1 | |
width=`sips -g pixelHeight $icon | tr -dc '0-9'` | |
height=`sips -g pixelWidth $icon | tr -dc '0-9'` | |
echo $icon is $width x $height pixels | |
if [ $width -lt 1024 ]; then | |
echo error: expected master image pixel dim of at least 1024x1024 | |
exit 1 | |
fi | |
if [ $width -ne $height ]; then | |
echo error: expected square aspect ratio | |
exit 1 | |
fi | |
i=0 | |
sizes=(16 32 128 256 512) | |
iconset=generated.iconset | |
icnfile=generated.icns | |
echo working into $icnfile | |
if [ -d $iconset ]; then | |
rm -rf $iconset | |
fi | |
if [ -e $icnfile ]; then | |
rm -rf $icnfile | |
fi | |
mkdir -p $iconset | |
base=iconbase.png | |
cp $1 $iconset/$base | |
echo working on $1 | |
while [ $i -lt ${#sizes[@]} ]; do | |
nextsize=${sizes[$i]} | |
nextsize2x=$((2*nextsize)) | |
nextname=icon_$nextsize'x'$nextsize.png | |
nextname2x=icon_$nextsize'x'$nextsize@2x.png | |
echo generating files $nextname and $nextname2x | |
cp $iconset/$base $iconset/$nextname | |
`sips -Z $nextsize $iconset/$nextname &>/dev/null` | |
cp $iconset/$base $iconset/$nextname2x | |
`sips -Z $nextsize2x $iconset/$nextname2x &>/dev/null` | |
: $[ i++ ] | |
done | |
rm $iconset/$base | |
`iconutil -c icns -o $icnfile $iconset` | |
if [ $? -ne 0 ]; then | |
echo "$icnfile not created" | |
exit 1 | |
fi | |
echo "$icnfile created successfully" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment