2017 © Pedro Peláez
 

library php-screenshot

PHP Screenshot Utilities

image

hugsbrugs/php-screenshot

PHP Screenshot Utilities

  • Friday, June 2, 2017
  • by hugsbrugs
  • Repository
  • 1 Watchers
  • 0 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

php-screenshot

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)

Build Status Coverage Status, (*2)

Notes

Currently 3 providers are available : Manet Apercite PagePeeker, (*3)

You're welcome to suggest others providers., (*4)

Install

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 two constants, (*7)

define('HUG_SCREENSHOT_SAVE_PATH', '/path/to/screenshots/');
define('HUG_SCREENSHOT_PROVIDERS', '/path/to/providers.json');

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)

Usage

$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)

Unit Tests

composer exec phpunit

Author

Hugo Maugey visit my website ;), (*13)

The Versions

02/06 2017