Skip to content

Instantly share code, notes, and snippets.

@Hais
Last active January 26, 2016 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hais/16276a7c97207ec5fbf4 to your computer and use it in GitHub Desktop.
Save Hais/16276a7c97207ec5fbf4 to your computer and use it in GitHub Desktop.
Generate XCode assets
#!/bin/bash
CAT_NAME=${PWD##*/}
XCASSETS_DIR="./${CAT_NAME}.xcassets"
mkdir $XCASSETS_DIR
for SVG_FILE in *.svg
do
NAME="${SVG_FILE%.*}"
#echo $NAME
ICONSET_DIR="${XCASSETS_DIR}/${NAME}.imageset"
#echo $ICONSET_DIR
mkdir $ICONSET_DIR
echo ""
printf "%40s: %s" ${NAME}
PDF_FILE="${ICONSET_DIR}/${NAME}.pdf"
#echo $PDF_FILE
inkscape $SVG_FILE --export-pdf=$PDF_FILE >/dev/null 2>&1
if [ $? -eq 0 ]; then
FILESIZE=$(du -h "$PDF_FILE" | cut -f 1)
echo -ne "${FILESIZE}"
else
echo -e "\n FAIL \n"
exit
fi
CONTENTS_JSON="${ICONSET_DIR}/Contents.json"
cat >$CONTENTS_JSON <<EOL
{
"images" : [
{
"idiom" : "universal",
"filename" : "${NAME}.pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
EOL
done
#!/bin/bash
for SVG_FILE in *.svg
do
NAME="${SVG_FILE%.*}"
WD=`pwd`
for POINTS in 16 29 32 40 50 57 60 72 76 83.5 120 128 256 512
do
for I in 1 2 3
do
echo "points = $POINTS"
echo "i = $I"
WIDTH=`echo "$POINTS * $I" | bc -l | xargs -0 printf "%d" 2> /dev/null`
echo "width = $WIDTH"
EXPORT_PNG="${WD}/${NAME}-${POINTS}-@${I}x.png"
echo $EXPORT_PNG
inkscape ${WD}/${SVG_FILE} --export-png=$EXPORT_PNG -w$WIDTH
done
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment