Created
June 13, 2017 12:41
-
-
Save qalqi/a3afc38ce4bf14fb80c1c88e3eb1cbff 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/bash -e | |
# Transforms a SVG into a PNG for each platform | |
# Sizes extracted from | |
# http://developer.android.com/design/style/iconography.html | |
# https://stackoverflow.com/a/23015417/2560946 | |
[ -z $2 ] && echo -e "ERROR: filename and one dimension (-w or -h) is required, for example:\nsvg2png -w48 icon.svg\n" && exit 1; | |
FILENAME=$2 | |
DEST_FILENAME=`echo $2 | sed s/\.svg/\.png/` | |
FLAG=`echo $1 | cut -c1-2` | |
ORIGINAL_VALUE=`echo $1 | cut -c3-` | |
if [ "$FLAG" != "-w" ] && [ "$FLAG" != "-h" ]; then | |
echo "Unknown parameter: $FLAG" | |
exit 1 | |
fi | |
# PARAMETERS: {multiplier} {destination folder} | |
function export { | |
VALUE=$(echo "scale=0; $ORIGINAL_VALUE*$1" | bc -l) | |
CMD="inkscape $FLAG$VALUE --export-background-opacity=0 --export-png=src/main/res/$2/$DEST_FILENAME src/main/svg/$FILENAME > /dev/null" | |
echo $CMD | |
eval $CMD | |
} | |
export 1 drawable-mdpi | |
export 1.5 drawable-hdpi | |
export 2 drawable-xhdpi | |
export 3 drawable-xxhdpi | |
export 4 drawable-xxxhdpi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment