Skip to content

Instantly share code, notes, and snippets.

@JerzyPuchalski
Forked from deepankarb/svg-to-android.sh
Created February 9, 2016 19:36
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 JerzyPuchalski/a4edd09e5d7d592801fd to your computer and use it in GitHub Desktop.
Save JerzyPuchalski/a4edd09e5d7d592801fd to your computer and use it in GitHub Desktop.
A script to generate android assets from a SVG file. Requires inkscape to resize and convert.
#!/bin/bash
if [[ -z "$1" ]];
then
echo "No SVG file specified. Exiting."
exit -1
fi
ispng=$(file $1)
echo $ispng | grep -q SVG
if [[ $? -ne 0 ]];
then
echo "Invalid SVG file. Exiting."
exit -2
fi
W=(48 72 96 144 192)
DPINAME=("mdpi" "hdpi" "xhdpi" "xxhdpi" "xxxhdpi")
if [[ -z "$2" ]];
then
BASE="ic_launcher"
else
BASE="$2"
fi
for ((ii=0;ii<5;ii++));
do
echo "Processing $1 for ${DPINAME[$ii]}@${W[$ii]} px"
suffix=${DPINAME[$ii]}
resroot=`basename $1`
dirname=$resroot/res/drawable-${DPINAME[$ii]}
mkdir -p "$dirname"
fname="$dirname"/"$BASE".png
inkscape -z -f=$1 --export-png="$fname" \
-h=${W[$ii]}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment