Skip to content

Instantly share code, notes, and snippets.

@ookami-kb
Last active August 29, 2015 14:03
Show Gist options
  • Save ookami-kb/80b0f28ac4797dbd8957 to your computer and use it in GitHub Desktop.
Save ookami-kb/80b0f28ac4797dbd8957 to your computer and use it in GitHub Desktop.
resize and put into res/drawable-* directories
#!/bin/sh
show_help() {
cat << EOF
Usage: ${0##*/} -i INPUT_FILE -o OUTPUT_RES_DIR -s MDPI_SIZE -n NAME
EOF
}
while getopts "hi:s:o:n:" opt; do
case $opt in
i)
input=$OPTARG
;;
s)
size=$OPTARG
;;
o)
output=${OPTARG%/}
;;
n)
name=$OPTARG
;;
h)
show_help
exit 0
;;
'?')
show_help >&2
exit 1
;;
esac
done
if [ -z ${input} ] || [ -z ${size} ] || [ -z ${output} ] || [ -z ${name} ]
then
show_help >&2
exit 1
fi
mkdir ${output}/drawable-mdpi > /dev/null 2>&1
mkdir ${output}/drawable-hdpi > /dev/null 2>&1
mkdir ${output}/drawable-xhdpi > /dev/null 2>&1
convert ${input} -resize ${size} ${output}/drawable-mdpi/${name}.png
convert ${input} -resize $(echo ${size}*1.5 | bc) ${output}/drawable-hdpi/${name}.png
convert ${input} -resize $((size*2)) ${output}/drawable-xhdpi/${name}.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment