xvfbを使わず、簡単にWEB画面をキャプチャしたいというときに便利なのが、
 phantomJSです。以下のようなコードで簡単に 画面キャプチャを実現できます。
 ※ただ、お手軽なだけあって、WEBサイトによっては うまく取得できないこともあります。
phantomJSをcomposerでインストールすることを想定してます。
composer.jsonの生成
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | {     "scripts": {         "post-install-cmd": [             "PhantomInstaller\\Installer::installPhantomJS"         ],         "post-update-cmd":[             "PhantomInstaller\\Installer::installPhantomJS"         ]     },     "config": {         "bin-dir": "bin"     },     "require": {         "jonnyw/php-phantomjs": "4.*"     } } | 
◆composerのインストール
| 1 2 | //composerが入っていない場合 curl -sS https://getcomposer.org/installer | php | 
◆composerパッケージインストール
| 1 | php composer.phar install | 
サンプルプログラム(screenshot.php)
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | <?php require_once('vendor/autoload.php'); use JonnyW\PhantomJs\Client; $client = Client::getInstance(); if(!isset($argv[1])){   die('urlを指定してください'); } $url = $argv[1]; $request = $client->getMessageFactory()->createCaptureRequest($url); $response = $client->getMessageFactory()->createResponse(); //サイズ指定 $width  = 1000; $height = 800; $request->setViewportSize($width, $height); //画面の一部 $dimen_width  = 800; $dimme_height = 500; $top  = 0; $left = 0; $request->setCaptureDimensions($dimen_width, $dimme_height, $top, $left); // 保存先ファイル $file = strtr($url,array('/'=>'_',':'=>'_','.'=>'_','?'=>'_','&'=>'_','='=>'_')) .'.jpg'; $request->setOutputFile($file); $client->send($request, $response); ?> | 
◆以下のような形でコマンドを投げると 簡単にWEBサイトのキャプチャができます。
| 1 | php screenshot.php https:/dbit.jp/ | 
◆画面を縮小
画面を縮小したい場合は、ImageMagickを使って縮小するのが簡単です。
| 1 | mogrify -resize 160x100 -quality 100 ファイル名 | 
以上でした。