PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.3.2
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.3.2
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.3.2, at webp/class-wpo-webp-convert.php

54 lines 1.4 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
5 if (!class_exists('WPO_WebP_Convert')) :
6
7 class WPO_WebP_Convert {
8
9 public $converters = null;
10
11 public function __construct() {
12 $this->converters = WP_Optimize()->get_options()->get_option('webp_converters');
13 }
14
15 /**
16 * Converts uploaded image to webp format
17 *
18 * @param string $source - path of the source file
19 */
20 public function convert($source) {
21 if (count($this->converters) < 1) return false;
22
23 $destination = $this->get_destination_path($source);
24 $this->check_converters_and_do_conversion($source, $destination);
25 }
26
27 /**
28 * Returns the destination full path
29 *
30 * @param string $source - path of the source file
31 *
32 * @return string $destination - path of destination file
33 */
34 protected function get_destination_path($source) {
35 $path_parts = pathinfo($source);
36 $destination = $path_parts['dirname'] . '/'. basename($source) . '.webp';
37 return $destination;
38 }
39
40 /**
41 * Loop through available converters and do the conversion
42 *
43 * @param string $source - path of source file
44 * @param string $destination - path of destination file
45 */
46 protected function check_converters_and_do_conversion($source, $destination) {
47 foreach ($this->converters as $converter) {
48 WPO_WebP_Utils::perform_webp_conversion($converter, $source, $destination);
49 break;
50 }
51 }
52 }
53 endif;
54