views:

68

answers:

3

I want to change my HTML page as an image. Is there a way in PHP to change or save an HTML page as an image?

A: 

This is not easy; as NullUserException says in his comment, you would need to render the HTML page on the server-side, which is not something PHP (or any other server-sided language) has built in.

The approach that comes to mind would be to write a program (probably not in PHP, but rather something like C# or C++) that runs on your server, fires up a web browser, and does a series of screen captures (possibly combined with page scrolls). As this is a very nontrivial and bug-prone process, I would suggest looking into third-party components that are capable of doing this.

You would then execute this program from PHP, and when it's done running, display the results from the file it output.

Domenic
A: 

I would advise you to use an external service with an api. This list might be a good start: http://blogs.sitepoint.com/2008/07/10/9-ways-to-put-site-screenshots-in-your-web-app/

Thumbalizr seems great, they allso provide a php script so you can cache the images locally: http://www.thumbalizr.com/apitools.php

zilverdistel
A: 

Try taking a look at browsershots.org - source code is available for it if you want to install it locally. Essentially it uses a browser to take screenshots, and can be controlled via an XML-RPC interface, which you can call from PHP.

As others have said this is not a simple job, and not something you can do directly in PHP, so use an external service.

(I'm not affiliated with browsershots.org in any way)

Peter Bagnall