views:

36

answers:

2

Hi. 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  A: 

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.

Samuel
Yeah. It seems impossible to do. When I was searching on google, that method of using the browser on the server was always appearing on the results. I might as well try that. Thanks!
saulkyut
A: 

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.

Dan F.
I think there's no easy way to do it. Thanks for the tip!
saulkyut