|
1 |
| -Screen |
2 |
| -====== |
| 1 | +#Screen |
3 | 2 |
|
4 | 3 | Web site screenshot tool based on PHP and [PhantomJS](http://phantomjs.org/ "")
|
5 |
| - |
6 | 4 | You can use it to take screenshots for testing or monitoring service
|
7 | 5 |
|
| 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 | +``` |
8 | 57 |
|
9 |
| -Usage |
10 |
| -====== |
| 58 | +You can also set the User Agent |
| 59 | +``` php |
| 60 | +$screenCapture->setUserAgentString('Some User Agent String'); |
| 61 | +``` |
11 | 62 |
|
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 | +``` |
16 | 68 |
|
| 69 | +##Other configurations |
| 70 | +Additionally to the basic usage, you can set so extra configurations. |
17 | 71 |
|
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 | +``` |
20 | 77 |
|
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 | +``` |
22 | 83 |
|
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/ |
24 | 88 |
|
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 | +``` |
26 | 93 |
|
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 | +``` |
29 | 98 |
|
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 |
32 | 100 |
|
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. |
34 | 102 |
|
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 |
40 | 104 |
|
| 105 | +- [Peter Ivanov](https://github.com/peter-mw) |
| 106 | +- [André Filipe](https://github.com/MASNathan) |
| 107 | +- [All Contributors](../../contributors) |
41 | 108 |
|
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. |
45 | 110 |
|
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