Skip to content

Instantly share code, notes, and snippets.

@rnkn
Last active April 17, 2017 15:26
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 rnkn/d29fcfbf1c46f9c1465468b8965175b6 to your computer and use it in GitHub Desktop.
Save rnkn/d29fcfbf1c46f9c1465468b8965175b6 to your computer and use it in GitHub Desktop.
Script to convert PNG to Retina icon
#! /usr/bin/env bash
if [[ $(file "$1") =~ "PNG image data, 1024 x 1024" ]]
then echo -e "Input file:\t$1"
else echo "Error: Input file must be a PNG image, 1024 x 1024 pixels"
exit 1
fi
png=$(basename "$1")
iconset="${png%.*}.iconset"
mkdir "$iconset"
iconutil=$(which iconutil)
sips=$(which sips)
echo "Processing..."
$sips --resampleHeightWidth 16 16 "$1" --out "${iconset}/icon_16x16.png" > /dev/null 2>&1
$sips --resampleHeightWidth 32 32 "$1" --out "${iconset}/icon_16x16@2x.png" > /dev/null 2>&1
$sips --resampleHeightWidth 32 32 "$1" --out "${iconset}/icon_32x32.png" > /dev/null 2>&1
$sips --resampleHeightWidth 64 64 "$1" --out "${iconset}/icon_32x32@2x.png" > /dev/null 2>&1
$sips --resampleHeightWidth 128 128 "$1" --out "${iconset}/icon_128x128.png" > /dev/null 2>&1
$sips --resampleHeightWidth 256 256 "$1" --out "${iconset}/icon_128x128@2x.png" > /dev/null 2>&1
$sips --resampleHeightWidth 256 256 "$1" --out "${iconset}/icon_256x256.png" > /dev/null 2>&1
$sips --resampleHeightWidth 512 512 "$1" --out "${iconset}/icon_256x256@2x.png" > /dev/null 2>&1
$sips --resampleHeightWidth 512 512 "$1" --out "${iconset}/icon_512x512.png" > /dev/null 2>&1
$sips --resampleHeightWidth 1024 1024 "$1" --out "${iconset}/icon_512x512@2x.png" > /dev/null 2>&1
$iconutil --convert icns --output "${iconset%.*}.icns" "$iconset"
echo -e "Output file:\t${iconset%.*}.icns"
rm -R "$iconset"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment