2017 © Pedro Peláez
 

library grabby

Creates an image of a web page using just it's URL.

image

edcs/grabby

Creates an image of a web page using just it's URL.

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

The README.md

Grabby

Codeship Status for edcs/grabby Total Downloads Latest Stable Version License Coverage Status SensioLabsInsight, (*1)

A PhantomJS adapter to generate screengrabs of webpages in PHP., (*2)

Installation

It is recommended that you install this library using Composer. Before installing Grabby, add the following to the scripts namespace in your composer.json file:, (*3)

    "scripts": {
        "post-install-cmd": [
            "PhantomInstaller\\Installer::installPhantomJS"
        ],
        "post-update-cmd": [
            "PhantomInstaller\\Installer::installPhantomJS"
        ]
    }

That takes care of installing the correct PhantomJS binary into your project directory. Next you need to run the following command to add Grabby to your project:, (*4)

$ composer require edcs/grabby

Dependencies

Grabby requires PHP version >=5.4.0 and symfony/process ^3.1. PhantomJS is also required; Grabby will download the correct binary for your system., (*5)

Getting Started

The following snippet will run grabby it's most basic form, this will generate a screengrab of Google's home page in a PNG called grabby.png at a resolution of 1920x1080px. The file will be stored in the same directory which the Grabby Factory class is located., (*6)

<?php

use Edcs\Grabby\Factory;

require 'vendor/autoload.php';

$grabby = new Factory('http://www.google.co.uk');

$grabby->grab();

Extra Parameters

You would probably like your screengrab to be stored in a different location and probably generated in a different size. You can pass Grabby some extra parameters to do this. The following example will generate a screengrab of Google's home page in a PNG called screenshot.jpg at a resolution of 150x200px. The file will be stored in /my/storage/dir/, an exception is thrown if this directory doesn't exist., (*7)

<?php

use Edcs\Grabby\Factory;

require 'vendor/autoload.php';

$grabby = new Factory('http://www.google.co.uk', 'screenshot.png', '/my/storage/dir/', [
    'viewportSize' => [
        'width' => 150,
        'height' => 200
    ]
]);

$grabby->grab();

Grabby also supports creating PDF versions of web pages in different paper sizes. You can use the same config as above to create PDF renderings using a viewport size, or, you can use the following paper size config:, (*8)

<?php

use Edcs\Grabby\Factory;

require 'vendor/autoload.php';

$grabby = new Factory('http://www.google.co.uk', 'screenshot.pdf', '/my/storage/dir/', [
    'paperSize' => [
        'format' => 'A4',
        'orientation' => 'portrait',
        'margin' => '1cm'
    ]
]);

$grabby->grab();

Since Grabby is built on top of PhantomJS, you have all of the Web Page Module configuration options at your disposal. If you required a complex configuration, you can build up an array using the module option as the array key and it's properties as the value. The following example would create a portrait A4 PDF with a 3cm margin containing an image of Google's homepage viewied through a 150px by 200px viewport using a header called X-Test with the value foo:, (*9)

<?php

use Edcs\Grabby\Factory;

require 'vendor/autoload.php';

$grabby = new Factory('http://www.google.co.uk', 'screenshot.pdf', '/my/storage/dir/', [
    'customHeaders' => [
        'X-Test' => 'foo'
    ],
    'viewportSize' => [
        'width' => 150,
        'height' => 200
    ],
    'paperSize' => [
        'format' => 'A4',
        'orientation' => 'portrait',
        'margin' => '3cm'
    ]
]);

$grabby->grab();

You can check out the Web Page Module documentation here: http://phantomjs.org/api/webpage/, (*10)

Other File Formats

You can generate screengrabs in png, jpg or pdf formats. Simply suffix the filename property with one of those extensions., (*11)

Accessing the Generated File

Once you have run grab() to generate your screengrab file, you can either access the generated filenames path like so:, (*12)

<?php

use Edcs\Grabby\Factory;

require 'vendor/autoload.php';

$grabby = new Factory('http://www.google.co.uk', 'screenshot.png', '/my/storage/dir/', 150, 200);

$file = $grabby->grab()->getScreengrabLocation(); // Returns /my/storage/dir/screenshot.png

Or you access the contents of the file like so:, (*13)

<?php

use Edcs\Grabby\Factory;

require 'vendor/autoload.php';

$grabby = new Factory('http://www.google.co.uk', 'screenshot.png', '/my/storage/dir/', 150, 200);

$fileContents = $grabby->grab()->getScreengrab(); // Returns the contents of /my/storage/dir/screenshot.png

Contributing

Please see CONTRIBUTING for details., (*14)

Security Vulnerabilities

If you discover a security vulnerability within this package, please send an e-mail to edcoleridgesmith@gmail.com. All security vulnerabilities will be promptly addressed., (*15)

The Versions

02/06 2017

dev-master

9999999-dev

Creates an image of a web page using just it's URL.

  Sources   Download

MIT

The Requires

 

The Development Requires

05/07 2016

v1.0.1

1.0.1.0

Creates an image of a web page using just it's URL.

  Sources   Download

MIT

The Requires

 

The Development Requires

30/06 2016

v1.0.0

1.0.0.0

Creates an image of a web page using just it's URL.

  Sources   Download

MIT

The Requires

 

The Development Requires

28/06 2016

v0.1.2

0.1.2.0

Creates an image of a web page using just it's URL.

  Sources   Download

MIT

The Requires

 

The Development Requires

28/06 2016

v0.1.1

0.1.1.0

Creates an image of a web page using just it's URL.

  Sources   Download

MIT

The Requires

 

The Development Requires

28/06 2016

v0.1.0

0.1.0.0

Creates an image of a web page using just it's URL.

  Sources   Download

MIT

The Requires

 

The Development Requires

28/06 2016

v0.0.1

0.0.1.0

Creates an image of a web page using just it's URL.

  Sources   Download

MIT

The Requires

 

The Development Requires