Hi,
I am looking for best solution to convert HTML to Image using PHP (on LINUX), please post your suggestions ....
Hi,
I am looking for best solution to convert HTML to Image using PHP (on LINUX), please post your suggestions ....
You need external tools, it's not possible in pure PHP I guess. e.G. http://cutycapt.sourceforge.net/
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:
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?