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

34,745

Solution 1

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.

Solution 2

JavaScript / HTML5 / Canvas

It could be hard to code it only in PHP. In your case I think I would follow those instructions:

Using HTML5/Canvas/JavaScript to take screenshots

PHP

Or if you really want use only PHP, it should help you:

Website screenshots using PHP

Share:
34,745
new_one
Author by

new_one

Updated on July 21, 2022

Comments

  • new_one
    new_one almost 2 years

    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