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

若如初见. 提交于 2019-12-10 16:14:33

问题


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.


回答1:


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.




回答2:


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);



回答3:


$imageOut = 'grafico';
$chart->drawFromJPG($width, $height, "{$imageOut}.jpg");
$chart->render("{$imageOut}.jpg");

I got this working very well.



来源:https://stackoverflow.com/questions/6785952/how-do-i-save-an-image-created-by-pchart-to-a-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!