#!/bin/bash

set -e
set -u

tilesize=20

svgroot=source/svg
pngroot=data

for x in `find $svgroot -name "*.svg"`
do
    sourcefile=`basename $x`
    sourcedir=`dirname $x`
    destpath=${sourcedir/#$svgroot/$pngroot}/${sourcefile/%svg/png}
    rsvg-convert $x -w $tilesize -h $tilesize -o $destpath
    pngcrush -q $destpath tmp && mv tmp $destpath
done
