-
-
Save alizainprasla/112b53777a7b90ee255546fa21b07ae0 to your computer and use it in GitHub Desktop.
Script for generating iOS app icons in all necessary sizes
This file contains 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 | |
# | |
# 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}[email protected]" | |
generate_size $((29 * 3)) "${output_file_prefix}[email protected]" | |
generate_size 40 "${output_file_prefix}Small-40.png" | |
generate_size $((40 * 2)) "${output_file_prefix}[email protected]" | |
generate_size $((40 * 3)) "${output_file_prefix}[email protected]" | |
generate_size 60 "${output_file_prefix}60.png" | |
generate_size $((60 * 2)) "${output_file_prefix}[email protected]" | |
generate_size $((60 * 3)) "${output_file_prefix}[email protected]" | |
generate_size 76 "${output_file_prefix}76.png" | |
generate_size $((76 * 2)) "${output_file_prefix}[email protected]" | |
generate_size 167 "${output_file_prefix}[email protected]" | |
generate_size 512 "iTunesArtwork.png" | |
generate_size $((512 * 2)) "[email protected]" | |
# Apple Watch | |
generate_size $((40 * 2)) "${watch_output_file_prefix}[email protected]" | |
generate_size $((44 * 2)) "${watch_output_file_prefix}[email protected]" | |
generate_size 48 "${watch_output_file_prefix}[email protected]" | |
generate_size 55 "${watch_output_file_prefix}[email protected]" | |
generate_size $((86 * 2)) "${watch_output_file_prefix}[email protected]" | |
generate_size $((98 * 2)) "${watch_output_file_prefix}[email protected]" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment