duanmengsuo9302 2019-03-14 19:35
浏览 62

使用cronjob和管道输出评估PHP到PNG文件

I have a PHP file which renders a PNG image (see online, based on Google Charts example). I want to "execute" this file using cronjob, and use it to generate PNG image on my server every day.

Is this possible? I can run PHP/Bash using cronjob. I tried running PHP script which executed the HTML using PHP's eval(), but how would I pipe the output to PNG file?

google.charts.load("current", {
  packages: ['corechart']
});
google.charts.setOnLoadCallback(drawChart);

function drawChart() {

  var data = google.visualization.arrayToDataTable([
    ['Element', 'Density', {
      role: 'style'
    }],
    ['Copper', 8.94, '#b87333', ],
    ['Silver', 10.49, 'silver'],
    ['Gold', 19.30, 'gold'],
    ['Platinum', 21.45, 'color: #e5e4e2']
  ]);

  var options = {
    title: "Density of Precious Metals, in g/cm^3",
    bar: {
      groupWidth: '95%'
    },
    legend: 'none',
  };

  var chart_div = document.getElementById('chart_div');
  var chart = new google.visualization.ColumnChart(chart_div);

  // Wait for the chart to finish drawing before calling the getImageURI() method.
  google.visualization.events.addListener(chart, 'ready', function() {
    chart_div.innerHTML = '<img src="' + chart.getImageURI() + '">';
    console.log(chart_div.innerHTML);
  });

  chart.draw(data, options);

}
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<div id='chart_div'></div>

</div>
  • 写回答

1条回答 默认 最新

  • duanchifo2866 2019-03-14 21:01
    关注

    I would prefer to use other PHP libs to do that.

    It's weird idea but... you can use

    firefox -headless http://localhost/script.html
    

    and pass chart.getImageURI() to PHP script through ajax, decode it and save. Then run shell_exec to kill all firefox process(I guess u will need to use sudo).

    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)