Skip to content

Commit baaa335

Browse files
committed
#85 - Added webp conversion
1 parent e09f907 commit baaa335

File tree

2 files changed

+91
-2
lines changed

2 files changed

+91
-2
lines changed

src/Configuration/ConfigurationDefaults.php

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public function __construct(&$settings) {
3636
$lsb = trim(`which lsb_release`);
3737
if ($lsb !== '') {
3838
$lsb = escapeshellarg($lsb);
39-
$settings['operating_system'] = trim(`$lsb -is`);
40-
$settings['operating_system_version'] = trim(`$lsb -rs`);
39+
$settings['operating_system'] = trim(`$lsb -is`);
40+
$settings['operating_system_version'] = trim(`$lsb -rs`);
4141
}
4242
}
4343
elseif ($settings['operating_system'] === 'Windows NT') {
@@ -111,6 +111,11 @@ public function __construct(&$settings) {
111111
'#engine' => 'Convert\\Pandoc',
112112
),
113113
),
114+
'(jpg|png|gif|svg|tiff|wmf)->(jpg|png|gif|svg|tiff|wmf)' => array(
115+
'imagemagick:default' => array(
116+
'#engine' => 'Convert\\ImageMagick',
117+
),
118+
),
114119
'pdf->jpg' => array(
115120
'imagemagick:default' => array(
116121
'#engine' => 'Convert\\ImageMagick',
@@ -145,6 +150,28 @@ public function __construct(&$settings) {
145150
'chain' => 'rtf->ps->pdf',
146151
),
147152
),
153+
'webp->jpg' => array(
154+
'webp->png->jpg' => array(
155+
'#engine' => 'Chain',
156+
'chain' => 'webp->png->jpg',
157+
),
158+
),
159+
'webp->png' => array(
160+
'webp:default' => array(
161+
'#engine' => 'Convert\\WebP',
162+
),
163+
),
164+
'jpg->webp' => array(
165+
'jpg->png->webp' => array(
166+
'#engine' => 'Chain',
167+
'chain' => 'jpg->png->webp',
168+
),
169+
),
170+
'png->webp' => array(
171+
'webp:default' => array(
172+
'#engine' => 'Convert\\WebP',
173+
),
174+
),
148175
'rtf->ps' => array(
149176
'ted:default' => array(
150177
'#engine' => 'Convert\\Ted',

src/Engine/Convert/WebP.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/*
3+
* This file is part of the FileConverter package.
4+
*
5+
* (c) Greg Payne
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
namespace FileConverter\Engine\Convert;
12+
use FileConverter\Engine\EngineBase;
13+
use FileConverter\Util\Shell;
14+
class WebP extends EngineBase {
15+
public function getConvertFileShell($source, &$destination) {
16+
if ($this->conversion[1] === 'webp') {
17+
$this->cmd = $this->shellWhich('cwebp');
18+
return array(
19+
$this->cmd,
20+
// '-lossless',
21+
$source,
22+
'-o',
23+
$destination,
24+
);
25+
}
26+
else {
27+
return array(
28+
$this->cmd,
29+
$source,
30+
'-o',
31+
$destination,
32+
);
33+
}
34+
}
35+
36+
protected function getHelpInstallation($os, $os_version) {
37+
$help = array(
38+
'title' => 'WebP',
39+
'url' => 'https://developers.google.com/speed/webp/docs/using',
40+
);
41+
switch ($os) {
42+
case 'Ubuntu':
43+
$help['os'] = 'confirmed on Ubuntu 16.04';
44+
$help['apt-get'] = 'webp';
45+
return $help;
46+
}
47+
48+
return parent::getHelpInstallation($os, $os_version);
49+
}
50+
51+
public function getVersionInfo() {
52+
$info = array(
53+
'dwebp' => $this->shell('dwebp -version'),
54+
);
55+
return $info;
56+
}
57+
58+
public function isAvailable() {
59+
$this->cmd = $this->shellWhich('dwebp');
60+
return isset($this->cmd);
61+
}
62+
}

0 commit comments

Comments
 (0)