you could use a Java applet driven by a set of dynmically generated params or a flat file serverside... It exists and it works well (sometimes...).
If you want to do it 100% PHP, I know some people have developed this code but it's a DB IO vampire... will try to locate the link to source...
Good luck anyway