| 1 | #!/bin/sh |
| 2 | set -e |
| 3 | |
| 4 | readonly programName="${0##*/}" |
| 5 | |
| 6 | programMessage() { |
| 7 | local message="${1}" |
| 8 | |
| 9 | echo "${programName}: ${message}" |
| 10 | } |
| 11 | |
| 12 | syntaxError() { |
| 13 | local message="${1}" |
| 14 | |
| 15 | programMessage "${message}" |
| 16 | exit 2 |
| 17 | } |
| 18 | |
| 19 | semanticError() { |
| 20 | local message="${1}" |
| 21 | |
| 22 | programMessage "${message}" |
| 23 | exit 3 |
| 24 | } |
| 25 | |
| 26 | makeIcon() { |
| 27 | local name="${1}" |
| 28 | local size="${2}" |
| 29 | |
| 30 | convert "${imageFile}" -resize "${size}" "res/drawable-${name}/${imageName}.png" |
| 31 | } |
| 32 | |
| 33 | [ "${#}" -ge 1 ] || syntaxError "missing image file" |
| 34 | imageFile="${1}" |
| 35 | shift 1 |
| 36 | |
| 37 | [ "${#}" -eq 0 ] || syntaxError "too many parameters" |
| 38 | |
| 39 | [ -f "${imageFile}" ] || semanticError "image file not found: ${imageFile}" |
| 40 | [ -r "${imageFile}" ] || semanticError "image file not readable: ${imageFile}" |
| 41 | |
| 42 | imageName="${imageFile%.*}" |
| 43 | |
| 44 | makeIcon ldpi 36x36 |
| 45 | makeIcon mdpi 48x48 |
| 46 | makeIcon hdpi 72x72 |
| 47 | makeIcon xhdpi 96x96 |
| 48 | |
| 49 | exit 0 |