PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.9
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.9
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / webp / class-wpo-webp-convert.php

class-wpo-webp-convert.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 3.2.9, at webp/class-wpo-webp-convert.php

63 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('WPO_VERSION')) die('No direct access allowed');
4 use \WebPConvert\Convert\ConverterFactory;
5
6 require_once(WPO_PLUGIN_MAIN_PATH . 'vendor/autoload.php');
7 require_once(WPO_PLUGIN_MAIN_PATH . 'webp/class-wpo-webp-test-run.php');
8
9 if (!class_exists('WPO_WebP_Convert')) :
10
11 class WPO_WebP_Convert {
12
13 public $converters = null;
14
15 public function __construct() {
16 $this->converters = WP_Optimize()->get_options()->get_option('webp_converters');
17 }
18
19 /**
20 * Converts uploaded image to webp format
21 *
22 * @param string $source - path of the source file
23 */
24 public function convert($source) {
25 if (count($this->converters) < 1) return false;
26
27 $destination = $this->get_destination_path($source);
28 $this->check_converters_and_do_conversion($source, $destination);
29 }
30
31 /**
32 * Returns the destination full path
33 *
34 * @param string $source - path of the source file
35 *
36 * @return string $destination - path of destination file
37 */
38 protected function get_destination_path($source) {
39 $path_parts = pathinfo($source);
40 $destination = $path_parts['dirname'] . '/'. basename($source) . '.webp';
41 return $destination;
42 }
43
44 /**
45 * Loop through available converters and do the conversion
46 *
47 * @param string $source - path of source file
48 * @param string $destination - path of destination file
49 */
50 protected function check_converters_and_do_conversion($source, $destination) {
51 foreach ($this->converters as $converter) {
52 $converter_instance = ConverterFactory::makeConverter(
53 $converter,
54 $source,
55 $destination
56 );
57 $converter_instance->doConvert();
58 break;
59 }
60 }
61 }
62 endif;
63