Skip to content

Instantly share code, notes, and snippets.

@kaunteya
Last active March 5, 2016 19:47
Show Gist options
  • Save kaunteya/4dda366a5ccb5edf7903 to your computer and use it in GitHub Desktop.
Save kaunteya/4dda366a5ccb5edf7903 to your computer and use it in GitHub Desktop.
This bash script creates icon of all the required sizes for OS X | iOS | Android
#!/bin/bash
inputFile=$1
directoryName=$2
[ $# -ne 2 ] && echo "Arguments improper. scaleK image.png outputdirectory " && exit
[ ! -f $inputFile ] && echo "File not found!" && exit;
sizeArrayMac=('16' '32' '128' '256' '512')
sizeArrayiOS=('29' '40' '60')
mkdir -p "${directoryName}/mac"
mkdir -p "${directoryName}/iOS"
# Make images for Mac
for size in ${sizeArrayMac[@]}; do
a="${directoryName}/mac/${size}x${size}.png"
b="${directoryName}/mac/${size}x${size}@2x.png"
sips -Z ${size} ${inputFile} -o ${a}
sips -Z $[size*2] ${inputFile} -o ${b}
done
#Make images for iOS
for size in ${sizeArrayiOS[@]}; do
a="${directoryName}/iOS/${size}x${size}.png"
b="${directoryName}/iOS/${size}x${size}@2x.png"
c="${directoryName}/iOS/${size}x${size}@3x.png"
sips -Z ${size} ${inputFile} -o ${a}
sips -Z $[size*2] ${inputFile} -o ${b}
sips -Z $[size*3] ${inputFile} -o ${c}
done
# Make for android
mkdir -p "${directoryName}/res/mipmap-hdpi"
mkdir -p "${directoryName}/res/mipmap-mdpi"
mkdir -p "${directoryName}/res/mipmap-xhdpi"
mkdir -p "${directoryName}/res/mipmap-xxhdpi"
mkdir -p "${directoryName}/res/mipmap-xxxhdpi"
sips -Z 72 ${inputFile} -o "${directoryName}/res/mipmap-hdpi/ic_launcher.png"
sips -Z 48 ${inputFile} -o "${directoryName}/res/mipmap-mdpi/ic_launcher.png"
sips -Z 96 ${inputFile} -o "${directoryName}/res/mipmap-xhdpi/ic_launcher.png"
sips -Z 144 ${inputFile} -o "${directoryName}/res/mipmap-xxhdpi/ic_launcher.png"
sips -Z 192 ${inputFile} -o "${directoryName}/res/mipmap-xxxhdpi/ic_launcher.png"
echo -e "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment