Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.