Created
April 20, 2019 12:24
-
-
Save zhongwm/66e83277fb76606b7c228fef44271d18 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env bash | |
set -e | |
#### | |
# Author zhongwm 2019-4-20 | |
# This script uses cairosvg (python 3 package) to make iOS app icon from SVG file. | |
# Prerequisites install: brew install cairo && pip3 install cairosvg; | |
#### | |
INPUT=$1 | |
INPUT_BASENAME=`basename $INPUT` | |
INPUT_BASENAME_NOEXT=${INPUT%.*} | |
echo $INPUT_BASENAME_NOEXT | |
APPICONSET_DIR="$INPUT_BASENAME_NOEXT.appiconset" | |
sizes=$(cat <<EOT | |
1024 | |
120 | |
121 | |
152 | |
167 | |
180 | |
20 | |
29 | |
40 | |
41 | |
42 | |
58 | |
59 | |
60 | |
76 | |
80 | |
81 | |
87 | |
EOT | |
) | |
if [[ ! -e $APPICONSET_DIR ]]; then | |
mkdir "$APPICONSET_DIR" | |
elif [[ -f $APPICONSET_DIR ]]; then | |
echo There already exist a file named $INPUT_BASENAME_NOEXT, delete? | |
rm "$APPICONSET_DIR" | |
fi | |
_BACK_IFS=$IFS | |
IFS="\n" | |
echo $sizes | while read line | |
do | |
OUTFILE="$APPICONSET_DIR/Icon-$line.png" | |
[[ -e $OUTFILE ]] || echo -e "\tGenerating $OUTFILE..." | |
[[ -e $OUTFILE ]] && echo -e "\tExist, delete and generating \n\t\t$OUTFILE..." && rm -f $OUTFILE | |
# set -x | |
realsize=$line | |
# 58,59 -> 58 | |
# 40,41,42 -> 40 | |
# 120,121 -> 120 | |
# 80,81 -> 80 | |
if [[ $line -eq 41 ]]; then | |
realsize=40 | |
elif [[ $line -eq 42 ]]; then | |
realsize=40 | |
elif [[ $line -eq 59 ]]; then | |
realsize=58 | |
elif [[ $line -eq 121 ]]; then | |
realsize=120 | |
elif [[ $line -eq 81 ]]; then | |
realsize=80 | |
fi | |
cairosvg -o "${OUTFILE}" --output-width $realsize --output-height $realsize -f png "$INPUT" | |
# set +x | |
done | |
IFS=$_BACK_IFS | |
ContentsDotJSON=$(cat <<EOT | |
{ | |
"images" : [ | |
{ | |
"size" : "20x20", | |
"idiom" : "iphone", | |
"filename" : "Icon-40.png", | |
"scale" : "2x" | |
}, | |
{ | |
"size" : "20x20", | |
"idiom" : "iphone", | |
"filename" : "Icon-60.png", | |
"scale" : "3x" | |
}, | |
{ | |
"size" : "29x29", | |
"idiom" : "iphone", | |
"filename" : "Icon-58.png", | |
"scale" : "2x" | |
}, | |
{ | |
"size" : "29x29", | |
"idiom" : "iphone", | |
"filename" : "Icon-87.png", | |
"scale" : "3x" | |
}, | |
{ | |
"size" : "40x40", | |
"idiom" : "iphone", | |
"filename" : "Icon-80.png", | |
"scale" : "2x" | |
}, | |
{ | |
"size" : "40x40", | |
"idiom" : "iphone", | |
"filename" : "Icon-120.png", | |
"scale" : "3x" | |
}, | |
{ | |
"size" : "60x60", | |
"idiom" : "iphone", | |
"filename" : "Icon-121.png", | |
"scale" : "2x" | |
}, | |
{ | |
"size" : "60x60", | |
"idiom" : "iphone", | |
"filename" : "Icon-180.png", | |
"scale" : "3x" | |
}, | |
{ | |
"size" : "20x20", | |
"idiom" : "ipad", | |
"filename" : "Icon-20.png", | |
"scale" : "1x" | |
}, | |
{ | |
"size" : "20x20", | |
"idiom" : "ipad", | |
"filename" : "Icon-42.png", | |
"scale" : "2x" | |
}, | |
{ | |
"size" : "29x29", | |
"idiom" : "ipad", | |
"filename" : "Icon-29.png", | |
"scale" : "1x" | |
}, | |
{ | |
"size" : "29x29", | |
"idiom" : "ipad", | |
"filename" : "Icon-59.png", | |
"scale" : "2x" | |
}, | |
{ | |
"size" : "40x40", | |
"idiom" : "ipad", | |
"filename" : "Icon-41.png", | |
"scale" : "1x" | |
}, | |
{ | |
"size" : "40x40", | |
"idiom" : "ipad", | |
"filename" : "Icon-81.png", | |
"scale" : "2x" | |
}, | |
{ | |
"size" : "76x76", | |
"idiom" : "ipad", | |
"filename" : "Icon-76.png", | |
"scale" : "1x" | |
}, | |
{ | |
"size" : "76x76", | |
"idiom" : "ipad", | |
"filename" : "Icon-152.png", | |
"scale" : "2x" | |
}, | |
{ | |
"size" : "83.5x83.5", | |
"idiom" : "ipad", | |
"filename" : "Icon-167.png", | |
"scale" : "2x" | |
}, | |
{ | |
"size" : "1024x1024", | |
"idiom" : "ios-marketing", | |
"filename" : "Icon-1024.png", | |
"scale" : "1x" | |
} | |
], | |
"info" : { | |
"version" : 1, | |
"author" : "xcode" | |
} | |
} | |
EOT | |
) | |
echo -e $ContentsDotJSON>"$APPICONSET_DIR/Contents.json" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment