Skip to content

Instantly share code, notes, and snippets.

@tommeier
Last active February 26, 2016 10:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommeier/f7f622b1c0a64c7550f0 to your computer and use it in GitHub Desktop.
Save tommeier/f7f622b1c0a64c7550f0 to your computer and use it in GitHub Desktop.
IFS=$'\n'
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${PROJECT_DIR}/${INFOPLIST_FILE}")
versionNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${PROJECT_DIR}/${INFOPLIST_FILE}")
PATH=${PATH}:/usr/local/bin
function checkFileExists () {
if [[ ! -e "$1" ]]; then
echo "Required file unable to be found: $1"
exit 1
fi
}
function generateIcon () {
BASE_IMAGE_NAME=$1
IDENTIFY_BIN=$(which identify)
if [[ "$IDENTIFY_BIN" == '' ]]; then
echo "No 'identify' command found. Please ensure image magick is installed correctly"
else
BUILD_RESOURCES_DIR="${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
TARGET_PATH="${BUILD_RESOURCES_DIR}/${BASE_IMAGE_NAME}"
BASE_IMAGE_PATH=$(find ${BUILD_RESOURCES_DIR} -name ${BASE_IMAGE_NAME})
checkFileExists "betaRibbon.png"
checkFileExists "debugRibbon.png"
checkFileExists "$BASE_IMAGE_PATH"
WIDTH=$(identify -format %w $BASE_IMAGE_PATH)
echo "Image width: $WIDTH"
FONT_SIZE=$(echo "$WIDTH * .15" | bc -l)
echo "Font size: $FONT_SIZE"
BADGE_TEXT="$buildNumber"
echo "Creating badged icon for: '$BASE_IMAGE_NAME' with '$BADGE_TEXT'"
if [ "${CONFIGURATION}" == "Debug" ]; then
convert debugRibbon.png -resize ${WIDTH}x${WIDTH} resizedRibbon.png
convert ${BASE_IMAGE_PATH} -fill black -font Times-Bold -pointsize ${FONT_SIZE} -gravity south -annotate 0 "$BADGE_TEXT" - | composite resizedRibbon.png - ${TARGET_PATH}
fi
if [ "${CONFIGURATION}" == "Beta" ]; then
convert betaRibbon.png -resize ${WIDTH}x${WIDTH} resizedRibbon.png
convert ${BASE_IMAGE_PATH} -fill black -font Times-Boldr -pointsize ${FONT_SIZE} -gravity south -annotate 0 "$BADGE_TEXT" - | composite resizedRibbon.png - ${TARGET_PATH}
fi
fi
}
generateIcon "AppIcon60x60@2x.png"
generateIcon "AppIcon60x60@3x.png"
generateIcon "AppIcon76x76~ipad.png"
generateIcon "AppIcon76x76@2x~ipad.png"
@tommeier
Copy link
Author

Actually this won't work as the generated image will keep adding values... need another way to maintain the raw image

@tommeier
Copy link
Author

Pretty much damned if you do, damned if you don't. Maybe caching a .original on first build attempt, but it would mean clearing build folder any time the image/script/variables are changed. Or knowing a way to translate the raw Images.xcassets image path to translate resulting image name into raw image name...

@milanpanchal
Copy link

I was trying to add Version number on Splash screen, but not able to success. Can you help me out on that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment