svg-to-android.sh

General

Category
Free
Tag
SVG
License
N/A
Registered
Aug 25, 2014
Favorites
0
Link
https://gist.github.com/deepankarb/e69de4373ebd7067e0fc
See also
kanji-strokeview
SVGMapView
VectorChildFinder
SVG Logos
SVG2VectorDrawable

Additional

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

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