Last active
August 29, 2015 14:27
-
-
Save mihaiserban/230655058e7e8735024b to your computer and use it in GitHub Desktop.
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
# Originally created by https://gist.github.com/brutella for ImageMagick | |
#! /bin/sh | |
function print_example() { | |
echo "Example" | |
echo " icons ios ~/AppIcon.png ~/Icons/" | |
} | |
function print_usage() { | |
echo "Usage" | |
echo " icons <ios|watch|all> in-file.png (out-dir)" | |
} | |
function command_exists() { | |
if type "$1" >/dev/null 2>&1; then | |
return 1 | |
else | |
return 0 | |
fi | |
} | |
if command_exists "sips" == 0 ; then | |
echo "sips tool not found" | |
exit 1 | |
fi | |
if [ "$1" = "--help" ] || [ "$1" = "-h" ] ; then | |
print_usage | |
exit 0 | |
fi | |
PLATFORM="$1" | |
FILE="$2" | |
if [ -z "$PLATFORM" ] || [ -z "$FILE" ] ; then | |
echo "Error: missing arguments" | |
echo "" | |
print_usage | |
echo "" | |
print_example | |
exit 1 | |
fi | |
DIR="$3" | |
if [ -z "$DIR" ] ; then | |
DIR=$(dirname $FILE) | |
fi | |
# Create directory if needed | |
mkdir -p "$DIR" | |
if [ "$PLATFORM" == "all" ] ; then | |
PLATFORM="ios watch" | |
fi | |
if [[ "$PLATFORM" == *"ios"* ]] ; then # iOS | |
sips -Z '120' "${FILE}" --out "${DIR}"/iPhone@2x.png | |
sips -Z '180' "${FILE}" --out "${DIR}"/iPhone@3x.png | |
sips -Z '29' "${FILE}" --out "${DIR}"/iPadSettings.png | |
sips -Z '58' "${FILE}" --out "${DIR}"/iPadSettings@2x.png | |
sips -Z '58' "${FILE}" --out "${DIR}"/iPhoneSettings@2x.png | |
sips -Z '87' "${FILE}" --out "${DIR}"/iPhoneSettings@3x.png | |
sips -Z '40' "${FILE}" --out "${DIR}"/iPadSpotlight.png | |
sips -Z '80' "${FILE}" --out "${DIR}"/iPadSpotlight@2x.png | |
sips -Z '80' "${FILE}" --out "${DIR}"/iPhoneSpotlight@2x.png | |
sips -Z '120' "${FILE}" --out "${DIR}"/iPhoneSpotlight@3x.png | |
sips -Z '76' "${FILE}" --out "${DIR}"/iPad.png | |
sips -Z '152' "${FILE}" --out "${DIR}"/iPad@2x.png | |
fi | |
if [[ "$PLATFORM" == *"watch"* ]] ; then # Apple Watch | |
sips -Z '48' "${FILE}" --out "${DIR}"/Watch38mmNotificationCenter.png | |
sips -Z '55' "${FILE}" --out "${DIR}"/Watch42mmNotificationCenter.png | |
sips -Z '58' "${FILE}" --out "${DIR}"/WatchCompanionSettings@2x.png | |
sips -Z '87' "${FILE}" --out "${DIR}"/WatchCompanionSettings@3x.png | |
sips -Z '80' "${FILE}" --out "${DIR}"/WatchAllHomeScreen.png | |
sips -Z '88' "${FILE}" --out "${DIR}"/WatchLongLook.png | |
sips -Z '172' "${FILE}" --out "${DIR}"/Watch38MMShortLook.png | |
sips -Z '196' "${FILE}" --out "${DIR}"/Watch42MMShortLook.png | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment