有没有办法使用 php 将 html div 输出到图像?

发布于 2024-09-28 00:45:45 字数 191 浏览 1 评论 0原文

我的页面上有一个 div,我想将其输出到 jpeg 文件。使用 PHP 可以吗?

我知道有用于在 PHP 中创建图像的 GD 库,但我不确定它是否可以实现我想要的功能。因为我还想在图像上放置条形码(我使用 jQuery 插件在 html 页面上执行此操作)。

这是否可能(如果可能,您能给我一个如何实现它的想法)还是有更好的方法?谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

嘿看小鸭子会跑 2024-10-05 00:45:45

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

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

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.

心头的小情儿 2024-10-05 00:45:45

它不能按照你想要的方式完成。相反,您可以根据您拥有的数据绘制图像。

你说它是条形码......所以我猜将是好的开始。

It can't be done the way you want it. Instead you can draw the image based on the data you have.

You say it's bar code... so I guess this would be a good start.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文