#!/bin/bash

set -e
set -u

tilesize=20

svgroot=source/svg
pngroot=data

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