if [[ -n "${1}" ]]; then
  timing=${1}
else
  timing=20
fi

i=10000
ls *.png |sort -n|while read line; do
  let i++
  mv "${line}" "${i}.foo"
done

i=0
ls *.foo |sort -n|while read line; do
  let i++
  if [[ -e "${i}.png" ]]; then
    echo "file exists... exiting to avoid breaking ${i}.png"
    exit
  fi
  mv "${line}" "${i}.png"
done

#thePath=$(pwd|sed 's@/home/dtorgo/.minecraft/resources/torgobooks/textures/@torgobooks:@')
thePath=$(pwd|awk -F '/textures/' '{print "torgobooks:"$2}')
theResource=$(ls *.png|sort -n|while read line; do
  echo "${line}"|sed 's/.png//'
done|awk -vtiming="${timing}" -vthePath="${thePath}" '{myvar=myvar","$0"_"timing}END{print myvar}'|sed 's@^,@'${thePath}'/@')

#mogrify -resize 210 *.png

echo '<image align="center" src="'"${theResource}"'" tw="50" th="50" scale="0.9"/>'
