Is there a way to output html div to an image using php?

自古美人都是妖i 提交于 2019-12-08 12:35:37

问题


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!


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/3953662/is-there-a-way-to-output-html-div-to-an-image-using-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!