Skip to content

Instantly share code, notes, and snippets.

@rharter
Forked from Arood/images2android.sh
Created January 28, 2014 23:51
Show Gist options
  • Save rharter/8679028 to your computer and use it in GitHub Desktop.
Save rharter/8679028 to your computer and use it in GitHub Desktop.
type mogrify >/dev/null 2>&1 || { echo >&2 "» This script requires mogrify. Please install ImageMagick first!"; exit 1; }
IOS_IMAGE_PATH="$1"
OUTPUT_PATH="$2"
mkdir -p $OUTPUT_PATH/res/drawable-hdpi $OUTPUT_PATH/res/drawable-mdpi $OUTPUT_PATH/res/drawable-xhdpi
echo " » Copy all resources to MDPI, this is"
echo " the same density as a non-retina iOS device"
find "${IOS_IMAGE_PATH}"/* -type f -exec cp {} ${OUTPUT_PATH}/res/drawable-mdpi/ \;
echo " » Move the retina resources to XHDPI, which"
echo " has the same density as a retina iOS device"
find ${OUTPUT_PATH}/res/drawable-mdpi/* -type f -regex ".*@2x.*" -exec mv {} ${OUTPUT_PATH}/res/drawable-xhdpi/ \;
echo " » Remove @2x from XHDPI filenames"
find ${OUTPUT_PATH}/res/drawable-xhdpi/* -type f -exec bash -c 'file={}; mv $file ${file/@2x/}' \;
echo " » Generate HDPI by copying XHDPI and resize these by 75%"
cp -R ${OUTPUT_PATH}/res/drawable-xhdpi/* ${OUTPUT_PATH}/res/drawable-hdpi/
find ${OUTPUT_PATH}/res/drawable-hdpi/* -type f -exec mogrify -resize 75% {} \;
echo " » Done!"
@rharter
Copy link
Author

rharter commented Jan 28, 2014

I've updated the gist to support transforming images from a single input directory to standard Android directories instead of Titanium drawable.

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