Search code examples
phphtmlwebscreenshot

how to take a screenshot of a loaded webpage using php?


I need to take screenshots of few web pages and save them in a folder using php.

I want to do this using a php script, is there a way I can render those webpages and take screenshot of a particular area after the website is fully loadedd? - I'm using windows.

I tried using wkhtmltoimage but it takes low quality screenshots and also it takes the screenshot before the whole page is loaded, so some images of the webpage are not appearing in the screenshot, is there a way to do this using php?

Please help php specialists. Thank you


Solution

  • PHP runs on server side, so to be able to take screenshots you need something to render HTML (a browser-like script) and generate a image of it. This script will do that (wkhtmltoimage too):

    HTML2PS: http://freecode.com/projects/html2ps_php

    But I still think the best solution will be using javascript. Of course, only the client will have access to the screenshots, and maybe you can upload the image to the server. A client browser is better than any kind of server script.

    If that is the case, I would suggest using HTML2CANVAS:

    HTML2CANVAS: http://html2canvas.hertzen.com/

    The best server solution will be a linux distribution with a google chrome installation and a local script to take screenshots. That is the only way to get accurate screenshots of a web page that may contain javacript/HTML5/animations and other difficult to render stuff.