Skip to content

Instantly share code, notes, and snippets.

@tomcurran
Created May 13, 2020 10:29
Show Gist options
  • Save tomcurran/071439c24b3b867df02cd4b16de9a633 to your computer and use it in GitHub Desktop.
Save tomcurran/071439c24b3b867df02cd4b16de9a633 to your computer and use it in GitHub Desktop.
Move images into Android drawable directories
#!/bin/bash
# Moves assets into android drawable folders and normalise file names.
# file@mdpi.png -> drawable-mdpi
# file@hdpi.png -> drawable-hdpi
# file@xhdpi.png -> drawable-xhdpi
# file@xxhdpi.png -> drawable-xxhdpi
# file@xxxhdpi.png -> drawable-xxxhdpi
# file.svg -> drawable-anydpi-v21 (svgs need converted to vector drawables using android studio vector asset import tool)
# Based on https://github.com/Ninjanetic/ios2android MIT License (MIT)
rm -rf drawable-anydpi-v21
rm -rf drawable-mdpi
rm -rf drawable-hdpi
rm -rf drawable-xhdpi
rm -rf drawable-xxhdpi
rm -rf drawable-xxxhdpi
mkdir drawable-anydpi-v21
mkdir drawable-mdpi
mkdir drawable-hdpi
mkdir drawable-xhdpi
mkdir drawable-xxhdpi
mkdir drawable-xxxhdpi
function image2drawable {
x=${1/$2./.}
x=${x//-/_}
x=${x//+/_}
x=`echo $x | tr "[:upper:]" "[:lower:]"`
echo $1
cp $1 $3/$x
}
for ii in *.jpg *.png *.svg; do
if [ -f $ii ];
then
if [[ ${ii} =~ @xxxhdpi ]]; then
image2drawable ${ii} @xxxhdpi drawable-xxxhdpi
elif [[ ${ii} =~ @xxhdpi ]]; then
image2drawable ${ii} @xxhdpi drawable-xxhdpi
elif [[ ${ii} =~ @xhdpi ]]; then
image2drawable ${ii} @xhdpi drawable-xhdpi
elif [[ ${ii} =~ @hdpi ]]; then
image2drawable ${ii} @hdpi drawable-hdpi
elif [[ ${ii} =~ @mdpi ]]; then
image2drawable ${ii} @mdpi drawable-mdpi
else
image2drawable ${ii} "" drawable-anydpi-v21
fi
fi
done
echo ''
echo 'svg files in drawable-anydpi-v21 should be converted to vector drawables using android studio vector asset import tool'
echo ''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment