Skip to content

Instantly share code, notes, and snippets.

@shortcircuit3
Last active August 10, 2016 12:22
Show Gist options
  • Select an option

  • Save shortcircuit3/1b9f011191382b833dfb to your computer and use it in GitHub Desktop.

Select an option

Save shortcircuit3/1b9f011191382b833dfb to your computer and use it in GitHub Desktop.
Convert @1x, @1.5x, @2x, @3x assets in 'Exports' folder to Android /mdpi, /hdpi, /xhdpi, /xxhdpi file structure
#!/bin/bash
# Let's get some color going!
red=$'\e[1;31m'
grn=$'\e[1;32m'
end=$'\e[0m'
# cd into directory where the script was run
cd "$(dirname "$0")"
# If '/Exports' doesn't exist, create the folder and exit
if [ ! -d "Exports" ]; then
mkdir "Exports"
printf "\n${red}No assets found in Exports${end}\n\n"
exit 0
fi
# if script was never run create drawable folder structure
if [ ! -d "_drawables" ]; then
mkdir "_drawables"
cd "_drawables"
mkdir "mdpi"
mkdir "hdpi"
mkdir "xhdpi"
mkdir "xxhdpi"
fi
# Move into exports folder and begin working...
cd "Exports"
# Move and rename @1x to /mdpi
printf "\nMoving and renaming @1x to /_drawables/mdpi..."
for file in *@1x.png
do
NAME=`echo "${file}"`
NAME2=`echo $NAME | sed -e 's/@1x//g'`
cp "${file}" ../_drawables/mdpi/"${NAME2}"
done
printf "\n${grn}Done!${end}\n"
# Move and rename @1.5x to /hdpi
printf "\nMoving and renaming @1.5x to /_drawables/hdpi..."
for file in *@1.5x.png
do
NAME=`echo "${file}"`
NAME2=`echo $NAME | sed -e 's/@1.5x//g'`
cp "${file}" ../_drawables/hdpi/"${NAME2}"
done
printf "\n${grn}Done!${end}\n"
# Move and rename @2x to /xhdpi
printf "\nMoving and renaming @2x to /_drawables/xhdpi..."
for file in *@2x.png
do
NAME=`echo "${file}"`
NAME2=`echo $NAME | sed -e 's/@2x//g'`
cp "${file}" ../_drawables/xhdpi/"${NAME2}"
done
printf "\n${grn}Done!${end}\n"
# Move and rename @3x to /xxhdpi
printf "\nMoving and renaming @3x to /_drawables/xxhdpi..."
for file in *@3x.png
do
NAME=`echo "${file}"`
NAME2=`echo $NAME | sed -e 's/@3x//g'`
cp "${file}" ../_drawables/xxhdpi/"${NAME2}"
done
printf "\n${grn}Done!${end}\n"
printf "\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment