Last active
August 29, 2015 14:14
-
-
Save jorgemf/b8b798b577c3bab9f470 to your computer and use it in GitHub Desktop.
Shell script that transforms a svg file in png resource files for an android project. It uses inkscape as a tool to export to png
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 | |
if [ $# -eq 0 ]; then | |
echo "svg2android.sh [INPUT] [PROJECT_DIR] [OUTPUT_NAME] [SIZE_DP]" | |
exit | |
fi | |
INPUT=$1 | |
PROJECT=$2 | |
NAME="ic_launcher" | |
DP=48 | |
if [ $# -eq 4 ]; then | |
DP=$4 | |
NAME=$3 | |
fi | |
MAIN="${PROJECT}/src/main/" | |
RES="${MAIN}res/" | |
DRAWABLE="${RES}drawable" | |
echo "DP = $DP" | |
PX_MDP=$(expr $DP \* 1) | |
PX_HDP=$(expr $DP \* 3 / 2) # *1.5 rounded to the lowest | |
PX_XHDP=$(expr $DP \* 2) | |
PX_XXHDP=$(expr $DP \* 3) | |
PX_XXXHDP=$(expr $DP \* 4) | |
echo "HDP = $PX_HDP" | |
echo "XHDP = $PX_XHDP" | |
echo "XXHDP = $PX_XXHDP" | |
inkscape --export-png "${DRAWABLE}-mdpi/${NAME}.png" -w $PX_MDP "${INPUT}" | |
inkscape --export-png "${DRAWABLE}-hdpi/${NAME}.png" -w $PX_HDP "${INPUT}" | |
inkscape --export-png "${DRAWABLE}-xhdpi/${NAME}.png" -w $PX_XHDP "${INPUT}" | |
inkscape --export-png "${DRAWABLE}-xxhdpi/${NAME}.png" -w $PX_XXHDP "${INPUT}" | |
if [ $# -ne 4 ]; then | |
inkscape --export-png "${DRAWABLE}-xxxhdpi/${NAME}.png" -w $PX_XXXHDP "${INPUT}" | |
inkscape --export-png "${MAIN}${NAME}-web.png" -w 512 "${INPUT}" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment