#!/bin/bash

# calls phantomjs to make screenshots 
# of each anchor in PROJECT then calls
# imagemagick to resize them for preview
# panel. The size of the screenshot 
# is defined in rasterize.js

# nodescore@kiben.net
# nodescore.kiben.net

SERVER=$2
BASEDIR='m'
PROJECT=$1
THUMBPATH=www/$BASEDIR/$PROJECT/img/thumbs

if [ ! -d $THUMBPATH ];
    echo creating $THUMBPATH
    then mkdir -p $THUMBPATH;
fi

ANCHORS=`grep '<a' www/$BASEDIR/$PROJECT/music.html|wc -l`

for each in $(seq 1 $ANCHORS);

do
    echo phantomjs rasterize.js $SERVER/$BASEDIR/$PROJECT/music.html#$each $each.png

    phantomjs rasterize.js $SERVER/$BASEDIR/$PROJECT/music.html#$each $each.png
    mogrify -scale 30% $each.png
    mv $each.png www/$BASEDIR/$PROJECT/img/thumbs/

done