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

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);
  $img_data = ob_get_contents();

  echo '<img width="'.$width.'" height="'.$height.'" src="data:image/png;base64,'.base64_encode($img_data).'"/>';