Last active
October 19, 2016 09:49
-
-
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)
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 |
I tried to run it on mac and it says: convert: command not found. Am I missing something?
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
You should place this script at the same level as the 'res' folder. Put your master images in the xhdpi folder and then run the script.