Page 1 of 1

Own 1.0.x component with jpgraph outputs PNG image as text?

Posted: Mon Feb 11, 2008 9:08 am
by pe7er
I am writing some own component (for 1.0.x) that uses JPGraph to draw images/charts.
If I use the JPGraph classes/methods in a standalone .php file, the output is correct.

However, if I use the same code in my component, at the place of $graph->Stroke(); I get the following error:
The image “[some URL]” cannot be displayed, because it contains errors.
and in the html source code shows (besides the regular html output):
‰PNG

���
IHDR��Â��Â���óz^�� �IDATxœì½m¬¥gu|?ûœùöÌxðØ31ãOlÇÁÆ0~IÛ¡©¢¤„¤)Uª¸Pµ¢”¨UZ寖ÚTUÓäG“V‘ˆ"EU"UÅrCÄ7¨Ôƒ&؃mlìñöÌìçý±=ë\Ïu­µž{Ì×>Ïúq´
÷ý¬{­k]÷ú¸÷9gÎ4e

Re: Own 1.0.x component with jpgraph outputs PNG image as text?

Posted: Mon Feb 11, 2008 1:36 pm
by pe7er
I tried to use buffered output:

ob_end_clean();
ob_start();
header("Content-Type: image/png");

-> jpgraph instructions, including
    $graph->Stroke();

ob_flush();
flush();
ob_end_clean();


This way the image is shown!
But now the text output from the component is not shown.....

Re: Own 1.0.x component with jpgraph outputs PNG image as text?

Posted: Thu Feb 14, 2008 10:05 am
by pe7er
Thanks to Adam (aka Websmurf) I was able to solve this problem:

You'll have to create a seperate function for it and reference to is with &no_html=1
At the position where you want to have the image, you'll have to put:
<img src="index2.php?option=com_componentname&task=yourspecialfunction&no_html=1" />
In the code of the php part of the component you'll have to add:

Code: Select all

switch ($task){
  case: 'yourspecialfunction':
    generateGraph();
    break;
}
And then put

Code: Select all

function generateGraph(){
  //everything commands that you want to use with jpgraph
  $graph->Stroke();
  exit;
}