Last active
March 5, 2018 18:44
-
-
Save bradmontgomery/a4b4465511defc07aaca to your computer and use it in GitHub Desktop.
A bash function to resize a collection of icons (e.g. png images) and organize them using android studio's drawable directory format.
This file contains hidden or 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 | |
# Given a collection of .png files, this function will resize the images | |
# and organize them in a way that android studio expects. | |
# | |
# Usage: resize_drawables *.png | |
# | |
# Given a file, my_icon.png, the command: | |
# | |
# rezie_drawables my_icon.png | |
# | |
# will output: | |
# | |
# drawable-mdpi/my_icon.png | |
# drawable-hdpi/my_icon.png | |
# drawable-xhdpi/my_icon.png | |
# drawable-xxhdpi/my_icon.png | |
# drawable-xxxhdpi/my_icon.png | |
function resize_drawables() | |
{ | |
for file in "$@"; do | |
sizes=(24, 36, 48, 72, 96) | |
locations=(mdpi hdpi xhdpi xxhdpi xxxhdpi) | |
for i in ${!sizes[@]}; do | |
mkdir -p drawable-${locations[$i]} | |
sips -Z ${sizes[$i]} $file --out drawable-${locations[$i]} | |
done | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment