Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I save an image created by pChart to a file?

Tags:

php

pchart

I am using the following:

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

The problem is that this code outputs the image to the browser. I would prefer it if it saved the image to a file with the directory and name I specified. How do I do this? I was looking at the pChart wiki, and its very confusing with all this pCache stuff. I don't have a need for any caching or anything like that... I just want to save the image.

like image 635
Jason Axelrod Avatar asked Dec 21 '22 11:12

Jason Axelrod


2 Answers

Try to use:

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

It worked for me in 1.x, don't know about 2.x - did not used it.

like image 98
rMX Avatar answered Dec 24 '22 01:12

rMX


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);
like image 37
rabudde Avatar answered Dec 23 '22 23:12

rabudde