Skip to content

Instantly share code, notes, and snippets.

@toshi0383
Last active August 30, 2015 01:40
Show Gist options
  • Select an option

  • Save toshi0383/efe6affc8543e5f936c3 to your computer and use it in GitHub Desktop.

Select an option

Save toshi0383/efe6affc8543e5f936c3 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# name:
# mkicon.sh
#
# description:
# Generates icon images from original file
# The original image should be larger than 1024x1024 in pixel
#
# parameters:
# $1:original file
# $2:mac/ios
#
# dependencies:
# sips
#
if [ $# -ne 2 ];then
echo give me an original file and mac/ios
exit 1
fi
org=$1
target=$2
if [ ! -f $org ];then
echo file not found: $org
exit 1
fi
OLD_IFS=$IFS
IFS='.'
set -- $org
if [ $# -ne 2 ];then
IFS=$OLD_IFS
echo File format error. Filename should not contain \
multiple \'.\' : $org
exit 1
fi
prefix=$1
suffix=$2
IFS=$OLD_IFS
case $target in
"mac" ) sizes=(16 32 64 128 256 512 1024);;
"ios" ) sizes=(29 58 87 76 152 60 120 180 \
40 80 120 72 144 50 100 57 \
114 512 1024);;
esac
for i in ${sizes[@]}
do
f=${prefix}_${i}.${suffix}
cp $org $f
sips -Z $i $f
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment