#!/usr/local/plan9/bin/rc fn txt_header { echo 'Content-type: text/plain' echo } fn png_header { echo 'Content-type: image/png' echo 'Content-Disposition: attachment; filename="pic.png"' echo } header = '.PS ' footer = '.PE ' switch ($REQUEST_METHOD) { case GET ./parse > /tmp/$pid.in sum = `{md5sum /tmp/$pid.in | sed -e 's/ .*//'} if (test -f /tmp/$sum.png) { rm /tmp/$pid.in png_header cat /tmp/$sum.png } if not { mv /tmp/$pid.in /tmp/$sum.in echo $"header > /tmp/a cat /tmp/$sum.in >> /tmp/a echo $"footer >> /tmp/a err = `{./tpdf /tmp/a /tmp/$sum.pdf >[2=1]} if (test -n $"err) { txt_header echo $"err exit } pdftoppm -freetype yes -aa yes -f 1 -l 1 -r 300 -png \ -singlefile /tmp/$sum.pdf | \ png -9t | \ crop -c 255 255 255 -i -10 -b 255 255 255 | \ topng > /tmp/$sum.png rm /tmp/$sum.out-1.png png_header cat /tmp/$sum.png } case * txt_header echo Make a GET request. }