From 803026b9e97a20d6c8e51007dc52dad0c57c0f9a Mon Sep 17 00:00:00 2001 From: bwt Date: Sat, 1 Feb 2020 06:16:49 -0500 Subject: [PATCH] Added scripts --- generate-icns.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 generate-icns.sh 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