0

Possible Duplicate:
Website screenshots using PHP

I cannot seem to find a simple example of how to render a webpage to an image via a web server.

Right now I have a backend running Nginx and serving a PHP app, I also have a reverse Proxy serving Node on the same backend.

What I need to achieve is an API to which I can hand a URL and have it rendered as a PNG then stock somewhere on the hard drive. (If this whole process could be asynchronous that would be perfect.)

What would be the best approach to achieve this?

Community
  • 1
  • 1
silkAdmin
  • 4,640
  • 10
  • 52
  • 83
  • 1
    As `phantomjs` tag hints, write simple util in [PhantomJS](http://phantomjs.org/) (or [CasperJS](http://casperjs.org/)) that opens passed URL and captures it to png or something. Then [`exec`](http://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback) child process. Relevant examples: [1](https://github.com/ariya/phantomjs/blob/master/examples/arguments.js) and [2](https://github.com/ariya/phantomjs/blob/master/examples/technews.js). – Aleksei Zabrodskii Oct 18 '12 at 21:41

1 Answers1

0

You will need a renderer, which I don't think is available in a simple PHP library. You could use the engine of Google Chrome, which is open source and has a reasonably usable API to embed it in other applications. I'm not sure how, but you should be able to make it render to an image, or to a canvas from which you can save it yourself.

Not an easy solution, though. Rendering a website is immensely complex.

GolezTrol
  • 114,394
  • 18
  • 182
  • 210