phantomJS and Google Chart getImageURI() -
i image/png;base64 (server side) of google chart phantomjs
$base64 = exec('phantomjs myscript.js'); header("content-type: image/png"); echo base64_decode( $base64 );
myscript.js :
page.onconsolemessage = function(msg, linenum, sourceid) { console.log( msg ); phantom.exit(); }; page.open('http://getpngchart.dev/chart.php');
chart.php:
<html> <head> <script type="text/javascript" src="https://www.google.com/jsapi"></script> <script type="text/javascript"> google.load("visualization", '1', {packages:['corechart']}); google.setonloadcallback(drawchart); function drawchart() { var data = google.visualization.arraytodatatable( [['task', 'quantity'], ['critical', 35], ['routine', 6], ['adjust', 2]] ); var options = {colors: ['#e34036','#f7a500','#ff0097'], legend: { position: "none" }}; var chart = new google.visualization.piechart( document.getelementbyid('chart_div') ); google.visualization.events.addlistener(chart, 'ready', function () { console.log( chart.getimageuri() ); }); chart.draw(data, options); } </script> </head> <body> <div id="chart_div" style="width:250px; height:250px;"></div> </body> </html>
when launch chart.php chrome expected base64 string
data:image/png;base64,ivborw0kggoaaaansuheugaaapoaaad6cayaaaci7fo9aaagaeleqvr4xu2dcxwurfbhx889kzshcshgkub6gip4ligicrgicyogycequq7ihbgercvokvtfr9vvbeq...ainze1kbbp19gbwqqaegxqijcxnzaqadfyavkeabbl0ci3mtwqegnx2afzbaaqzdainze1mb/wedej8spznwdqaaaabjru5erkjggg==
but when use terminal (#phantomjs myscript.js), wrong base64 lot of aaaa... :
data:image/png;base64,ivborw0kggoaaaansuheugaaaewaaahkcayaaad8erwnaaaabhncsvqicagifahkiaaaaalwsflzaaalewaacxmbajqcgaaaiabjrefueaeawyi+fqh/////aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
my goal same base64 chrome , phantomjs
this script works fine. small tweak on datastream needed @line2
$base64 = str_replace(' ','+',$base64); //remove identifier string begining of data. $base64 = str_replace('data:image/png;base64,', '', $base64);
Comments
Post a Comment