Created
August 28, 2016 18:23
-
-
Save kristopherjohnson/9d90a99e4856f7e70cb9727bfb780641 to your computer and use it in GitHub Desktop.
bash script to create all necessary sizes of app icons for Android applications
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 Android launcher icon. | |
# | |
# First (required) argument is path to source file. | |
# | |
# Second (optional) argument is the filename to be used for the output files. | |
# If not specified, defaults to "ic_launcher.png". | |
# | |
# Third (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-android-app-icons filename [output-file-name] [gm-path]" | |
exit 1 | |
fi | |
source_file=$1 | |
output_file_name=ic_launcher.png | |
gm_path=/usr/local/bin/gm | |
if [ ! -z "$2" ]; then | |
output_file_name=$2 | |
fi | |
if [ ! -z "$3" ]; then | |
gm_path=$3 | |
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" | |
} | |
/bin/mkdir -p ./mdpi | |
/bin/mkdir -p ./hdpi | |
/bin/mkdir -p ./xhdpi | |
/bin/mkdir -p ./xxhdpi | |
/bin/mkdir -p ./xxxhdpi | |
/bin/mkdir -p ./play_store | |
generate_size 48 "./mdpi/${output_file_name}" | |
generate_size 72 "./hdpi/${output_file_name}" | |
generate_size 96 "./xhdpi/${output_file_name}" | |
generate_size 144 "./xxhdpi/${output_file_name}" | |
generate_size 192 "./xxxhdpi/${output_file_name}" | |
generate_size 512 "./play_store/${output_file_name}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment