1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| function png2icon() { local image_file=$1 if [[ ! -f "${image_file}" ]]; then echo "No such file or directory: ${image_file}" exit 1 fi
local fmt=$(sips --getProperty format "${image_file}" | grep format | awk '{print $2}') local size=$(sips --getProperty pixelWidth "${image_file}" | grep pixelWidth | awk '{print $2}') local filename=${image_file%.*} local ico_size=32
mkdir -p "${filename}.iconset/" local resizes=(32 64 128 256 512 1024) for resize in ${resizes[*]}; do if [[ ${size} -ge ${resize} ]]; then sips -z ${resize} ${resize} "${image_file}" --out "${filename}.iconset/icon_${resize}x${resize}.${fmt}" ico_size=${resize} fi done
iconutil -c icns ${filename}.iconset if [[ $ico_size -ge 256 ]]; then ico_size=256 fi convert -resize x${ico_size} -gravity center -crop ${ico_size}x${ico_size}+0+0 "${image_file}" -flatten -colors 256 -background transparent "${filename}.ico" }
|