Converter for Media – Optimize images | Convert WebP & AVIF - Version 1.0.6

Version Description

(2019-11-06) = * Automatic deletion of converted files larger than original * Changed way of generating file path (without ABSPATH)

Download this release

Release Info

Developer mateuszgbiorczyk
Plugin Icon 128x128 Converter for Media – Optimize images | Convert WebP & AVIF
Version 1.0.6
Comparing to
See all releases

Code changes from version 1.0.5 to 1.0.6

app/Convert/Gd.php CHANGED
@@ -115,6 +115,7 @@
115
  return [
116
  'success' => true,
117
  'data' => [
 
118
  'size' => [
119
  'before' => filesize($path),
120
  'after' => filesize($output),
115
  return [
116
  'success' => true,
117
  'data' => [
118
+ 'path' => $output,
119
  'size' => [
120
  'before' => filesize($path),
121
  'after' => filesize($output),
app/Convert/Imagick.php CHANGED
@@ -86,6 +86,7 @@
86
  return [
87
  'success' => true,
88
  'data' => [
 
89
  'size' => [
90
  'before' => filesize($path),
91
  'after' => filesize($output),
86
  return [
87
  'success' => true,
88
  'data' => [
89
+ 'path' => $output,
90
  'size' => [
91
  'before' => filesize($path),
92
  'after' => filesize($output),
app/Regenerate/Paths.php CHANGED
@@ -52,7 +52,7 @@
52
  $list['_source'] = str_replace('\\', '/', implode('/', [$upload['basedir'], $path]));
53
  foreach ($sizes as $size) {
54
  $src = wp_get_attachment_image_src($postId, $size);
55
- $url = str_replace(site_url('/'), ABSPATH, $src[0]);
56
  $url = str_replace('\\', '/', $url);
57
 
58
  if (in_array($url, $list)) continue;
52
  $list['_source'] = str_replace('\\', '/', implode('/', [$upload['basedir'], $path]));
53
  foreach ($sizes as $size) {
54
  $src = wp_get_attachment_image_src($postId, $size);
55
+ $url = str_replace($upload['baseurl'], $upload['basedir'], $src[0]);
56
  $url = str_replace('\\', '/', $url);
57
 
58
  if (in_array($url, $list)) continue;
app/Regenerate/Regenerate.php CHANGED
@@ -22,6 +22,8 @@
22
 
23
  foreach ($paths as $path) {
24
  $response = $convert->convertImage($path, $settings['quality']);
 
 
25
  if ($response['success'] !== true) {
26
  $errors[] = $response['message'];
27
  } else {
@@ -38,4 +40,11 @@
38
  ],
39
  ];
40
  }
 
 
 
 
 
 
 
41
  }
22
 
23
  foreach ($paths as $path) {
24
  $response = $convert->convertImage($path, $settings['quality']);
25
+ if ($response['success'] && !$this->checkFileSize($response['data'])) continue;
26
+
27
  if ($response['success'] !== true) {
28
  $errors[] = $response['message'];
29
  } else {
40
  ],
41
  ];
42
  }
43
+
44
+ private function checkFileSize($data)
45
+ {
46
+ if ($data['size']['after'] < $data['size']['before']) return true;
47
+ unlink($data['path']);
48
+ return false;
49
+ }
50
  }
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: mateuszgbiorczyk
3
  Donate link: https://www.paypal.me/mateuszgbiorczyk/
4
  Tags: webp, images, performance, compress, optimize
5
  Requires at least: 5.0
6
- Tested up to: 5.2
7
  Requires PHP: 5.6
8
  Stable tag: trunk
9
  License: GPLv2 or later
@@ -52,8 +52,12 @@ That's all! Your website is already loading faster!
52
 
53
  Practically every hosting meets these requirements. You must use PHP at least 5.6 and have the `GD` or `Imagick` extension installed. **The extension must support `WebP format` *(you can check it using `phpinfo()` function)*.**
54
 
 
 
55
  These are native PHP extensions, used among others by WordPress to generate thumbnails. Your server must also have the modules `mod_mime`, `mod_rewrite` and `mod_expires` enabled.
56
 
 
 
57
  Also REST API must be enabled and work without additional restrictions.
58
 
59
  = Are there any settings? =
@@ -101,6 +105,34 @@ Therefore in this plugin for browsers supporting the WebP format, only the sourc
101
 
102
  If you are using a CDN server, find one that automatically converts images to WebP format and properly sends the correct image format to the browser.
103
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
  == Screenshots ==
105
 
106
  1. Screenshot of the options panel
@@ -108,6 +140,10 @@ If you are using a CDN server, find one that automatically converts images to We
108
 
109
  == Changelog ==
110
 
 
 
 
 
111
  = 1.0.5 (2019-09-16) =
112
  * Adding information on available FAQ
113
 
3
  Donate link: https://www.paypal.me/mateuszgbiorczyk/
4
  Tags: webp, images, performance, compress, optimize
5
  Requires at least: 5.0
6
+ Tested up to: 5.3
7
  Requires PHP: 5.6
8
  Stable tag: trunk
9
  License: GPLv2 or later
52
 
53
  Practically every hosting meets these requirements. You must use PHP at least 5.6 and have the `GD` or `Imagick` extension installed. **The extension must support `WebP format` *(you can check it using `phpinfo()` function)*.**
54
 
55
+ An example of the correct server configuration can be found [here](https://gbiorczyk.pl/webp-converter/serverinfo.png).
56
+
57
  These are native PHP extensions, used among others by WordPress to generate thumbnails. Your server must also have the modules `mod_mime`, `mod_rewrite` and `mod_expires` enabled.
58
 
59
+ If your configuration is different, please contact your server administrator. He is the most competent to solve such problems. Due to the huge amount of possible server environments, we are not able to help you with its configuration. Surely the server administrator will be able to do it best.
60
+
61
  Also REST API must be enabled and work without additional restrictions.
62
 
63
  = Are there any settings? =
105
 
106
  If you are using a CDN server, find one that automatically converts images to WebP format and properly sends the correct image format to the browser.
107
 
108
+ = Does the plugin work in Multisite Network? =
109
+
110
+ Yes, with one exception. In this mode it is not possible to automatically generate the contents of .htaccess file.
111
+
112
+ Please manually paste the following code **at the beginning of .htaccess file**:
113
+
114
+ `# BEGIN WebP Converter`
115
+ `<IfModule mod_mime.c>
116
+ AddType image/webp .webp
117
+ </IfModule>
118
+ <IfModule mod_rewrite.c>
119
+ RewriteEngine On
120
+ RewriteCond %{HTTP_ACCEPT} image/webp
121
+ RewriteCond %{DOCUMENT_ROOT}/$1/uploads-webpc/$2.jpg.webp -f
122
+ RewriteRule (.+)/uploads/(.+)\.jpg$ $1/uploads-webpc/$2.jpg.webp [T=image/webp]
123
+ RewriteCond %{HTTP_ACCEPT} image/webp
124
+ RewriteCond %{DOCUMENT_ROOT}/$1/uploads-webpc/$2.jpeg.webp -f
125
+ RewriteRule (.+)/uploads/(.+)\.jpeg$ $1/uploads-webpc/$2.jpeg.webp [T=image/webp]
126
+ RewriteCond %{HTTP_ACCEPT} image/webp
127
+ RewriteCond %{DOCUMENT_ROOT}/$1/uploads-webpc/$2.png.webp -f
128
+ RewriteRule (.+)/uploads/(.+)\.png$ $1/uploads-webpc/$2.png.webp [T=image/webp]
129
+ </IfModule>
130
+ <IfModule mod_expires.c>
131
+ ExpiresActive On
132
+ ExpiresByType image/webp "access plus 1 year"
133
+ </IfModule>`
134
+ `# END WebP Converter`
135
+
136
  == Screenshots ==
137
 
138
  1. Screenshot of the options panel
140
 
141
  == Changelog ==
142
 
143
+ = 1.0.6 (2019-11-06) =
144
+ * Automatic deletion of converted files larger than original
145
+ * Changed way of generating file path _(without `ABSPATH`)_
146
+
147
  = 1.0.5 (2019-09-16) =
148
  * Adding information on available FAQ
149
 
webp-converter-for-media.php CHANGED
@@ -3,13 +3,13 @@
3
  /*
4
  Plugin Name: WebP Converter for Media
5
  Description: Speed up your website by serving WebP images instead of standard formats JPEG, PNG and GIF.
6
- Version: 1.0.5
7
  Author: Mateusz Gbiorczyk
8
  Author URI: https://gbiorczyk.pl/
9
  Text Domain: webp-converter
10
  */
11
 
12
- define('WEBPC_VERSION', '1.0.5');
13
  define('WEBPC_FILE', __FILE__);
14
  define('WEBPC_NAME', plugin_basename(__FILE__));
15
  define('WEBPC_PATH', plugin_dir_path(__FILE__));
3
  /*
4
  Plugin Name: WebP Converter for Media
5
  Description: Speed up your website by serving WebP images instead of standard formats JPEG, PNG and GIF.
6
+ Version: 1.0.6
7
  Author: Mateusz Gbiorczyk
8
  Author URI: https://gbiorczyk.pl/
9
  Text Domain: webp-converter
10
  */
11
 
12
+ define('WEBPC_VERSION', '1.0.6');
13
  define('WEBPC_FILE', __FILE__);
14
  define('WEBPC_NAME', plugin_basename(__FILE__));
15
  define('WEBPC_PATH', plugin_dir_path(__FILE__));