docs depage-graphics
Optimizers
Optimizer.php
Go to the documentation of this file.
1
<?php
2
3
namespace
Depage\Graphics\Optimizers
;
4
5
class
Optimizer
6
{
7
protected
$executable
=
null
;
8
protected
$command
=
''
;
9
protected
$options
= array();
10
11
public
function
__construct
(
$options
= array())
12
{
13
$this->options =
$options
;
14
}
15
16
protected
function
execCommand
()
17
{
18
exec($this->command .
' 2>&1'
, $commandOutput, $returnStatus);
19
if
($returnStatus != 0) {
20
throw
new \Depage\Graphics\Exceptions\Exception(implode(
"\n"
, $commandOutput));
21
}
22
23
return
true
;
24
}
25
public
function
optimize
($filename)
26
{
27
$optimizer =
false
;
28
$parts = explode(
'.'
, $filename);
29
$extension = strtolower(end($parts));
30
31
if
($extension ==
"jpg"
|| $extension ==
"jpeg"
) {
32
if
(isset($this->options[
'jpegoptim'
])) {
33
$optimizer =
new
Jpegoptim
($this->options);
34
}
else
{
35
$optimizer =
new
Jpegtran
($this->options);
36
}
37
} elseif ($extension ==
"png"
) {
38
if
(isset($this->options[
'pngcrush'
])) {
39
$optimizer =
new
Pngcrush
($this->options);
40
}
else
{
41
$optimizer =
new
Optipng
($this->options);
42
}
43
}
44
if
($optimizer) {
45
return
$optimizer->optimize($filename);
46
}
47
return
false
;
48
}
49
}
50
51
/* vim:set ft=php sw=4 sts=4 fdm=marker et : */
Depage\Graphics\Optimizers\Jpegoptim
Definition
Jpegoptim.php:6
Depage\Graphics\Optimizers\Jpegtran
Definition
Jpegtran.php:6
Depage\Graphics\Optimizers\Optimizer
Definition
Optimizer.php:6
Depage\Graphics\Optimizers\Optimizer\$options
$options
Definition
Optimizer.php:9
Depage\Graphics\Optimizers\Optimizer\$executable
$executable
Definition
Optimizer.php:7
Depage\Graphics\Optimizers\Optimizer\$command
$command
Definition
Optimizer.php:8
Depage\Graphics\Optimizers\Optimizer\__construct
__construct($options=array())
Definition
Optimizer.php:11
Depage\Graphics\Optimizers\Optimizer\execCommand
execCommand()
Definition
Optimizer.php:16
Depage\Graphics\Optimizers\Optimizer\optimize
optimize($filename)
Definition
Optimizer.php:25
Depage\Graphics\Optimizers\Optipng
Definition
Optipng.php:6
Depage\Graphics\Optimizers\Pngcrush
Definition
Pngcrush.php:6
Depage\Graphics\Optimizers
Definition
Jpegoptim.php:3