dev-master
9999999-devPHP Screenshot Utilities
The Requires
The Development Requires
by Hugo Maugey
Wallogit.com
2017 © Pedro Peláez
PHP Screenshot Utilities
This librairy provides utilities function to ease screenshot generation with different providers in order to always get a fallback in case first provider fails to generate screenshot., (*1)
Currently 3 providers are available : Manet Apercite PagePeeker, (*3)
You're welcome to suggest others providers., (*4)
Install package with composer, (*5)
composer require hugsbrugs/php-screenshot
In your PHP code, load library, (*6)
require_once __DIR__ . '/../vendor/autoload.php'; use Hug\Screenshot\Screenshot as Screenshot;
You first have to define 3 constants, (*7)
define('HUG_SCREENSHOT_SAVE_PATH', '/path/to/screenshots/');
define('HUG_SCREENSHOT_PROVIDERS', '/path/to/providers.json');
define('HUG_SCREENSHOT_CACHE', 'P1W');
HUG_SCREENSHOT_SAVE_PATH should be writable by webserver user, (*8)
HUG_SCREENSHOT_PROVIDERS is a json file like following, (*9)
{
"1": {
"provider":"Manet",
"basic_auth_user":"USERNAME",
"basic_auth_pass":"PASSWORD",
"scheme":"http OR https",
"host":"HOSTNAME_OR_IP",
"port":"PORT",
"params":{
"engine":"slimerjs|phantomjs",
"format":"jpg|png|gif",
"width":"1024",
"delay":"3000",
"quality":"0.9"
}
},
"2":{
"provider":"Apercite"
},
"3":{
"provider":"PagePeeker",
"code":"YOUR_CODE",
"entrypoint":"free",
"size":"x",
"refresh":"",
"wait":""
}
}
Please referer to each provider documentation for option details., (*10)
$Screenshot = new Screenshot(); $url = 'https://hugo.maugey.fr'; $widths = ['1024', '768', '480']; $screenshot = $Screenshot->shot($url, $widths); error_log(print_r($screenshot, true));
with outputs, (*11)
[status] => success
[message] =>
[images] => Array
(
[1024] => hugo.maugey.fr-1024xauto-1492020456.jpg
[768] => hugo.maugey.fr-768xauto-1492020467.jpg
[480] => hugo.maugey.fr-480xauto-1492020475.jpg
)
[details] => Array
Screenshot filenames are generated with following conventions : - URL - width x height - timestamp, (*12)
phpunit --bootstrap vendor/autoload.php tests
Hugo Maugey visit my website ;), (*13)
PHP Screenshot Utilities