Exporting an inkscape logo in many resolutions via script

January 10, 2012

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
# this assumes, that there is an asset directory in the project root
# the standard icon name

# -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() {
	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?

Enter your email below to join my mailing list!