vsupalov


Exporting an inkscape logo in many resolutions via script

January 10, 2012 [ inkscape | bash | android | chrome ]

Lately I have been fiddling with android/chrome development, and one of the more tedious tasks is creating assets from the same source with different target resolutions. A very simple thing to save you from repeatedly exporting the same file by hand is (obviously) scripting.

The script version below assumes that the asset file are in an assets/ directory in the root of an android project. The script expects to be executed from the assets/ directory.

#! /bin/bash

# the input file relative to the script working directory
IN_FILE=assetInInkscapeFromat.svg
# this assumes, that there is an asset directory in the project root
OUT_PATH=../res/drawable-
# the standard icon name
OUT_FILE=ic_launcher.png

# -z makes inkscape run without gui
# -f specifies an input file
# -e stands for --export-png
# -D exports the whole drawing
# -w and -h can be used to specify the output dimensions
inkscape -z -f $IN_FILE -e ../ic_launcher-web.png -D -w 512 -h 512

# a shorthand function to export different sized images to different directories in the res/ folder
# the first argument is what size is desired
# the second what the target directory name in the res/ folder is
render() {
	SIZE=$1
	TYPE=$2
	inkscape -z -f $IN_FILE -e ${OUT_PATH}${TYPE}/${OUT_FILE} -D -w $SIZE -h $SIZE
}

render 72	hdpi
render 36	ldpi
render 48	mdpi
render 96	xhdpi

Want to be notified when I publish new content?

Just enter your name and email below. You will also get content that I share exclusively with the list, and zero spam!