有没有一种方法来输出HTML格式的图像使用PHP? [英] Is there a way to output html div to an image using php?

查看:160
本文介绍了有没有一种方法来输出HTML格式的图像使用PHP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的页面上有一个div,我想输出到一个jpeg文件。这可能使用PHP?

我知道有用于在PHP中创建图像的GD库,但我不确定它是否可以做到我想要的。因为我也想在图片上添加一个条形码(我使用了一个jQuery插件在html页面上执行此操作)。



这是可能的吗(如果可以的话可以给我一个想法如何实现)还是有更好的方法呢?谢谢!

解决方案

据我所知,GD所不支持的功能。你可能想要搜索一个能做到这一点的库。问题是浏览器呈现HTML和CSS,但GD需要知道如何解析和呈现HTML和CSS(以及Javascript)才能将HTML转换为图像。这可能是一个更好的主意,取决于你真正想做什么,在GD中创建一个图像并将其粘贴到HTML DIV中,然后你就不必进行任何转换。



如果有一种方法可以将HTML的一部分导出到浏览器中的图像中,那么您可以使用PHP来控制服务器端浏览器并以此方式导出。这将是更多的工作,但它绝对有可能。


I have a div on my page which I want to output to a jpeg file. Is this possible using PHP?

I know there's the GD library for creating images in PHP but I'm not sure if it can do what I want. Because I also want to put a barcode on the image (I used a jQuery plugin to do this on the html page) .

Is this possible (if it's possible can you give me an idea how to implement it) or is there a better approach to this? Thanks!

解决方案

As far as I know the functionality you want is not supported by GD. You might want to search for a library that does that. The problem is that the browser renders the HTML and CSS, but GD would need to know how to parse and render HTML and CSS (and Javascript) in order to turn HTML into an image. It might be a better idea, depending on what you really want to do, to create an image in GD and stick it in the HTML DIV, and then you won't have to do any conversion.

If there is a way to export a section of HTML to an image in a browser, then you could use PHP to control a server-side browser and export it that way. It would be a lot more work, but it's definitely possible.

这篇关于有没有一种方法来输出HTML格式的图像使用PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆