Skip to content

Commit deef3ad

Browse files
committed
V1.0.1 (#45)
* 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
1 parent e1016a5 commit deef3ad

20 files changed

+565
-270
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ vendor/
55
jobs/*.js
66

77
demo/test.jpg
8+
test.php

LICENSE

Lines changed: 0 additions & 36 deletions
This file was deleted.

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# The MIT License (MIT)
2+
3+
Copyright (c) 2016 Peter Ivanov <[email protected]>
4+
5+
> Permission is hereby granted, free of charge, to any person obtaining a copy
6+
> of this software and associated documentation files (the "Software"), to deal
7+
> in the Software without restriction, including without limitation the rights
8+
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
> copies of the Software, and to permit persons to whom the Software is
10+
> furnished to do so, subject to the following conditions:
11+
>
12+
> The above copyright notice and this permission notice shall be included in
13+
> all copies or substantial portions of the Software.
14+
>
15+
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
> THE SOFTWARE.

README.md

Lines changed: 93 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,111 @@
1-
Screen
2-
======
1+
#Screen
32

43
Web site screenshot tool based on PHP and [PhantomJS](http://phantomjs.org/ "")
5-
64
You can use it to take screenshots for testing or monitoring service
75

6+
## Install
7+
8+
Via Composer
9+
10+
``` bash
11+
$ composer require microweber/screen
12+
```
13+
14+
If on any unix system, you need to make the `bin` executable `chmod +x /path/to/screen/bin/phantomjs`
15+
16+
The directory `/path/to/screen/jobs` must be writeble as well.
17+
18+
##Linux requirements
19+
20+
* FontConfig - `apt-get/yum install fontconfig`
21+
* FreeType - `apt-get/yum install freetype*`
22+
23+
##Usage
24+
25+
With this library you can make use of PhantomJs to screenshot a website.
26+
27+
Check our [demo](/demo) or read the following instructions.
28+
29+
Creating the object, you can either pass the url on the constructer or set it later on
30+
``` php
31+
use Screen\Capture;
32+
33+
$url = 'https://github.com';
34+
35+
$screenCapture = new Capture($url);
36+
// or
37+
$screenCapture = new Capture();
38+
$screenCapture->setUrl($url);
39+
```
40+
41+
You can also set the browser dimensions
42+
``` php
43+
$screenCapture->setWidth(1200);
44+
$screenCapture->setHeight(800);
45+
```
46+
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
47+
``` php
48+
// You also need to set the width and height.
49+
$screenCapture->setClipWidth(1200);
50+
$screenCapture->setClipHeight(800);
51+
```
52+
53+
Some webpages don't have a background color setted to the body, if you want you can set the color using this method
54+
``` php
55+
$screenCapture->setBackgroundColor('#ffffff');
56+
```
857

9-
Usage
10-
======
58+
You can also set the User Agent
59+
``` php
60+
$screenCapture->setUserAgentString('Some User Agent String');
61+
```
1162

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

69+
##Other configurations
70+
Additionally to the basic usage, you can set so extra configurations.
1771

18-
API
19-
=====
72+
You can change the where the PhantomJS binary file is.
73+
``` php
74+
$screenCapture->binPath = '/path/to/bin/dir/';
75+
// This will result in /path/to/bin/dir/phantomjs
76+
```
2077

21-
You can directly render the taken screen-shot with the `shot.php` file
78+
Change the jobs location
79+
``` php
80+
$screenCapture->jobs->setLocation('/path/to/jobs/dir/');
81+
echo $screenCapture->jobs->getLocation(); // -> /path/to/jobs/dir/
82+
```
2283

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

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

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

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

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

35-
36-
Dependencies
37-
=====
38-
* FontConfig must be installed - `apt-get/yum install fontconfig`
39-
* FreeType is also required - `apt-get/yum install freetype*`
103+
## Credits
40104

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

42-
Thanks
43-
====
44-
Thanks to the [PhantomJS](http://phantomjs.org/ "Headless browser") guys for creating their awesome WebKit scripting interface.
109+
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.
45110

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

0 commit comments

Comments
 (0)