Skip to content

Instantly share code, notes, and snippets.

@kristopherjohnson
Last active February 3, 2020 15:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kristopherjohnson/4f01504e6b5816bd978807912bd4a5dc to your computer and use it in GitHub Desktop.
Save kristopherjohnson/4f01504e6b5816bd978807912bd4a5dc to your computer and use it in GitHub Desktop.
Script for generating iOS app icons in all necessary sizes
#!/bin/bash
#
# Given a source image, create icons in all sizes needed for an iOS app icon.
# See <https://developer.apple.com/library/ios/qa/qa1686/_index.html> for details.
#
# First (required) argument is path to source file.
#
# Second (optional) argument is the prefix to be used for the output files.
# If not specified, defaults to "Icon-".
#
# Third (optional) argument is the prefix to be used for the Watch output files.
# If not specified, defaults to "AppIcon".
#
# Fourth (optional) argument is path to the GraphicsMagick gm executable.
# If not specified, defaults to /usr/local/bin/gm.
#
# Requires GraphicsMagick. ("brew install graphicsmagick" on macOS)
set -e
if [ -z "$1" ]; then
echo "usage: make-ios-app-icons filename [output-file-prefix] [watch-output-file-prefix] [gm-path]"
exit 1
fi
source_file=$1
output_file_prefix=Icon-
watch_output_file_prefix=AppIcon
gm_path=/usr/local/bin/gm
if [ ! -z "$2" ]; then
output_file_prefix=$2
fi
if [ ! -z "$3" ]; then
watch_output_file_prefix=$3
fi
if [ ! -z "$4" ]; then
gm_path=$4
fi
if [ ! -e "$gm_path" ]; then
echo "error: GraphicsMagick executable not found at $gm_path"
exit 1
fi
generate_size() {
size=$1
output_file=$2
"$gm_path" convert "$source_file" -resize ${size}x${size}\! "$output_file"
}
generate_size 20 "${output_file_prefix}20.png"
generate_size 29 "${output_file_prefix}Small.png"
generate_size $((29 * 2)) "${output_file_prefix}Small@2x.png"
generate_size $((29 * 3)) "${output_file_prefix}Small@3x.png"
generate_size 40 "${output_file_prefix}Small-40.png"
generate_size $((40 * 2)) "${output_file_prefix}Small-40@2x.png"
generate_size $((40 * 3)) "${output_file_prefix}Small-40@3x.png"
generate_size 60 "${output_file_prefix}60.png"
generate_size $((60 * 2)) "${output_file_prefix}60@2x.png"
generate_size $((60 * 3)) "${output_file_prefix}60@3x.png"
generate_size 76 "${output_file_prefix}76.png"
generate_size $((76 * 2)) "${output_file_prefix}76@2x.png"
generate_size 167 "${output_file_prefix}83.5@2x.png"
generate_size 512 "iTunesArtwork.png"
generate_size $((512 * 2)) "iTunesArtwork@2x.png"
# Apple Watch
generate_size $((40 * 2)) "${watch_output_file_prefix}40x40@2x.png"
generate_size $((44 * 2)) "${watch_output_file_prefix}44x44@2x.png"
generate_size 48 "${watch_output_file_prefix}24@2x.png"
generate_size 55 "${watch_output_file_prefix}27_5@2x.png"
generate_size $((86 * 2)) "${watch_output_file_prefix}86x86@2x.png"
generate_size $((98 * 2)) "${watch_output_file_prefix}98x98@2x.png"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment