Skip to content

Instantly share code, notes, and snippets.

@antranapp
Forked from brutella/icons
Last active August 29, 2015 14:18
Show Gist options
  • Save antranapp/46ca69d255b54e1e72bc to your computer and use it in GitHub Desktop.
Save antranapp/46ca69d255b54e1e72bc to your computer and use it in GitHub Desktop.
#! /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 "convert" == 0 ; then
echo "ImageMagick tool 'convert' 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
convert -resize '120x120' "${FILE}" "${DIR}"/iPhone@2x.png
convert -resize '180x180' "${FILE}" "${DIR}"/iPhone@3x.png
convert -resize '29x29' "${FILE}" "${DIR}"/iPadSettings.png
convert -resize '58x58' "${FILE}" "${DIR}"/iPadSettings@2x.png
convert -resize '58x58' "${FILE}" "${DIR}"/iPhoneSettings@2x.png
convert -resize '87x87' "${FILE}" "${DIR}"/iPhoneSettings@3x.png
convert -resize '40x40' "${FILE}" "${DIR}"/iPadSpotlight.png
convert -resize '80x80' "${FILE}" "${DIR}"/iPadSpotlight@2x.png
convert -resize '80x80' "${FILE}" "${DIR}"/iPhoneSpotlight@2x.png
convert -resize '120x120' "${FILE}" "${DIR}"/iPhoneSpotlight@3x.png
convert -resize '76x76' "${FILE}" "${DIR}"/iPad.png
convert -resize '152x152' "${FILE}" "${DIR}"/iPad@2x.png
fi
if [[ "$PLATFORM" == *"watch"* ]] ; then # Apple Watch
convert -resize '48x48' "${FILE}" "${DIR}"/Watch38mmNotificationCenter.png
convert -resize '55x55' "${FILE}" "${DIR}"/Watch42mmNotificationCenter.png
convert -resize '58x58' "${FILE}" "${DIR}"/WatchCompanionSettings@2x.png
convert -resize '87x87' "${FILE}" "${DIR}"/WatchCompanionSettings@3x.png
convert -resize '80x80' "${FILE}" "${DIR}"/WatchAllHomeScreen.png
convert -resize '88x88' "${FILE}" "${DIR}"/WatchLongLook.png
convert -resize '172x172' "${FILE}" "${DIR}"/Watch38MMShortLook.png
convert -resize '196x196' "${FILE}" "${DIR}"/Watch42MMShortLook.png
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment