Taking Screenshots of Websites with PHP

There are many command lines tools you can use to take a screenshots of a web page. See the list of tools here: in Windows, in Linux. The mentioned tools can be used on a from a php script using shell_exec function.

* If you are looking for taking screenshots programmatically in .NET – read the post Taking Screenshots of Websites with .NET Windows Forms.

The pseudo code might look as follows:

// The URL to get your HTML
$url = "http://www.google.com/";
// Name of your output image
$filename = "/path/to/myfile.jpg";
// Command to execute
$command = "/path/to/tool <<params_for_the_tool>> ";
// Generate the image
$output = shell_exec($command);
// check the file on disk
if (file_exists(filename)){
// do smth with the image file
}

 

Depending on the tool you should change this line with appropriate parameters:
$command = “/path/to/tool <<params_for_the_tool>> “;

 

An example of a PHP script to take screenshots of websites using wkhtmltoimage is shown here.


 

 

One thought on “Taking Screenshots of Websites with PHP”

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>