-
Notifications
You must be signed in to change notification settings - Fork 1
/
SiteScreen.php
64 lines (53 loc) · 1.65 KB
/
SiteScreen.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
class SiteScreen{
public $url;
public $timeout;
public $sizes;
public $size;
public $imageDestination;
public $imageName;
/**
* Construct.
*
* @param string $destinationPath destination of the site screenshot
*
*/
public function __construct( string $destinationPath )
{
$this->destinationPath = $destinationPath;
$this->sizes =
array(
'360x2000'=>"360,2000",
'768x2000'=>"768,2000",
'1800x1400'=>"1800,1400"
);
}
/**
* shot process a screenshot at a predefined size (see $sizes).
*
* @param string $url url to capture (screenshot).
* @param string $size predefined size from array sizes.
* @param int $timeout for stop the process after x sec.
*
*/
public function shot( string $url, string $size, int $timeout )
{
$this->url = $url;
$this->size = $size;
$this->timeout = $timeout;
$this->imageName = md5($url) . '-' .( $this->size ).'.png';
$this->imageDestination = $this->destinationPath . '/' . $this->imageName;
$this->command();
}
/**
* command() | generate the shell command and execute it.
*
*/
public function command()
{
// local -> delete chromium-browser for your local browser chrome, ...
$cmd = 'timeout=' . $this->timeout . ' chromium-browser --headless --disable-gpu --hide-scrollbars --window-size=';
$cmd .= $this->sizes[$this->size].' --screenshot=' . $this->imageDestination . ' ' . $this->url . ' &';
exec( $cmd,$output );
}
}