Created
May 13, 2020 10:30
-
-
Save tomcurran/b26889fd0668f865a66c90cd59d7467c to your computer and use it in GitHub Desktop.
Move images named in iOS convention to Android resource directories convention
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 | |
# Moves ios images (file.png, file@2x.png, file@3x.png) into android drawable folders (drawable-mdpi, drawable-xhdpi, drawable-xxhdpi) and normalises file names. | |
# Simplified version of https://github.com/Ninjanetic/ios2android MIT License (MIT) | |
rm -rf drawable-mdpi | |
rm -rf drawable-xhdpi | |
rm -rf drawable-xxhdpi | |
mkdir drawable-mdpi | |
mkdir drawable-xhdpi | |
mkdir drawable-xxhdpi | |
function image2drawable { | |
x=${1/$2./.} | |
if [[ ${x} =~ -568h ]]; then | |
x=${x/-568h./.} | |
fi | |
x=${x//-/_} | |
if [[ ${x} =~ ^[0-9] ]]; then | |
x="img_${x}" | |
fi | |
x=`echo $x | tr "[:upper:]" "[:lower:]"` | |
echo $1 | |
cp $1 $3/$x | |
} | |
for ii in *.jpg *.png; do | |
if [ -f $ii ]; | |
then | |
if [[ ${ii} =~ @3x ]]; then | |
image2drawable ${ii} @3x drawable-xxhdpi | |
elif [[ ${ii} =~ @2x ]]; then | |
image2drawable ${ii} @2x drawable-xhdpi | |
else | |
image2drawable ${ii} "" drawable-mdpi | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment