Example #1
0
$color = isset($_SESSION['color']) ? $_SESSION['color'] : 0;
$triangles = isset($_SESSION['triangles']) ? $_SESSION['triangles'] : FALSE;
$antialias = isset($_SESSION['antialias']) ? $_SESSION['antialias'] : 0;
$autosub = isset($_SESSION['autosub']) ? $_SESSION['autosub'] : 0;
$font = isset($_SESSION['font']) ? $_SESSION['font'] : 'Vera.ttf';
$fontsize = isset($_SESSION['fontsize']) ? $_SESSION['fontsize'] : 8;
// Validate the phrase and draw the tree
$sp = new CStringParser($data);
if (!$sp->Validate()) {
    // Display an error if the phrase doesn't validate.
    //   Right now that only means the brackets didn't
    //   match up. More tests could be added in the future.
    // It would also be a good idea to make this error
    //   image creation a standalone class or something.
    $im = imagecreate(350, 20);
    $col_bg = imagecolorallocate($im, 255, 255, 255);
    $col_fg = imagecolorallocate($im, 255, 0, 0);
    imagestring($im, 3, 5, 3, "Sentence brackets don't match up...", $col_fg);
    imagepng($im);
} else {
    // If all is well, go ahead and draw the graph ...
    $sp->Parse();
    if ($autosub) {
        $sp->AutoSubscript();
    }
    $elist = $sp->GetElementList();
    // Draw the graph
    $fontpath = dirname($_SERVER['SCRIPT_FILENAME']) . '/ttf/';
    $graph = new CTreegraph($elist, $color, $antialias, $triangles, $fontpath . $font, $fontsize);
    $graph->Draw();
}
Example #2
0
$data = $_SESSION['data'];
$color = isset($_SESSION['color']) ? $_SESSION['color'] : 0;
$triangles = isset($_SESSION['triangles']) ? $_SESSION['triangles'] : FALSE;
$antialias = isset($_SESSION['antialias']) ? $_SESSION['antialias'] : 0;
$autosub = isset($_SESSION['autosub']) ? $_SESSION['autosub'] : 0;
$font = isset($_SESSION['font']) ? $_SESSION['font'] : 'Vera.ttf';
$fontsize = isset($_SESSION['fontsize']) ? $_SESSION['fontsize'] : 8;
// Validate the phrase and draw the tree
$sp = new CStringParser($data);
if ($sp->Validate()) {
    // If all is well, go ahead and draw the graph ...
    $sp->Parse();
    if ($autosub) {
        $sp->AutoSubscript();
    }
    $elist = $sp->GetElementList();
    // Draw the graph into a file
    $tmpfile = tempnam('var/', 'stgraph');
    $fontpath = dirname($_SERVER['SCRIPT_FILENAME']) . '/ttf/';
    $graph = new CTreegraph($elist, $color, $antialias, $triangles, $fontpath . $font, $fontsize);
    $graph->Save($tmpfile);
    $size = filesize($tmpfile);
    header("Content-Type: application/octet-stream");
    // header( "Content-Type: image/png" );
    header("Content-Disposition: attachment; filename=syntax_tree.png");
    header(sprintf("Content-Length: %ld", $size));
    readfile($tmpfile);
    unlink($tmpfile);
} else {
    printf("Error: Phrase could not be parsed correctly.");
}