Skip to content

Instantly share code, notes, and snippets.

@alldne
Created March 30, 2021 09:32
Show Gist options
  • Save alldne/b7bb30ccf38454bbf753f4e3abc1171a to your computer and use it in GitHub Desktop.
Save alldne/b7bb30ccf38454bbf753f4e3abc1171a to your computer and use it in GitHub Desktop.
resize-icon.bash
#!/bin/bash
# https://stackoverflow.com/a/51343786
# https://developer.apple.com/library/archive/qa/qa1686/_index.html
RED='\033[0;31m' # Red
GREEN='\033[0;32m' # Green
RESET='\033[0m' # Text Reset
function __system {
echo -e $GREEN$*$RESET
}
function __error {
echo -e $RED$*$RESET
}
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
PROJECT_DIR=$SCRIPT_DIR/..
OUTDIR="resized"
mkdir -p $OUTDIR
ICON=$1
if [[ -z $ICON ]]; then
echo "Usage:"
echo $0 "Icon-1024.png"
exit 1
fi
function resize {
POSTFIX=$1
SIZE=$2
MULTIPLIER=$3
ACTUAL_SIZE=$(echo "$SIZE" '*' "$MULTIPLIER" | bc -l)
SIZE_STR=$ACTUAL_SIZE'x'$ACTUAL_SIZE
if [[ $MULTIPLIER -eq "1" ]]; then
FILENAME='Icon-'$SIZE$POSTFIX'.png'
else
FILENAME='Icon-'$SIZE'@'$MULTIPLIER'x'$POSTFIX'.png'
fi
__system "Resizing $FILENAME..."
convert $ICON -resize $SIZE_STR $OUTDIR/$FILENAME
}
# iPhone
resize '' 20 2
resize '' 20 3
resize '' 29 1
resize '' 29 2
resize '' 29 3
resize '' 40 2
resize '' 40 3
resize '' 60 2
resize '' 60 3
# iPad
resize '~ipad' 20 1
resize '~ipad' 20 2
resize '~ipad' 29 1
resize '~ipad' 29 2
resize '~ipad' 40 1
resize '~ipad' 40 2
resize '~ipad' 76 1
resize '~ipad' 76 2
resize '~ipad' 83.5 2
# App Store
resize '~ios-marketing' 1024 1
__system "Done"
__system "Output directory: $OUTDIR"
ls $OUTDIR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment