Last active
April 17, 2017 15:26
-
-
Save rnkn/d29fcfbf1c46f9c1465468b8965175b6 to your computer and use it in GitHub Desktop.
Script to convert PNG to Retina icon
This file contains hidden or 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
#! /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}/[email protected]" > /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}/[email protected]" > /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}/[email protected]" > /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}/[email protected]" > /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}/[email protected]" > /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