joshualambert / screen

Web site screenshot tool based on PHP and PhantomJS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

#Screen

Web site screenshot tool based on PHP and PhantomJS You can use it to take screenshots for testing or monitoring service

Install

Via Composer

$ composer require microweber/screen

If on any unix system, you need to make the bin executable chmod +x /path/to/screen/bin/phantomjs

The directory /path/to/screen/jobs must be writeble as well.

##Linux requirements

  • FontConfig - apt-get/yum install fontconfig
  • FreeType - apt-get/yum install freetype*

##Usage

With this library you can make use of PhantomJs to screenshot a website.

Check our demo or read the following instructions.

Creating the object, you can either pass the url on the constructer or set it later on

use Screen\Capture;

$url = 'https://github.com';

$screenCapture = new Capture($url);
// or
$screenCapture = new Capture();
$screenCapture->setUrl($url);

You can also set the browser dimensions

$screenCapture->setWidth(1200);
$screenCapture->setHeight(800);

This will output all the page including the content rendered beyond the setted dimensions (e.g.: all the scrollable content), if you want just the content inside those boudaries you need to clip the result

// You also need to set the width and height.
$screenCapture->setClipWidth(1200);
$screenCapture->setClipHeight(800);

Some webpages don't have a background color setted to the body, if you want you can set the color using this method

$screenCapture->setBackgroundColor('#ffffff');

You can also set the User Agent

$screenCapture->setUserAgentString('Some User Agent String');

And most importantly, save the result

$fileLocation = '/some/dir/test.jpg';
$screen->save($fileLocation);

##Other configurations Additionally to the basic usage, you can set so extra configurations.

You can change the where the PhantomJS binary file is.

$screenCapture->binPath = '/path/to/bin/dir/';
// This will result in /path/to/bin/dir/phantomjs

Change the jobs location

$screenCapture->jobs->setLocation('/path/to/jobs/dir/');
echo $screenCapture->jobs->getLocation(); // -> /path/to/jobs/dir/

And set an output base location

$screenCapture->output->setLocation('/path/to/output/dir/');
echo $screenCapture->output->getLocation(); // -> /path/to/output/dir/

// if the output location is setted
$screenCapture->save('file.jpg');
// will save the file to /path/to/output/dir/file.jpg

You can also clean/delete all the generated job files like this:

$screenCapture->jobs->clean();

License

The MIT License (MIT). Please see License File for more information.

Credits

Thanks to the PhantomJS (LICENSE) guys for creating their awesome WebKit scripting interface.

This tool was originally created to take screenshots for Microweber

About

Web site screenshot tool based on PHP and PhantomJS

License:MIT License


Languages

Language:PHP 63.5%Language:HTML 36.5%