Skip to content

Instantly share code, notes, and snippets.

@bradmontgomery
Last active March 5, 2018 18:44
Show Gist options
  • Save bradmontgomery/a4b4465511defc07aaca to your computer and use it in GitHub Desktop.
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.
#!/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