php 如何使用php将html代码转换为png图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38875110/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 01:44:44 来源:igfitidea点击:
how to convert html code to png image using php
提问by mohamed
Is there a php script that allow to convert a html code to a png image. The problem with GD library is that only convert text to image( and not html code )
是否有允许将 html 代码转换为 png 图像的 php 脚本。GD 库的问题是只能将文本转换为图像(而不是 html 代码)
回答by Anticom
There is no pure PHP solution to this.
对此没有纯 PHP 解决方案。
Basically you've got two options:
基本上你有两个选择:
- Client-side rendering
Use something like html2canvasto render your image using javascript in the browser. - Server-side rendering
Use a library like wkhtmltopdfwhich can be invoked by PHP to generate the image.
Another server-side solution would be using Phantom.jswhich can also run javascript before capturing the screen.
- 客户端渲染
使用html2canvas 之类的东西在浏览器中使用 javascript 渲染图像。 - 服务端渲染
使用像wkhtmltopdf这样的库,PHP 可以调用它来生成图像。
另一个服务器端解决方案是使用Phantom.js,它也可以在捕获屏幕之前运行 javascript。