Skip to content

Instantly share code, notes, and snippets.

@Kishanjvaghela
Last active November 17, 2022 11:26
Show Gist options
  • Save Kishanjvaghela/8ec54f66c322d8d6940b4c0d1a58098d to your computer and use it in GitHub Desktop.
Save Kishanjvaghela/8ec54f66c322d8d6940b4c0d1a58098d to your computer and use it in GitHub Desktop.
Create Image drawable for all resolutions
if [ $# -eq 0 ]; then
echo "No arguments supplied"
else if [ -f "$1" ]; then
echo " Creating different dimensions (dips) of "$1" ..."
mkdir -p drawable-xxhdpi
mkdir -p drawable-xhdpi
mkdir -p drawable-hdpi
mkdir -p drawable-mdpi
if [ $1 = "ic_launcher.png" ]; then
echo " App icon detected"
convert ic_launcher.png -resize 144x144 drawable-xxhdpi/ic_launcher.png
convert ic_launcher.png -resize 96x96 drawable-xhdpi/ic_launcher.png
convert ic_launcher.png -resize 72x72 drawable-hdpi/ic_launcher.png
convert ic_launcher.png -resize 48x48 drawable-mdpi/ic_launcher.png
rm -i ic_launcher.png
else
convert $1 -resize 67% drawable-xhdpi/$1
convert $1 -resize 50% drawable-hdpi/$1
convert $1 -resize 33% drawable-mdpi/$1
mv $1 drawable-xxhdpi/$1
fi
echo " Done"
else
echo "$1 not found."
fi
fi
@Kishanjvaghela
Copy link
Author

Kishanjvaghela commented Jul 14, 2017

How to use:
./converter.sh <app icon path>
This will create all drawable folders if not have already in pwd.

Example:

./converter.sh ic_bag.png

@rdromao
Copy link

rdromao commented Jul 15, 2017

That's a great addition 👍

There's an extra fi at the end I think but everything else is on point, going to edit the StackOverflow answer now

@rdromao
Copy link

rdromao commented Aug 22, 2017

Nevermind, that last fi should in fact be there

@matkoniecz
Copy link

@Kishanjvaghela Can you consider releasing it under some open license, for example GNU GPL v3? See https://choosealicense.com/

I want to include it as a part of a project (Android app) and as it is fully copyrighted I am not allowed to do this.

@Kishanjvaghela
Copy link
Author

@matkoniecz Thanks for the suggestion.
https://github.com/Kishanjvaghela/drawable-converter
Please check it. Let me know its working or not for you.

@Abdallah-Abdelazim
Copy link

Thanks for sharing this. It works great.
I've forked this gist and added xxxhdpi drawable generation. Also, added better documentation.
Here's my fork: https://gist.github.com/Abdallah-Abdelazim/af99647e1f9542fd4b4fa770c508c335

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