diff --git a/generate-icns.sh b/generate-icns.sh new file mode 100755 index 0000000..5f5d262 --- /dev/null +++ b/generate-icns.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +abs() { + [[ $[ $@ ] -lt 0 ]] && echo "$[ ($@) * -1 ]" || echo "$[ $@ ]" +} + +DIMS=( $(identify "${1}" | cut -d\ -f3 | sed "s/x/ /g") ) +PWRS=( 16 32 128 256 512 1024 ) + +for PWR in ${PWRS[@]}; do + WIDEDIFS+=( $(abs "${DIMS[0]}-${PWR}") ) + HITEDIFS+=( $(abs "${DIMS[1]}-${PWR}") ) +done + +IFS=$'\n' +WIDESORT=( $(sort -n <<<"${WIDEDIFS[*]}")) +HITESORT=( $(sort -n <<<"${HITEDIFS[*]}")) +unset IFS + +for SIZE in $((DIMS[0] - WIDESORT[0])) $((DIMS[0] + WIDESORT[0])); do + (( SIZE > 0 && (SIZE & (SIZE - 1)) == 0 )) && RESIZE=${SIZE} +done + +set -x +convert "${1}" -resize ${RESIZE}x${RESIZE} /tmp/tmp.png +png2icns ${1/%png/icns} /tmp/tmp.png +rm /tmp/tmp.png