Skip to content

Instantly share code, notes, and snippets.

@benvium
Last active October 19, 2016 09:49
Show Gist options
  • Select an option

  • Save benvium/8352993 to your computer and use it in GitHub Desktop.

Select an option

Save benvium/8352993 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)
#!/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
@benvium
Copy link
Author

benvium commented Aug 7, 2015

This script depends on ImageMagick - try this http://cactuslab.com/imagemagick/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment