tags:

views:

71

answers:

3

Hi,

I am looking for best solution to convert HTML to Image using PHP (on LINUX), please post your suggestions ....

+1  A: 

You need external tools, it's not possible in pure PHP I guess. e.G. http://cutycapt.sourceforge.net/

joni
this won't work on linux
stillstanding
"CutyCapt is a small cross-platform command-line utility to capture WebKit's rendering of..." -> On the webpage is stated that it's cross-plattform, and the fact that it uses QT4 and an X-Server makes me believe that it works on Linux very well, too. However, it might be that it's not tested on Windows and as only .exe binaries are provided, he's got to compile it on his own for Linux.
joni
A: 

Not an answer for you but might help others reading this: If you are on Windows PHP offers some built-in option to create Screenshots:

johannes
I am using LINUX and searching for command line tools ...
dev
+1  A: 

Firstly, can you explain what you're planning to use this for? My guess is maybe you want a thumbnail image of a web page to display as a link to that site? Something like that, right?

Anyway, you're definitely barking up the wrong tree if you expect PHP to be able to do this. HTML is just a big string of text until it is loaded into a web browser. It is the browser that renders it as a visible page, including loading additional graphics, etc.

Therefore, in order to convert HTML into an image, you would need to load it into a browser and save the rendered screen.

The question then is which browser? Most pages will display with slight differences between the various browsers, so which one do you want to use for your screenshot? Will you care if the screenshots aren't accurate for other browsers?

Of course if you use a traditional browser, you'll have the issue that you'll need to run a GUI desktop, load the page, and save the screenshot, and then your PHP app would have to load the screenshot and present it to the user. Quite a big effort.

There are command-line tools that allow you to automate a lot of this, but there will likely still be some issues to consider. For example, are you looking for a screenshot of whatever fits in the browser window, or the whole page no matter how long. And what about pages with frames or other scrollable or dynamic elements that aren't suited to display in a static image?

Spudley