|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace WebPConvert; |
|
4
|
|
|
|
|
5
|
|
|
//use WebPConvert\Convert\Converters\ConverterHelper; |
|
6
|
|
|
use WebPConvert\Convert\Converters\Stack; |
|
7
|
|
|
//use WebPConvert\Serve\ServeExistingOrHandOver; |
|
8
|
|
|
use WebPConvert\Serve\ServeConvertedWebP; |
|
9
|
|
|
use WebPConvert\Serve\ServeConvertedWebPWithErrorHandling; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Convert images to webp and/or serve them. |
|
13
|
|
|
* |
|
14
|
|
|
* This class is just a couple of convenience methods for doing conversion and/or |
|
15
|
|
|
* serving. |
|
16
|
|
|
* |
|
17
|
|
|
* @package WebPConvert |
|
18
|
|
|
* @author Bjørn Rosell <[email protected]> |
|
19
|
|
|
* @since Class available since Release 2.0.0 |
|
20
|
|
|
*/ |
|
21
|
|
|
class WebPConvert |
|
22
|
|
|
{ |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Convert jpeg or png into webp |
|
26
|
|
|
* |
|
27
|
|
|
* @param string $source Absolute path to image to be converted (no backslashes). Image must be jpeg or png |
|
28
|
|
|
* @param string $destination Absolute path (no backslashes) |
|
29
|
|
|
* @param array $options Array of named options, such as 'quality' and 'metadata' |
|
30
|
|
|
* @throws \WebPConvert\Exceptions\WebPConvertException |
|
31
|
|
|
* @return void |
|
32
|
|
|
*/ |
|
33
|
6 |
|
public static function convert($source, $destination, $options = [], $logger = null) |
|
34
|
|
|
{ |
|
35
|
|
|
//return ConverterHelper::runConverterStack($source, $destination, $options, $logger); |
|
36
|
|
|
//return Convert::runConverterStack($source, $destination, $options, $logger); |
|
37
|
6 |
|
Stack::convert($source, $destination, $options, $logger); |
|
38
|
2 |
|
} |
|
39
|
|
|
|
|
40
|
|
|
public static function convertAndServe($source, $destination, $options = []) |
|
41
|
|
|
{ |
|
42
|
|
|
//return ServeExistingOrHandOver::serveConverted($source, $destination, $options); |
|
43
|
|
|
//if (isset($options['handle-errors']) && $options['handle-errors'] === true) { |
|
44
|
|
|
if (isset($options['fail']) && ($options['fail'] != 'throw')) { |
|
45
|
|
|
ServeConvertedWebPWithErrorHandling::serve($source, $destination, $options); |
|
46
|
|
|
} else { |
|
47
|
|
|
ServeConvertedWebP::serve($source, $destination, $options); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|