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:
[codesyntax lang=”php”]
// 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
}
[/codesyntax]
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”