Last active
July 28, 2021 20:49
-
-
Save gmoraleda/af51e85ff5cac49b92d68c7705feac1d to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# | |
# Helpers | |
# | |
function installImageMagick() { | |
brew install imagemagick ghostscript | |
} | |
# | |
# Preflight: Check if tools are installed | |
# | |
if hash identify 2>/dev/null && hash convert 2>/dev/null; then | |
echo "---------------------------------- " | |
echo "ImageMagick already installed ✅ " | |
echo "---------------------------------- " | |
else | |
echo "------------------------------- " | |
echo "ImageMagick is not installed💥 " | |
echo "------------------------------- " | |
installImageMagick | |
fi | |
# | |
# Access AppIcon | |
# | |
IFS=$'\n' | |
BASE_ICONS_DIR=$(find ${SRCROOT}/${PRODUCT_NAME} -name "AppIcon.appiconset") | |
IFS=$' ' | |
CONTENTS_JSON="${BASE_ICONS_DIR}/Contents.json" | |
# | |
# Read Read configuration, version and build number | |
# | |
production_configurations=("BetaProduction", "AlphaProduction", "DebugProduction", "ReleaseProduction") | |
staging_configurations=("BetaStaging", "AlphaStaging", "DebugStaging", "ReleaseStaging") | |
version=`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${INFOPLIST_FILE}"` #iOS < 13 | |
version="${MARKETING_VERSION}" #iOS 13 | |
buildNumber=`/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${INFOPLIST_FILE}"` | |
caption="${CONFIGURATION}\n${version}\n($buildNumber)" | |
echo $caption | |
# | |
# Generate icons | |
# | |
function generateIcons() { | |
ICON_PATH=$1 | |
if [ "${CONFIGURATION}" != "ReleaseProduction" ]; then | |
width=`identify -format %w ${ICON_PATH}` | |
height=`identify -format %h ${ICON_PATH}` | |
band_height=$((($height * 50) / 100)) | |
band_position=$(($height - $band_height)) | |
text_position=$(($band_position - 1)) | |
point_size=$(((14 * $width) / 100)) | |
# | |
# Band color | |
# | |
band_color='rgba(0,0,0,0.8)' | |
if [[ " ${production_configurations[@]} " =~ "${CONFIGURATION}" ]]; then | |
band_color='rgba(224,40,40,0.8)' | |
fi | |
# | |
# Blur band and text | |
# | |
convert ${ICON_PATH} -blur 10x8 /tmp/blurred.png | |
convert /tmp/blurred.png -gamma 0 -fill white -draw "rectangle 0,$band_position,$width,$height" /tmp/mask.png | |
convert -size ${width}x${band_height} xc:none -fill $band_color -draw "rectangle 0,0,$width,$band_height" /tmp/labels-base.png | |
convert -background none -size ${width}x${band_height} -pointsize $point_size -fill white -gravity center -gravity South -font ArialNarrowB caption:"$caption" /tmp/labels.png | |
convert ${ICON_PATH} /tmp/blurred.png /tmp/mask.png -composite /tmp/temp.png | |
rm /tmp/blurred.png | |
rm /tmp/mask.png | |
# | |
# Compose final image | |
# | |
convert /tmp/temp.png /tmp/labels-base.png -geometry +0+$band_position -composite /tmp/labels.png -geometry +0+$text_position -geometry +${w}-${h} -composite "${ICON_PATH}" | |
# | |
# Clean up | |
# | |
rm /tmp/temp.png | |
rm /tmp/labels-base.png | |
rm /tmp/labels.png | |
fi | |
} | |
ICONS=(`grep 'filename' "${CONTENTS_JSON}" | cut -f2 -d: | tr -d ',' | tr -d '\n' | tr -d '"'`) | |
ICONS_COUNT=${#ICONS[*]} | |
IFS=$'\n' | |
for (( i=0; i<ICONS_COUNT; i++ )); do | |
generateIcons "$BASE_ICONS_DIR/${ICONS[$i]}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment