Created
October 28, 2015 14:01
-
-
Save stevesparks/c1a7e5a3d9ffde9990b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# Export Icons | |
# | |
# If you have a square image "bob.png" and you need to rapidly generate the right | |
# icon sizes, and you have ImageMagick installed, this script will do it for you. | |
# The quality suffers at lower sizes, so this is not some sort of production icon | |
# maker. I use it to icon my quick test apps. | |
# | |
# No guarantees, warranties, etc. | |
# | |
# Steve Sparks, Big Nerd Ranch. | |
# | |
if [ ! -f "$1" ]; then | |
echo "Usage: $0 <input-file>" | |
exit 1 | |
fi | |
BASE=`echo $1 | cut -d . -f 1`; | |
TAIL=`echo $1 | cut -d . -f 2-`; | |
set_size_label() | |
{ | |
case "$1" in | |
40) | |
SIZE_LABEL=40pt@1x | |
;; | |
48) | |
SIZE_LABEL=24pt@2x | |
;; | |
55) | |
SIZE_LABEL=27.5pt@2x | |
;; | |
58) | |
SIZE_LABEL=29pt@2x | |
;; | |
87) | |
SIZE_LABEL=29pt@3x | |
;; | |
80) | |
SIZE_LABEL=40pt@2x | |
;; | |
88) | |
SIZE_LABEL=44pt@2x | |
;; | |
120) | |
SIZE_LABEL=40pt@3x | |
;; | |
180) | |
SIZE_LABEL=60pt@3x | |
;; | |
76) | |
SIZE_LABEL=76pt@1x | |
;; | |
152) | |
SIZE_LABEL=76pt@2x | |
;; | |
172) | |
SIZE_LABEL=86pt@2x | |
;; | |
196) | |
SIZE_LABEL=98pt@2x | |
;; | |
esac | |
} | |
if [ ! -f ${BASE}/watch/ ]; then | |
mkdir -p ${BASE}/watch/ | |
fi | |
case $TAIL in | |
jpg) TAIL=png;; | |
esac | |
echo exporting watch sizes for ${BASE} ... | |
for SIZE in 48 55 58 87 80 88 172 196; do | |
set_size_label ${SIZE} | |
NEWFILE=$BASE/watch/${BASE}-${SIZE_LABEL}.${TAIL} | |
convert $1 -resize ${SIZE}x${SIZE} ${NEWFILE} | |
done | |
if [ ! -f ${BASE}/app/ ]; then | |
mkdir -p ${BASE}/app/ | |
fi | |
echo exporting app sizes for ${BASE} ... | |
for SIZE in 58 87 80 120 180 40 76 152; do | |
set_size_label ${SIZE} | |
NEWFILE=$BASE/app/${BASE}-${SIZE_LABEL}.${TAIL} | |
convert $1 -resize ${SIZE}x${SIZE} ${NEWFILE} | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment