douyi1779 2017-08-19 23:25
浏览 304

如何将HTML转换为base64并使用php在服务器上保存图像?

I have a json file like this:

{"user":{"email":"user@test.com"},
 "screenshot":{"blobFile":"<!DOCTYPE html><html lang=\"en\">...</html>"}}

and I want to take a screenshot, using XMLHttpRequest sending data a PHP file.

In PHP file getting request like:

$data = json_decode(file_get_contents("php://input"), true);
$htmlStr = json_encode($data["screenshot"]["blobFile"]); // <!DOCTYPE html><html lang=\"en\">...

so far everything is ok but how to convert this string to the image file and save a server?

I've tried html2canvas in PHP file but not fire.

any ideas?

  • 写回答

1条回答 默认 最新

  • duanlinghe8417 2017-08-20 03:38
    关注

    I'd try to use PhantomJS. It's headless browser, which allows to interact with web pages many ways including making screenshots. It will require some time to understand how to work with it, but it definitely will get a result. Although, PhantomJS sometimes is a headache if your page is quite complicated structured, written using some frameworks like ReactJS, AngularJS, etc.

    What it does it renders HTML page with styles including scripts serverside. If you save not HTML string but exact URL with COOKIE and SESSION data and then reconstruct conditions which user had in an opened page when you did a screenshot, it'll do a job.

    See example here Screen Capture on PhantomJS

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器