Vish
Vish

Reputation: 4492

Generating Website screenshots on CentOS using PHP

Are there any free utilities that can be used to take screenshots of webpages and websites on centos and that can be run through php.

Thanks

Upvotes: 1

Views: 2486

Answers (2)

mario
mario

Reputation: 145482

There are various commandline utilities available. Most start one of the browser engines in headless X11 and take a screenshot then. A particular common one is khtml2png which can be used from php like this (not sure if there is a precompiled version for CentOS):

exec("khtml2png --width 800 --height 600 http://google.com/ img.png");

A few more are listed here: Command line program to create website screenshots (on Linux)

Upvotes: 7

PiZzL3
PiZzL3

Reputation: 2210

I don't think that's possible because PHP doesn't render websites like a browser does.

EDIT: However, you could save each page's raw unrendered HTML using a PHP cURL script.

eg:

$websites[] = 'http://google.com'; 
$websites[] = 'http://stackoverflow.com';
$websites[] = 'http://msn.com'; 
$websites[] = 'http://microsoft.com';

foreach ($websites as $site)
{
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $site);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $data = curl_exec($curl);
    curl_close($curl);

    if(!empty($data)) 
    {
        savePageToFile($data); //placeholder, not real function
    }
}

Upvotes: 0

Related Questions