Quantcast
Channel: Gubatron.com
Viewing all articles
Browse latest Browse all 174

[CODE/PHP] JpGraph: How to output your graph as a base64 encoded image

$
0
0

Some times you just want to output the image created by your $graph object without having to create a separate .php script that would need to receive a bunch of parameters.

Here’s a function you can pass your $graph object right before the $graph->Stroke(); call

function graphInSrc($graph, $width, $height) {
$img = $graph->Stroke(_IMG_HANDLER);
ob_start();
imagepng($img);
$img_data = ob_get_contents();
ob_end_clean();
echo '<img width="'.$width.'" height="'.$height.'" src="data:image/png;base64,';
echo base64_encode($img_data);
echo '"/>';
}


Viewing all articles
Browse latest Browse all 174

Trending Articles