-
Notifications
You must be signed in to change notification settings - Fork 77
/
WebsiteToImage.php
89 lines (73 loc) · 1.86 KB
/
WebsiteToImage.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
<?php
class WebsiteToImage
{
const FORMAT_JPG = 'jpg';
const FORMAT_JPEG = 'jpeg';
const FORMAT_PNG = 'png';
const FORMAT_TIF = 'tif';
const FORMAT_TIFF = 'tiff';
protected $_programPath;
protected $_outputFile;
protected $_url;
protected $_format = self::FORMAT_JPG;
protected $_quality = 90;
public function start()
{
$programPath = escapeshellcmd($this->_programPath);
$outputFile = escapeshellarg($this->_outputFile);
$url = escapeshellarg($this->_url);
$format = escapeshellarg($this->_format);
$quality = escapeshellarg($this->_quality);
$command = "$programPath --format $format --quality $quality $url $outputFile";
exec($command);
}
public function setOutputFile($outputFile)
{
clearstatcache();
if (!is_writable(dirname($outputFile))) {
throw new Exception('output file not writable');
}
$this->_outputFile = $outputFile;
return $this;
}
public function getOutputFile()
{
return $this->_outputFile;
}
public function setProgramPath($programPath)
{
$this->_programPath = $programPath;
return $this;
}
public function getProgramPath()
{
return $this->_programPath;
}
public function setFormat($format)
{
$this->_format = $format;
return $this;
}
public function getFormat()
{
return $this->_format;
}
public function setQuality($quality)
{
$this->_quality = (int)$quality;
return $this;
}
public function getQuality()
{
return $this->_quality;
}
public function setUrl($url)
{
$this->_url = $url;
return $this;
}
public function getUrl()
{
return $this->_url;
}
}