在HTML中将HTML转换为图像 [英] Convert HTML to image in php
问题描述
我必须从PHP脚本创建PNG / JPEG图像。简要
I have to create a PNG / JPEG image from PHP script .. Briefly
代码将创建一个html表,并在该页面中包含一个图像。我需要将整个页面保存为图像,将该图像保存在我的服务器中并返回图像的路径(使用webservice)。
The code will create a html table and will include an image in that page. I need to save this entire page as an image , save that image in my server and return the path of the image ( using webservice ).
我可以从imagejpg创建图像功能很好。我的问题是如何将HTML转换为图像,因为通过Web服务进行处理,因此不能拍摄屏幕截图。
I can create image from imagejpg function pretty well . My problem is how to convert that HTML to image, Cant take a screen shot because the processes going on through web services .
请帮我用PHP将HTML转换为图像
Please help me to convert HTML to image using php
提前致谢
推荐答案
您可以从此链接。所有操作系统都有一个版本,因此不应该是一个问题。然后你可以像这样使用它:
You can download wkhtmltoimage from this link. There is a version for all operating systems so that shouldn't be a problem. Then you can use it like so:
$path="wkhtmltoimg/wkhtmltoimage.exe"; //path to your executable
$url="http://google.com";
$output_path="test.png";
shell_exec("$path $url $output_path");
你要注意的一件事是,如果PHP处于安全模式,shell_exec将不起作用,你将无法进行转换。
One thing you want to note is that if PHP is in safe mode, shell_exec will not work and you won't be able to do your conversion.
这篇关于在HTML中将HTML转换为图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!