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

Version Description

(2020-02-10) = * [Fixed] Support for WordPress installation in subdirectory * [Fixed] Error detecting WebP support by Imagick

Download this release

Release Info

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

Code changes from version 1.0.9 to 1.1.0

app/Media/Htaccess.php CHANGED
@@ -48,6 +48,7 @@
48
  $content = '';
49
  if (!$settings['extensions']) return $content;
50
 
 
51
  $pathSource = apply_filters('webpc_uploads_path', '');
52
  $pathOutput = apply_filters('webpc_uploads_webp', '');
53
 
@@ -55,7 +56,7 @@
55
  $content .= ' RewriteEngine On' . PHP_EOL;
56
  foreach ($settings['extensions'] as $ext) {
57
  $content .= ' RewriteCond %{HTTP_ACCEPT} image/webp' . PHP_EOL;
58
- $content .= " RewriteCond %{DOCUMENT_ROOT}/${pathOutput}/$1.${ext}.webp -f" . PHP_EOL;
59
  $content .= " RewriteRule ${pathSource}/(.+)\.${ext}$ ${pathOutput}/$1.${ext}.webp [T=image/webp]" . PHP_EOL;
60
  }
61
  $content .= '</IfModule>';
48
  $content = '';
49
  if (!$settings['extensions']) return $content;
50
 
51
+ $pathUrl = parse_url(site_url('/'), PHP_URL_PATH);
52
  $pathSource = apply_filters('webpc_uploads_path', '');
53
  $pathOutput = apply_filters('webpc_uploads_webp', '');
54
 
56
  $content .= ' RewriteEngine On' . PHP_EOL;
57
  foreach ($settings['extensions'] as $ext) {
58
  $content .= ' RewriteCond %{HTTP_ACCEPT} image/webp' . PHP_EOL;
59
+ $content .= " RewriteCond %{DOCUMENT_ROOT}${pathUrl}${pathOutput}/$1.${ext}.webp -f" . PHP_EOL;
60
  $content .= " RewriteRule ${pathSource}/(.+)\.${ext}$ ${pathOutput}/$1.${ext}.webp [T=image/webp]" . PHP_EOL;
61
  }
62
  $content .= '</IfModule>';
app/Settings/Methods.php CHANGED
@@ -21,7 +21,7 @@
21
  $list[] = 'gd';
22
  }
23
  if (extension_loaded('imagick') && class_exists('\Imagick')) {
24
- $formats = \Imagick::queryformats();
25
  if (in_array('WEBP', $formats)) $list[] = 'imagick';
26
  }
27
  return $list;
21
  $list[] = 'gd';
22
  }
23
  if (extension_loaded('imagick') && class_exists('\Imagick')) {
24
+ $formats = (new \Imagick)->queryformats();
25
  if (in_array('WEBP', $formats)) $list[] = 'imagick';
26
  }
27
  return $list;
readme.txt CHANGED
@@ -50,60 +50,73 @@ That's all! Your website is already loading faster!
50
 
51
  == Frequently Asked Questions ==
52
 
53
- = What are the requirements of the plugin? =
54
 
55
- Practically every hosting meets these requirements. You must use PHP at least 7.0 and have the `GD` or `Imagick` extension installed. **The extension must support `WebP format` *(you can check it using `phpinfo()` function)*.**
56
 
57
- An example of the correct server configuration can be found [here](https://gbiorczyk.pl/webp-converter/serverinfo.png).
58
 
59
- 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.
60
 
61
- 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.
62
 
63
- Also REST API must be enabled and work without additional restrictions.
64
 
65
- = Configuration for Nginx =
66
 
67
- Please edit the configuration file:
68
 
69
- `/etc/nginx/mime.types`
70
 
71
- and add this code:
72
 
73
- `types {`
74
- ` # ...
75
 
76
- image/webp webp;
77
- }`
 
78
 
79
- Then please find your configuration file in the path *(default is default file)*:
80
 
81
- `/etc/nginx/sites-available/`
 
 
 
 
 
 
82
 
83
- and add below code in this file:
84
 
85
- `server {`
86
- ` # ...
87
 
88
- location ~ (?<root>.+)/uploads/(?<path>.+)\.(?<ext>jp?g|png|gif)$ {
89
- if ($http_accept !~* "image/webp") {
90
- break;
91
- }
92
- add_header Vary Accept;
93
- expires 365d;
94
- try_files $root/uploads-webpc/$path.$ext.webp $uri =404;
95
- }
96
- }`
97
 
98
- = How can I convert existing images after installing? =
99
 
100
- In the WordPress admin panel, on the `Settings -> WebP Converter` subpage there is a module that allows you to process all your images.
101
 
102
- It uses the WordPress REST API by downloading addresses of all images and converting all files gradually.
 
 
 
 
103
 
104
- This process may take few or more than ten minutes depending on the number of files.
105
 
106
- = What are the restrictions? =
 
 
 
 
 
 
 
 
 
 
 
 
107
 
108
  The size of the image is a limited. Its resolution cannot be bigger than `8192 x 8192px`. This is due to the limitations of the PHP library.
109
 
@@ -111,7 +124,30 @@ Please remember that **Safari and Internet Explorer do not support the WebP form
111
 
112
  You can find more about WebP support by browsers [here](https://caniuse.com/#feat=webp).
113
 
114
- = Where are the converted images stored? =
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
 
116
  All WebP images are stored in the `/wp-content/uploads-webpc/` directory. Inside the directory there is the same structure as in the original `uploads` directory. The files have original extensions in the name along with the new `.webp`.
117
 
@@ -139,28 +175,13 @@ Filter `webpc_uploads_path` modifies the default path to the original uploads fi
139
 
140
  Then go to `Settings -> WebP Converter` in the admin panel and click the `Save Changes` button. Also remember to regenerate all images using the `Regenerate All` button.
141
 
142
- = How to check if plugin works? =
143
-
144
- When you have installed plugin and converted all images, follow these steps:
145
-
146
- 1. Run `Google Chrome` and enable `Dev Tools` *(F12)*.
147
- 2. Go to the `Network` tab and select filtering for `Img` *(Images)*.
148
- 3. Refresh your website page.
149
- 4. Check list of loaded images. Note `Type` column.
150
- 5. If value of `webp` is there, then everything works fine.
151
- 6. Remember that this plugin does not change URLs. This means that e.g. link will have path to .jpg file, but `.jpg.webp file will be loaded instead of original .jpg`.
152
- 7. In addition, you can check weight of website before and after using plugin. The difference will be huge!
153
- 8. More information: [here](https://gbiorczyk.pl/webp-converter/check-devtools.png)
154
-
155
- Please remember that if the converted image in WebP format is larger than the original, the browser will use the original file. Therefore, you can also see files other than WebP on the list.
156
-
157
  = Can I enable browser caching for WebP images? =
158
 
159
  Yes of course. The plugin allows this by using the module `mod_expires`. Thanks to this, we can even speed up page loading time for returning users because they do not need to re-download files from the server.
160
 
161
  If you do not want to use this functionality, you can turn it off at any time.
162
 
163
- = Does the plugin support CDN? =
164
 
165
  Unfortunately not. This is due to the logic of the plugin's operation. Plugins that enable integration with the CDN servers modify the HTML of the website, changing URLs for media files. This plugin does not modify URLs. Replacing URLs in the HTML code is not an optimal solution.
166
 
@@ -172,7 +193,40 @@ Therefore in this plugin for browsers supporting the WebP format, only the sourc
172
 
173
  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.
174
 
175
- = Does the plugin work in Multisite Network? =
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
 
177
  Yes, with one exception. In this mode it is not possible to automatically generate the contents of .htaccess file.
178
 
@@ -200,58 +254,6 @@ Please manually paste the following code **at the beginning of .htaccess file**:
200
  </IfModule>`
201
  `# END WebP Converter`
202
 
203
- = How to get technical support? =
204
-
205
- We are happy to help you with any problem. Contact us about this matter.
206
-
207
- Please always adding your thread, read plugin FAQ and other threads in support forum first. Perhaps someone had a similar problem and it has been resolved.
208
-
209
- This will save time repeating the same issues many times and solving the same problems.
210
-
211
- If you do not find anything and you still have a problem, then contact us. So that we can better help you need additional information.
212
-
213
- When adding a thread, follow these steps and reply to each of them:
214
-
215
- **1.** Does your server meet the technical requirements described in the FAQ?
216
-
217
- **2.** Do you use CDN? If so, please see the question **"Does the plugin support CDN?"** in plugin FAQ.
218
-
219
- **3.** Do you use other plugins to optimize images? Please disable them and check this plugin without them. Remember not to combine several optimization plugins because they can be mutually exclusive.
220
-
221
- **4.** Check if in `/wp-content/uploads-webpc/` directory are all files that should be converted.
222
-
223
- If not, please enable `WP_DEBUG_LOG` in your `wp-config.php` *(more about debugging: [https://codex.wordpress.org/WP_DEBUG](https://codex.wordpress.org/WP_DEBUG))*. That's what you should have in this file:
224
-
225
- `define('WP_DEBUG', true);
226
- define('WP_DEBUG_LOG', true);
227
- define('WP_DEBUG_DISPLAY', false);`
228
-
229
- Then follow these steps:
230
-
231
- > 1. Go to administration panel and go to plugin settings page.
232
- 2. Run Google Chrome and enable Dev Tools *(F12)*.
233
- 3. Go to the Network tab and select filtering for `XHR` *(XHR and Fetch)*.
234
- 4. Click button `Regenerate All` on the plugin settings page *(do not close the console during this time)*.
235
- 5. Go to Dev Tools and find request that is marked in red. Click on them and go to `Preview` tab.
236
- 6. Take screenshot of all information presented there.
237
- 7. Please check also if you have any errors in `/wp-content/debug.log`?
238
-
239
- Send a screenshot from console if an error occurred while converting images. Of you have errors in `/wp-content/debug.log` send their?
240
-
241
- **5.** URL of your website. If your site is not publicly available, add it to test environment.
242
-
243
- **6.** Configuration of your server *(link to it can be found on the settings page of plugin in the **"We are waiting for your message"** section)* - please take a screenshot of the ENTIRE page and send it to me.
244
-
245
- Directly URL: `/wp-admin/options-general.php?page=webpc_admin_page&action=server`
246
-
247
- **7.** Content of your `.htaccess` file.
248
-
249
- **8.** What plugin version are you using? If it is not the latest then update and check everything again. Please also provide the version of WordPress and the list of plugins you use.
250
-
251
- Please remember to include the answers for all 8 questions by adding a thread. It is much easier and accelerate the solution of your problem.
252
-
253
- And most importantly - **do not leave the thread unanswered**. If you add a thread, follow when you get a reply. Then let us know if we have helped you or not. This helps us improve technical support.
254
-
255
  = Is the plugin completely free? =
256
 
257
  Yes. The plugin is completely free.
@@ -271,6 +273,10 @@ This is all very important to us and allows us to do even better things for you!
271
 
272
  == Changelog ==
273
 
 
 
 
 
274
  = 1.0.9 (2020-01-03) =
275
  * `[Added]` Limit of maximum image resolution limit using `GD` library
276
 
50
 
51
  == Frequently Asked Questions ==
52
 
53
+ = How to get technical support? (before you ask for help) =
54
 
55
+ We are happy to help you with any problem. Contact us about this matter.
56
 
57
+ Please always adding your thread, **read all other questions in the FAQ of plugin and other threads in support forum first**. Perhaps someone had a similar problem and it has been resolved.
58
 
59
+ This will save time repeating the same issues many times and solving the same problems.
60
 
61
+ If you do not find anything and you still have a problem, then contact us. So that we can better help you need additional information.
62
 
63
+ When adding a thread, follow these steps and reply to each of them:
64
 
65
+ **1.** Does your server meet the technical requirements described in the FAQ?
66
 
67
+ **2.** Do you use CDN? If so, please see the question **"Does the plugin support CDN?"** in plugin FAQ.
68
 
69
+ **3.** Do you use other plugins to optimize images? Please disable them and check this plugin without them. Remember not to combine several optimization plugins because they can be mutually exclusive.
70
 
71
+ **4.** Check if in `/wp-content/uploads-webpc/` directory are all files that should be converted.
72
 
73
+ If not, please enable `WP_DEBUG_LOG` in your `wp-config.php` *(more about debugging: [https://codex.wordpress.org/WP_DEBUG](https://codex.wordpress.org/WP_DEBUG))*. That's what you should have in this file:
 
74
 
75
+ `define('WP_DEBUG', true);
76
+ define('WP_DEBUG_LOG', true);
77
+ define('WP_DEBUG_DISPLAY', false);`
78
 
79
+ Then follow these steps:
80
 
81
+ > 1. Go to administration panel and go to plugin settings page.
82
+ 2. Run Google Chrome and enable Dev Tools *(F12)*.
83
+ 3. Go to the Network tab and select filtering for `XHR` *(XHR and Fetch)*.
84
+ 4. Click button `Regenerate All` on the plugin settings page *(do not close the console during this time)*.
85
+ 5. Go to Dev Tools and find request that is marked in red. Click on them and go to `Preview` tab.
86
+ 6. Take screenshot of all information presented there.
87
+ 7. Please check also if you have any errors in `/wp-content/debug.log`?
88
 
89
+ Send a screenshot from console if an error occurred while converting images. Of you have errors in `/wp-content/debug.log` send their?
90
 
91
+ **5.** URL of your website. If your site is not publicly available, add it to test environment.
 
92
 
93
+ **6.** Configuration of your server *(link to it can be found on the settings page of plugin in the section **"We are waiting for your message"**)* - please take a screenshot of the ENTIRE page and send it to me.
 
 
 
 
 
 
 
 
94
 
95
+ Directly the URL path: `/wp-admin/options-general.php?page=webpc_admin_page&action=server`
96
 
97
+ **7.** Content of your `.htaccess` file.
98
 
99
+ **8.** What plugin version are you using? If it is not the latest then update and check everything again. Please also provide the version of WordPress and the list of plugins you use.
100
+
101
+ Please remember to include the answers for all 8 questions by adding a thread. It is much easier and accelerate the solution of your problem.
102
+
103
+ And most importantly - **do not leave the thread unanswered**. If you add a thread, follow when you get a reply. Then let us know if we have helped you or not. This helps us improve technical support.
104
 
105
+ = What are requirements of plugin? =
106
 
107
+ Practically every hosting meets these requirements. You must use PHP at least 7.0 and have the `GD` or `Imagick` extension installed. **The extension must support `WebP format`.**
108
+
109
+ They are required 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.
110
+
111
+ Also REST API must be enabled and work without additional restrictions.
112
+
113
+ An example of the correct server configuration can be found [here](https://gbiorczyk.pl/webp-converter/serverinfo.png). Link to your current configuration can be found in the administration panel, on the management plugin page in the section **"We are waiting for your message"** *(or using the URL path: `/wp-admin/options-general.php?page=webpc_admin_page&action=server`)*.
114
+
115
+ **Note the items marked in red.** If your server does not meet the technical requirements, please contact your server Administrator.
116
+
117
+ 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.
118
+
119
+ = What are restrictions? =
120
 
121
  The size of the image is a limited. Its resolution cannot be bigger than `8192 x 8192px`. This is due to the limitations of the PHP library.
122
 
124
 
125
  You can find more about WebP support by browsers [here](https://caniuse.com/#feat=webp).
126
 
127
+ = How can I convert existing images after installing? =
128
+
129
+ In the WordPress admin panel, on the `Settings -> WebP Converter` subpage there is a module that allows you to process all your images.
130
+
131
+ It uses the WordPress REST API by downloading addresses of all images and converting all files gradually.
132
+
133
+ This process may take few or more than ten minutes depending on the number of files. **It should be done once after installing the plugin.** Then all added images will be automatically regerated.
134
+
135
+ = How to check if plugin works? =
136
+
137
+ When you have installed plugin and converted all images, follow these steps:
138
+
139
+ 1. Run `Google Chrome` and enable `Dev Tools` *(F12)*.
140
+ 2. Go to the `Network` tab and select filtering for `Img` *(Images)*.
141
+ 3. Refresh your website page.
142
+ 4. Check list of loaded images. Note `Type` column.
143
+ 5. If value of `webp` is there, then everything works fine.
144
+ 6. Remember that this plugin does not change URLs. This means that e.g. link will have path to .jpg file, but `.jpg.webp file will be loaded instead of original .jpg`.
145
+ 7. In addition, you can check weight of website before and after using plugin. The difference will be huge!
146
+ 8. More information: [here](https://gbiorczyk.pl/webp-converter/check-devtools.png)
147
+
148
+ Please remember that if the converted image in WebP format is larger than the original, the browser will use the original file. Therefore, you can also see files other than WebP on the list.
149
+
150
+ = Where are converted images stored? =
151
 
152
  All WebP images are stored in the `/wp-content/uploads-webpc/` directory. Inside the directory there is the same structure as in the original `uploads` directory. The files have original extensions in the name along with the new `.webp`.
153
 
175
 
176
  Then go to `Settings -> WebP Converter` in the admin panel and click the `Save Changes` button. Also remember to regenerate all images using the `Regenerate All` button.
177
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
178
  = Can I enable browser caching for WebP images? =
179
 
180
  Yes of course. The plugin allows this by using the module `mod_expires`. Thanks to this, we can even speed up page loading time for returning users because they do not need to re-download files from the server.
181
 
182
  If you do not want to use this functionality, you can turn it off at any time.
183
 
184
+ = Does plugin support CDN? =
185
 
186
  Unfortunately not. This is due to the logic of the plugin's operation. Plugins that enable integration with the CDN servers modify the HTML of the website, changing URLs for media files. This plugin does not modify URLs. Replacing URLs in the HTML code is not an optimal solution.
187
 
193
 
194
  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.
195
 
196
+ = Configuration for Nginx =
197
+
198
+ Please edit the configuration file:
199
+
200
+ `/etc/nginx/mime.types`
201
+
202
+ and add this code:
203
+
204
+ `types {`
205
+ ` # ...
206
+
207
+ image/webp webp;
208
+ }`
209
+
210
+ Then please find your configuration file in the path *(default is default file)*:
211
+
212
+ `/etc/nginx/sites-available/`
213
+
214
+ and add below code in this file:
215
+
216
+ `server {`
217
+ ` # ...
218
+
219
+ location ~ (?<root>.+)/uploads/(?<path>.+)\.(?<ext>jp?g|png|gif)$ {
220
+ if ($http_accept !~* "image/webp") {
221
+ break;
222
+ }
223
+ add_header Vary Accept;
224
+ expires 365d;
225
+ try_files $root/uploads-webpc/$path.$ext.webp $uri =404;
226
+ }
227
+ }`
228
+
229
+ = Configuration for Multisite Network =
230
 
231
  Yes, with one exception. In this mode it is not possible to automatically generate the contents of .htaccess file.
232
 
254
  </IfModule>`
255
  `# END WebP Converter`
256
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
257
  = Is the plugin completely free? =
258
 
259
  Yes. The plugin is completely free.
273
 
274
  == Changelog ==
275
 
276
+ = 1.1.0 (2020-02-10) =
277
+ * `[Fixed]` Support for WordPress installation in subdirectory
278
+ * `[Fixed]` Error detecting WebP support by Imagick
279
+
280
  = 1.0.9 (2020-01-03) =
281
  * `[Added]` Limit of maximum image resolution limit using `GD` library
282
 
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.9
7
  Author: Mateusz Gbiorczyk
8
  Author URI: https://gbiorczyk.pl/
9
  Text Domain: webp-converter
10
  */
11
 
12
- define('WEBPC_VERSION', '1.0.9');
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.1.0
7
  Author: Mateusz Gbiorczyk
8
  Author URI: https://gbiorczyk.pl/
9
  Text Domain: webp-converter
10
  */
11
 
12
+ define('WEBPC_VERSION', '1.1.0');
13
  define('WEBPC_FILE', __FILE__);
14
  define('WEBPC_NAME', plugin_basename(__FILE__));
15
  define('WEBPC_PATH', plugin_dir_path(__FILE__));