使用PHP将Google图表图片保存到文件 [英] Saving Google Chart image to file using PHP
本文介绍了使用PHP将Google图表图片保存到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个脚本为客户生成Google图表图片。它在HTML中工作正常显示,但我现在需要保存每个图表在本地作为.png。
I have a script which generates Google Chart images for clients. It works fine displaying in HTML but I now need to save each chart locally as a .png.
如果我尝试:
$ imageData = file_get_contents($ url);
file_put_contents('C:/xampp/htdocs/image.png',$ imageData);
/ p>
then I always receive
[function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 400
脚本适用于正常图像,
The script works fine for normal images, but not Google charts. Same result if I use cURL to save the image too.
我的Google图表$ url的一个例子如下。我已经勾出冒号和管道符号,但它没有解决这个问题:
An example of my Google chart $url is below. I've hexed out the colons and pipe symbols but it did not fix the issue:
http://chart.apis.google.com/chart?cht=lc&chxt=x,y&chs=700x400&chco=76A4FB,FF9900&chg=0,8.3333333&chdl=Visits|Unique%20visits&chls=3|3&chma=40,20,20,30&chxr=1,0,33411&chds=0,33411&chd=t%3A33411,33411,33411,33411,33411,33411,33411,33411,33411,33411,33411,33411|33411,33411,33411,33411,33411,33411,33411,33411,33411,33411,33411,33411&chxl=0%3A|Jan-10|Feb-10|Mar-10|Apr-10|May-10|Jun-10|Jul-10|Aug-10|Sep-10|Oct-10|Nov-10|Dec-10
推荐答案
CURL示例:
<?php
$ch = curl_init("www.example.com/curl.php?option=test");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
echo $output; ?>
这篇关于使用PHP将Google图表图片保存到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文