Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env bash
# This script assumes that ImageMagick is installed and the convert command is accessible via the $PATH variable
# Ensure that one argument has been passed in.
if [ ! "$#" -eq 1 ]
then
echo -e "This script requires one argument.\\ne.g. iOS_icon_maker.sh app_icon.png"
exit 1
fi
# Assign the argument to the path variable so it is easier to follow throughout the script.
path=$1
# Ensure that the path points to a valid file.
if [ ! -f "$path" ]
then
echo "Path must point to a valid file."
exit 1
fi
# This function takes in the dimension of the icon (it assumes the icon is a square) and the name of the file to save the icon to.
function createIconImage()
{
iconDimension=$1
iconName=$2
convert "$path" -resize ${iconDimension}x${iconDimension}^ -gravity center -extent ${iconDimension}x${iconDimension} $iconName
}
# Create all the suggested icons for both the iPhone and iPad platforms to ensure the best appearance.
# iOS 8.0+
# iPhone 6 Plus
createIconImage 180 icon-60@3x.png
# iOS 7.0+
# iPhone / iPod Touch
createIconImage 60 icon-60.png
createIconImage 120 icon-60@2x.png
# ipad
createIconImage 76 icon-76.png
createIconImage 152 icon-76@2x.png
# iOS 6.1
# Spotlight iCon
createIconImage 40 icon-40.png
createIconImage 80 icon-40@2x.png
# iPhone / iPod Touch
createIconImage 57 icon-57.png
createIconImage 114 icon-57@2x.png
# iPad
createIconImage 72 icon-72.png
createIconImage 144 icon-72@2x.png
# iPhone Spotlight and Settings Icon
createIconImage 29 icon-29.png
createIconImage 58 icon-29@2x.png
# iPad Spotlight and Settings Icon
createIconImage 50 icon-50.png
createIconImage 100 icon-50@2x.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.