Android Application Launcher Icon generator bash script

Android Launcher icon sizes are as following,

48 × 48 (mdpi)
72 × 72 (hdpi)
96 × 96 (xhdpi)
144 × 144 (xxhdpi)
192 × 192 (xxxhdpi)
512 × 512 (Google Play store)

So, when you create an image with one size, we need to convert this image icon to match with different screen sizes.

The below shell script will help you to create android app launcher icons for different screen resolutions.

Create the shell script as below,

$ vim make_android_icon.sh 
#!/bin/sh

#argument image should be with png format

#cleanup previous icons
DIR_TO_SAVE_ICONS=$PWD/android_icons
rm -rf $DIR_TO_SAVE_ICONS
ICON_NAME=$1 #take icon name as first argument

echo "Creating android icons of different dimensions for $ICON_NAME"

mkdir -p $DIR_TO_SAVE_ICONS/drawable-xxxhdpi/
mkdir -p $DIR_TO_SAVE_ICONS/drawable-xxhdpi/
mkdir -p $DIR_TO_SAVE_ICONS/drawable-xhdpi/
mkdir -p $DIR_TO_SAVE_ICONS/drawable-hdpi/
mkdir -p $DIR_TO_SAVE_ICONS/drawable-mdpi/
mkdir -p $DIR_TO_SAVE_ICONS/drawable-ldpi/

convert $ICON_NAME -resize 192x192 $DIR_TO_SAVE_ICONS/drawable-xxxhdpi/$ICON_NAME
convert $ICON_NAME -resize 144x144 $DIR_TO_SAVE_ICONS/drawable-xxhdpi/$ICON_NAME
convert $ICON_NAME -resize 96x96 $DIR_TO_SAVE_ICONS/drawable-xhdpi/$ICON_NAME
convert $ICON_NAME -resize 72x72 $DIR_TO_SAVE_ICONS/drawable-hdpi/$ICON_NAME
convert $ICON_NAME -resize 48x48 $DIR_TO_SAVE_ICONS/drawable-mdpi/$ICON_NAME
convert $ICON_NAME -resize 36x36 $DIR_TO_SAVE_ICONS/drawable-ldpi/$ICON_NAME

#create a zip to copy to android app, res folder

cd $DIR_TO_SAVE_ICONS
zip -r $ICON_NAME.zip .

echo "Icon zip $ICON_NAME.zip is ready at $DIR_TO_SAVE_ICONS"

Now, you need to pass the icon / image name which you want to convert to different sizes as first argument to shell script.

$ make_android_icon.sh image.png

Once this script is executed, you will get the different icons at respective drawable folders.

Extract above generated .zip inside res folder of application source.

Reference : https://iconhandbook.co.uk/reference/chart/android/

Leave a Comment