Optimizer.php
Go to the documentation of this file.
1<?php
2
4
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 : */