Skip to content

Instantly share code, notes, and snippets.

@sormy
Created February 12, 2018 07:38
Show Gist options
  • Save sormy/38ef6163c071bd6a64fc61759ad6d942 to your computer and use it in GitHub Desktop.
Save sormy/38ef6163c071bd6a64fc61759ad6d942 to your computer and use it in GitHub Desktop.
Script to convert png to icns
#!/usr/bin/env bash
# Author: Artem Butusov <art.sormy@gmail.com>
# Version: 1.0
# Idea: https://stackoverflow.com/questions/12306223/how-to-manually-create-icns-files-using-iconutil
source="$1"
if [ -z "$source" ]; then
echo "Usage: png2icns <file.png>"
exit 0
fi
if [ ! -e "$source" ]; then
echo "Unable to find file: ${source}"
exit 1
fi
if [ "${source: -4}" != ".png" ]; then
echo "This script could accept only png files with .png extension"
exit 2
fi
iconset="$(basename "${source}" ".png").iconset"
mkdir "${iconset}"
sips -z 16 16 "${source}" --out "${iconset}/icon_16x16.png"
sips -z 32 32 "${source}" --out "${iconset}/icon_16x16@2x.png"
sips -z 32 32 "${source}" --out "${iconset}/icon_32x32.png"
sips -z 64 64 "${source}" --out "${iconset}/icon_32x32@2x.png"
sips -z 128 128 "${source}" --out "${iconset}/icon_128x128.png"
sips -z 256 256 "${source}" --out "${iconset}/icon_128x128@2x.png"
sips -z 256 256 "${source}" --out "${iconset}/icon_256x256.png"
sips -z 512 512 "${source}" --out "${iconset}/icon_256x256@2x.png"
sips -z 512 512 "${source}" --out "${iconset}/icon_512x512.png"
sips -z 1024 1024 "${source}" --out "${iconset}/icon_512x512@2x.png"
iconutil -c icns "$iconset"
rm -R "$iconset"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment