-
-
Save zulu-pham/a5d540eb16fae2e4e3c6ba7e64f799cb to your computer and use it in GitHub Desktop.
Android app script for Android Studio / Android SDK. This script resizes android xhdpi-sized png image assets into the ldpi, mdpi, hdpi, xhdpi folders. Now just maintain one folder of images rather than 4 or 5. Updated to create directories if needed and also to separately convert images in the mipmap folder (used for app icons)
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 -e | |
# Ensure we're running in location of script. | |
cd "`dirname $0`" | |
function fail { | |
echo "FAILED with $1" | |
exit 1 | |
} | |
function doConversion() { | |
local folderName=$1 | |
echo "Using $folderName..." | |
cd "res/$folderName-xhdpi" || fail "No $folderName-xhdpi folder" | |
for f in *; do | |
if [[ ${f} == *.png ]]; | |
then | |
echo "...$f" | |
if [[ ${f} != *.9.png ]]; | |
then | |
# ensure folders exist | |
mkdir -p "../$folderName-xhdpi" || fail "can't make folder" | |
mkdir -p "../$folderName-hdpi" || fail "can't make folder" | |
mkdir -p "../$folderName-mdpi" || fail "can't make folder" | |
mkdir -p "../$folderName-ldpi" || fail "can't make folder" | |
convert ${f} -resize 75% "../$folderName-hdpi/${f}" || fail "Failed with ../$folderName-hdpi/${f}" | |
convert ${f} -resize 50% "../$folderName-mdpi/${f}" || fail "Failed with ../$folderName-mdpi/${f}" | |
convert ${f} -resize 37.5% "../$folderName-ldpi/${f}" || fail "Failed with ../$folderName-ldpi/${f}" | |
else | |
echo "not resizing ${f} as it's a 9-patch" | |
fi | |
fi | |
done | |
cd - | |
} | |
# Convert graphic images | |
doConversion "drawable" | |
# Convert app icon (now goes in the mipmap folder) | |
doConversion "mipmap" | |
echo Complete |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment