jueves, diciembre 04, 2008

Resize Tango icons SVG to PNG with ImageMagick

Convert all images in Tango project with ImageMagickEnlace
For example, if I wanted to resize the .svg icons to png 40x40 size:

$ for i in `find -name *.svg`; do ./svg2png.sh '-density 60 -background transparent' 40x40 $i; done;

I have changed the content of svg2png.sh to:

#!/bin/sh

SVGCONVERT="convert"

ICONTEST=`echo ${3} | grep "icon$"`
if [ ! -z "${ICONTEST}" ]; then
exit 0
fi

ICONFILE=`basename ${3}`
ICONNAME=`echo ${ICONFILE} | sed -e "s/.svg//"`
DIRNAME=`dirname ${3}`
DIRNAME=${DIRNAME#*/scalable/}
if test `basename $SVGCONVERT` = "rsvg"; then
OPTIONS="-w ${1} -h ${1}"
else
OPTIONS="${1}"
fi

OUTDIR=${2}/${DIRNAME}
mkdir -p ${OUTDIR}

echo "${SVGCONVERT} ${OPTIONS} ${3} ${2}/${ICONNAME}.png"
${SVGCONVERT} ${OPTIONS} ${3} ${OUTDIR}/${ICONNAME}.png


If you want to change to .gif or .bmp files you should change the options in the convert call and the file extensions in the end of svn2png.sh.