vsupalov

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
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

Join the mailing list!


Subscribe to get notified about future articles and stay in touch via email.

I write about Kubernetes, Docker, automation- and deployment topics, but would also like to keep you up to date about news around the business-side of things.

Privacy and your data: You can get more information about the usage of your data, the storage of your registration, sending out mails with the US-provider ConvertKit, statistical analysis of emails sent and your possibility to unsubscribe in my Privacy Policy.

I use the US-provider ConvertKit for email automation. By clicking to submit this form, you acknowledge that the information you provide will be transferred to ConvertKit for processing in accordance with their Privacy Policy and Terms.

We won't send you spam. Unsubscribe at any time. Powered by ConvertKit