<?php
if (isset($_GET['data'])) {

header("Content-type:image/png");

$descriptorspec = array(
0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
2 => array("pipe", "w")   // stderr is a file to write to
);

$data = addslashes(strip_tags($_GET['data']));

$input = "245 140 moveto ($data) () qrcode\n0 -10 rmoveto (QR Code) show\nshowpage";

$proc = proc_open ( "cat ./barcode.ps - | convert - -trim PNG:-", $descriptorspec, $pipes );
fwrite($pipes[0],$input);
fclose($pipes[0]);
while (!feof($pipes[1])) {
        echo fread($pipes[1],10);
}
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($proc);
}
else {
?>
<html>
<head></head>
<body>
<form target="barcode_frame" enctype="multipart/form-data" action="barcode.php" method="get">
<table>
<tr><td>
<textarea cols="30" rows="5" name="data">
Matt Oates
07123456789
matt@someplace.com
http://www.someplace.com
</textarea>
</td><td>
<iframe name="barcode_frame" id="barcode_frame" style="border:0px;width:100px;height:100px;padding:0px;margin-top:1em;"></iframe>
</td></tr>
<tr colspan="2"><td><input type="submit" name="generate" value="Generate"/></td></tr>
</table>
</form>
</body>
</html>
<?php } ?>