Website Screenshots with Laravel
Created on August 9th, 2015
Below is the code used in the routes.php:
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
use JonnyW\PhantomJs\Client;
Route::get('/', function () {
$url = Input::get('url');
$client = Client::getInstance();
$client->setBinDir('../bin');
$request = $client->getMessageFactory()->createCaptureRequest($url);
$response = $client->getMessageFactory()->createResponse();
$file = '../bin/file.jpg';
$request->setCaptureFile($file);
$client->send($request, $response);
rename('../bin/file.jpg', 'screenshots/file.jpg');
echo '<img src="screenshots/file.jpg" />';
});
You can also download the files from the Github repository here: https://github.com/thedevdojo/website-screenshot-with-laravel
Comments (0)