-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathphpCutyCapt.php
120 lines (106 loc) · 3.1 KB
/
phpCutyCapt.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
namespace phpCutyCapt;
/**
* Project: phpCutyCapt
* File: phpCutyCapt.php
*
* This class is free software for generating website screenshots
* using CutyCapt(http://cutycapt.sourceforge.net) via X virtual
* framebuffer (xvfb) on linux systems
*
* @link http://moneyseeker.ru/
* @copyright 2013 Stanislav Fedotov
* @author Stanislav Fedotov <me at moneyseeker dot ru>
* @version 1.0
*/
class phpCutyCapt {
/**
* The url of the website page, we're making the screenshot of
* This must include protocol (http:// or https://)
*
* @var string
*/
protected $parseURL;
/**
* Minimum width of the page to take screenshot
*
* @var int
*/
protected $minWidth;
/**
* File path to output the screenshot to
* CutyCapt has an heuristic format recognizer, so you can
* use one of the following extensions:
* svg,ps,pdf,itext,html,rtree,png,jpeg,mng,tiff,gif,bmp,ppm,xbm,xpm
* I suggest png or jpg
*
* @var string
*/
protected $outFile;
/**
* Enable plugins, such as Flash and others
*
* @var bool
*/
protected $pluginsEnable;
/**
* Delay. Amount of time in seconds to wait before taking shot
* after the page is loaded
*
* @var int
*/
protected $delay;
/**
* @param $parseUrl
* @param $outFile
* @param int $minWidth
* @param bool $pluginsEnable
* @param int $delay
* @throws InvalidArgumentException
*/
public function __construct($parseUrl, $outFile, $minWidth = 1024, $pluginsEnable = true, $delay = 1)
{
$this->parseURL = escapeshellarg($parseUrl);
$this->outFile = $outFile;
$this->minWidth = $minWidth;
$this->minWidth = $minWidth;
$this->pluginsEnable = $pluginsEnable;
$this->delay = $delay;
if(!is_dir(dirname($outFile)) OR !is_writeable(dirname($outFile))) {
throw new InvalidArgumentException('Directory for screenshotfile does not exist');
}
}
/**
* Create screenshot and tell if it was successfully generated
* @return bool
*/
public function screenshot()
{
$cmd = 'xvfb-run --auto-servernum --server-args="-screen 0, 1024x768x24" lib/CutyCapt';
$cmd .= ' --min-width='.$this->minWidth;
$cmd .= ' --min-height=1024';
$cmd .= ' --url='.$this->parseURL;
$cmd .= ' --out='.$this->outFile;
$cmd .= ' --delay='.$this->delay;
$cmd .= ($this->pluginsEnable) ? ' --plugins=on' : ' --plugins=off';
$cmd .= " --insecure";
#exec("source /opt/rh/qt48/enable && ".$cmd, $output);//For CentOS 6.x
exec($cmd, $output);
if(file_exists($this->outFile)) {
if(filesize($this->outFile)>1) {
return true;
} else {
return false;
}
} else {
return false;
}
}
/**
* Delete file after managing actions for it
*/
public function clean()
{
unlink($this->outFile);
}
}