Optipng.php
Go to the documentation of this file.
1<?php
2
4
5class Optipng extends Optimizer
6{
7 protected $version;
8
9 public function __construct($options = array())
10 {
11 parent::__construct($options);
12
13 if (isset($this->options['optipng'])) {
14 $this->executable = $this->options['optipng'];
15 }
16
17 if (is_null($this->executable)) {
18 $this->executable = \Depage\Graphics\Graphics::which("optipng");
19 }
20
21 if ($this->executable) {
22 exec($this->executable . ' --version 2>&1', $commandOutput, $returnStatus);
23
24 preg_match("/(\d+).(\d+).(\d+)/", $commandOutput[0], $matches);
25
26 $this->version = $matches[0];
27 }
28 }
29
30 public function optimize($filename)
31 {
32 if (!$this->executable) {
33 return false;
34 }
35
36 $this->command = "{$this->executable} ";
37
38 // 2 is the default (8 trials) -> may change between versions
39 //$this->command .= "-o 2 ";
40
41 if (version_compare($this->version, '0.7.0', '>=')) {
42 // strip got added in version 0.7
43 $this->command .= "-strip all ";
44 }
45
46 $this->command .= "-preserve ";
47
48 $this->command .= " " . escapeshellarg($filename);
49
50 return $this->execCommand();
51 }
52}
53
54/* vim:set ft=php sw=4 sts=4 fdm=marker et : */
__construct($options=array())
Definition Optipng.php:9