Last active
December 5, 2016 14:44
-
-
Save erdemolkun/7e8699abde1ce96c795f7cf4bd2da745 to your computer and use it in GitHub Desktop.
android_asset_generator.sh
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
printSimpleAndExit(){ | |
echo "#simple usage ./asset_generator.sh <input.png> <output> <reference_ratio>" | |
exit 1 | |
} | |
printError(){ | |
echo "Error : $1" | |
} | |
resize(){ | |
echo "$3" | |
temp_file_name="$2.png" | |
convert "../$1" -resize "$3%" $temp_file_name | |
if [ ! -d "$4" ] | |
then | |
mkdir "$4" | |
fi | |
cp $temp_file_name "$4/" | |
rm "$temp_file_name" | |
} | |
# Check if file name is empty. | |
if [ -n "$1" ]; then | |
echo "Using File : '$1'" | |
else | |
printError "File name can't be empty" | |
printSimpleAndExit | |
fi | |
# Check if output file name is empty. | |
if [ -n "$2" ]; then | |
echo "To generate drawable files of '$2'" | |
else | |
printError "Output file name can't be empty" | |
printSimpleAndExit | |
fi | |
#convert $1 -resize 75% "$2.png" | |
#mkdir "$2" | |
#cd "$2" | |
#mkdir drawable-xxhdpi | |
#cd .. | |
#cp "$2.png" "$2/drawable-xxhdpi/" | |
# Create output folder if not exists | |
if [ ! -d "$2" ] | |
then | |
mkdir "$2" | |
fi | |
# Goto root of output folder to start resize | |
cd $2 | |
ratio=1 | |
# Check if output file name is empty. | |
if [ -n "$3" ]; then | |
ratio=$[$3 / 100] | |
fi | |
echo "Using Ratio : $ratio" | |
resize $1 $2 $[100/ratio] drawable-xxxhdpi | |
resize $1 $2 $[75/ratio] drawable-xxhdpi | |
resize $1 $2 $[50/ratio] drawable-xhdpi | |
resize $1 $2 $[33/ratio] drawable-hdpi | |
resize $1 $2 $[25/ratio] drawable-mdpi | |
echo "* Exported files successfully *" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment