svg-to-android.sh

Additional

Language
Shell
Version
N/A
Created
Aug 21, 2014
Updated
Jul 14, 2018
Owner
Deepankar Bhardwaj (deepankarb)
Activity
N/A
Badge
Generate
Download
Source code

Promotion

A script to generate android assets from a SVG file. Requires inkscape to resize and convert.

Shell file (646 bytes): svg-to-android.sh

#!/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