How to save the image created by pChart to a file?

I am using the following:

$chartImage->autoOutput('/statistics/'.$image.'.png'); 

The problem is that this code displays the image in the browser. I would prefer it to save the image in a file with the name I specified. How can I do it? I looked at the pChart wiki and it really confused all these pCache stuff. I don't need caching or anything like that ... I just want to save the image.

+4
source share
3 answers

Try using:

 $chartImage->render("image_name.png"); 

He worked for me in 1.x, I do not know about 2.x - I did not use it.

+9
source

If there is no way, then do

 ob_start(); $chartImage->autoOutput('/statistics/'.$image.'.png'); $image = ob_get_contents(); ob_end_clean(); $file = fopen('<path_to_file>', 'wb'); fputs($file, $image); fclose($file); 
+1
source
 $imageOut = 'grafico'; $chart->drawFromJPG($width, $height, "{$imageOut}.jpg"); $chart->render("{$imageOut}.jpg"); 

I did it very well.

0
source

All Articles