PHP: How to capture browser window screen using php?

First of all, I'm not sure if it is possible to capture the browser window screen using php, then how to do it?

If possible, capturing the entire contents of the website, with the exception of parts of the browser, such as menus, toolbars, status bars, etc., is best.

thank

+6
browser php screenshot
Dec 23 '09 at 12:37
source share
5 answers

There is imagegrabscreen() and imagegrabwindow() , which allows you to programmatically create screenshots from a browser running on the same computer via COM (Win only). See the comments in the guide on how to lower the Chrome browser. Using DCOM , this will also work with remote Windows machines that have been configured to access through DCOM.

In the field for those who said that PHP does not know about the browser, I would suggest looking at get_browser() in the PHP manual. It is not much, but hey, it is nothing.

+9
Dec 23 '09 at 12:55
source share

This can absolutely be done, it just requires a little more than PHP to make this happen. I have an application written in PHP that takes snapshots of websites at regular intervals. This is a little tricky to do, but here are the steps I took on a Linux machine:

  • Install Xvfb (or vnc server) to emulate an X Windows session in memory. Run Xvfb on the display: 1
  • Install Firefox
  • Install imagemagick
  • Create a bash script to launch Firefox at the desired URL. My looked like this:

.

 #!/bin/bash DISPLAY=:1 firefox & sleep 2s DISPLAY=:1 firefox -kill-all & sleep 1s DISPLAY=:1 firefox -url $1 & sleep 5s DISPLAY=:1 import -window root /var/www/images/screenshots/$2.png 
  • Run the script from PHP:

.

 exec ('sh ../scripts/screencap.sh ' . $url . ' ' . $file_name); 

The hardest part for me was to get the browser to be in full screen when the screenshot took place. Since you cannot access the browser directly, you need to configure everything through the Firefox configuration files, which may take some time to understand.

Useful links to help you get started:

http://semicomplete.com/blog/geekery/xvfb-firefox.html http://www.webmasterworld.com/forum21/9182.htm

+6
Dec 23 '09 at 18:29
source share

PHP knows nothing about the browser. In fact, usually PHP ends before the browser receives the data.

If at all possible, it should be a client system such as Javascript. This can cross the DOM and thus capture the model that the browser considers it to be displayed; but I donโ€™t remember to see any tool for capturing real graphics. In any case, it is not clear what you could do with such information. Browsers do not allow Javascript to access local files. I suppose you could, in principle, send it back to the server on an Ajax call.

+2
Dec 23 '09 at 12:42
source share

In fact, it is not supported by the architecture of the Internet and not without reason. The server you are connecting to should not have more information about you than is necessary to process and respond to your request. The server MAY NOT be able to capture information about what you are viewing on the screen.

However, you can probably create something related to client-side technologies, such as ActiveX or Flash or Java, that will capture the screen and then send it back to the server at the request of AJAX, but you probably This should not be done. I canโ€™t imagine what use you would have for such a thing, besides, perhaps debugging problems with layouts.

+1
Dec 23 '09 at 15:52
source share

You cannot do this with PHP (server side).

But you can lay out and use one of the many HTML to PDF converters for image capture (and there are many tools for converting PDF code to another).

0
Dec 23 '09 at 18:13
source share



All Articles