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.
If I try:
$imageData = file_get_contents($url);
file_put_contents('C:/xampp/htdocs/image.png',$imageData);
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.
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