Skip to content

Commit

Permalink
V1.0.1 (#45)
Browse files Browse the repository at this point in the history
* Now the background color and the user agent can be changed
Added clean jobs functionality - fixed #38
Updated vendor

* Added setUrl method
Added configuration to set the default output directory

* Small fixes

* Fixed typo

* Updated binaries, documentation and license

* Added post install script
  • Loading branch information
MASNathan committed Apr 7, 2016
1 parent e1016a5 commit deef3ad
Show file tree
Hide file tree
Showing 20 changed files with 565 additions and 270 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ vendor/
jobs/*.js

demo/test.jpg
test.php
36 changes: 0 additions & 36 deletions LICENSE

This file was deleted.

21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# The MIT License (MIT)

Copyright (c) 2016 Peter Ivanov <[email protected]>

> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in
> all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> THE SOFTWARE.
121 changes: 93 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,111 @@
Screen
======
#Screen

Web site screenshot tool based on PHP and [PhantomJS](http://phantomjs.org/ "")

You can use it to take screenshots for testing or monitoring service

## Install

Via Composer

``` bash
$ 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](/demo) or read the following instructions.

Creating the object, you can either pass the url on the constructer or set it later on
``` php
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
``` php
$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
``` php
// 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
``` php
$screenCapture->setBackgroundColor('#ffffff');
```

Usage
======
You can also set the User Agent
``` php
$screenCapture->setUserAgentString('Some User Agent String');
```

* Upload to your webserver
* Make the `bin` executable `chmod +x /var/www/html/screen/bin/phantomjs`
* Make your folder writable
* Open your browser to index.php
And most importantly, save the result
``` php
$fileLocation = '/some/dir/test.jpg';
$screen->save($fileLocation);
```

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

API
=====
You can change the where the PhantomJS binary file is.
``` php
$screenCapture->binPath = '/path/to/bin/dir/';
// This will result in /path/to/bin/dir/phantomjs
```

You can directly render the taken screen-shot with the `shot.php` file
Change the jobs location
``` php
$screenCapture->jobs->setLocation('/path/to/jobs/dir/');
echo $screenCapture->jobs->getLocation(); // -> /path/to/jobs/dir/
```

You can render any link by passing it as `url` parameter
And set an output base location
``` php
$screenCapture->output->setLocation('/path/to/output/dir/');
echo $screenCapture->output->getLocation(); // -> /path/to/output/dir/

`shot.php?url=google.com`
// if the output location is setted
$screenCapture->save('file.jpg');
// will save the file to /path/to/output/dir/file.jpg
```

You can specify height and width:
`shot.php?url=google.com&w=300&h=100`
You can also clean/delete all the generated job files like this:
``` php
$screenCapture->jobs->clean();
```

If you want to crop/clip the screen shot, you can do so like this:
`shot.php?url=google.com&w=800&h=600&clipw=800&cliph=600`
## License

To download the image, just go to `shot.php?url=google.com&download=true`
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.


Dependencies
=====
* FontConfig must be installed - `apt-get/yum install fontconfig`
* FreeType is also required - `apt-get/yum install freetype*`
## Credits

- [Peter Ivanov](https://github.com/peter-mw)
- [André Filipe](https://github.com/MASNathan)
- [All Contributors](../../contributors)

Thanks
====
Thanks to the [PhantomJS](http://phantomjs.org/ "Headless browser") guys for creating their awesome WebKit scripting interface.
Thanks to the [PhantomJS](http://phantomjs.org/ "Headless browser") ([LICENSE](https://github.com/ariya/phantomjs/blob/master/LICENSE.BSD)) guys for creating their awesome WebKit scripting interface.

This tool was originally created to take screenshots for [Microweber](http://microweber.com/ "open source cms")
This tool was originally created to take screenshots for [Microweber](http://microweber.com/ "Open Source CMS")
Loading

1 comment on commit deef3ad

@peter-mw
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work, its getting better and better :)

also MIT license it better too

i used BSD at start because PhantomJS is BSD

Please sign in to comment.