Version Description
(released 4 May 2022) * AlterHTML did not skip existing picture tags when they contained newlines, resulting in picture tags inside picture tags, which is invalid markup. Thanks to Jonas for being very helpful in solving this.
Download this release
Release Info
Developer | rosell.dk |
Plugin | WebP Express |
Version | 0.25.2 |
Comparing to | |
See all releases |
Code changes from version 0.25.1 to 0.25.2
- README.txt +22 -13
- changelog.txt +6 -2
- composer.json +7 -2
- docs/development.md +10 -1
- docs/publishing.md +4 -2
- lib/classes/AlterHtmlHelper.php +1 -0
- lib/classes/AlterHtmlPicture.php +2 -0
- lib/classes/ConvertHelperIndependent.php +1 -1
- lib/options/options/alter-html/alter-html-options.inc +1 -1
- vendor/autoload.php +5 -0
- vendor/composer/ClassLoader.php +1 -1
- vendor/composer/InstalledVersions.php +2 -0
- vendor/composer/autoload_classmap.php +2 -1
- vendor/composer/autoload_namespaces.php +1 -1
- vendor/composer/autoload_psr4.php +1 -1
- vendor/composer/autoload_real.php +3 -22
- vendor/composer/autoload_static.php +1 -0
- vendor/composer/installed.json +22 -21
- vendor/composer/installed.php +11 -11
- vendor/rosell-dk/dom-util-for-webp/README.md +1 -2
- vendor/rosell-dk/dom-util-for-webp/composer.json +6 -3
- vendor/rosell-dk/dom-util-for-webp/phpcs-ruleset.xml +8 -0
- vendor/rosell-dk/dom-util-for-webp/phpstan.neon +0 -3
- vendor/rosell-dk/dom-util-for-webp/phpunit.xml.dist +0 -17
- vendor/rosell-dk/dom-util-for-webp/src/ImageUrlReplacer.php +6 -2
- vendor/rosell-dk/dom-util-for-webp/src/PictureTags.php +12 -10
- vendor/rosell-dk/exec-with-fallback/README.md +10 -3
- vendor/rosell-dk/exec-with-fallback/src/Availability.php +1 -1
- vendor/rosell-dk/exec-with-fallback/src/ExecWithFallback.php +56 -5
- vendor/rosell-dk/exec-with-fallback/src/ExecWithFallbackNoMercy.php +56 -0
- vendor/rosell-dk/exec-with-fallback/src/ShellExec.php +2 -4
- vendor/rosell-dk/webp-convert/README.md +8 -8
- vendor/rosell-dk/webp-convert/docs/development.md +0 -79
- vendor/rosell-dk/webp-convert/docs/v1.3/converting/convert-options.md +0 -322
- vendor/rosell-dk/webp-convert/docs/v1.3/converting/convert.md +0 -96
- vendor/rosell-dk/webp-convert/docs/v1.3/converting/converters.md +0 -322
- vendor/rosell-dk/webp-convert/docs/v1.3/serving/convert-and-serve.md +0 -167
- vendor/rosell-dk/webp-convert/docs/v1.3/webp-on-demand/tweaks.md +0 -167
- vendor/rosell-dk/webp-convert/docs/v1.3/webp-on-demand/webp-on-demand.md +0 -133
- vendor/rosell-dk/webp-convert/docs/v1.3/webp-on-demand/without-composer.md +0 -45
- vendor/rosell-dk/webp-convert/docs/v2.0/converting/architecture-q50-w600.jpg +0 -0
- vendor/rosell-dk/webp-convert/docs/v2.0/converting/converters/stack.md +0 -248
- vendor/rosell-dk/webp-convert/docs/v2.0/converting/dice.png +0 -0
- vendor/rosell-dk/webp-convert/docs/v2.0/converting/introduction-for-converting.md +0 -251
- vendor/rosell-dk/webp-convert/docs/v2.0/converting/mouse-q100.jpg +0 -0
- vendor/rosell-dk/webp-convert/docs/v2.0/converting/options.md +0 -403
- vendor/rosell-dk/webp-convert/docs/v2.0/installing-converters/cwebp.md +0 -3
- vendor/rosell-dk/webp-convert/docs/v2.0/installing-converters/ffmpeg.md +0 -15
- vendor/rosell-dk/webp-convert/docs/v2.0/installing-converters/gd.md +0 -19
- vendor/rosell-dk/webp-convert/docs/v2.0/installing-converters/gmagick-extension.md +0 -40
- vendor/rosell-dk/webp-convert/docs/v2.0/installing-converters/imagick-extension.md +0 -80
- vendor/rosell-dk/webp-convert/docs/v2.0/installing-converters/vips.md +0 -35
- vendor/rosell-dk/webp-convert/docs/v2.0/migrating-to-2.0.md +0 -73
- vendor/rosell-dk/webp-convert/docs/v2.0/serving/introduction-for-serving.md +0 -157
- vendor/rosell-dk/webp-convert/docs/v2.0/serving/laravel-nginx-serving.md +0 -116
- vendor/rosell-dk/webp-convert/docs/v2.0/webp-on-demand/tweaks.md +0 -181
- vendor/rosell-dk/webp-convert/docs/v2.0/webp-on-demand/webp-on-demand.md +0 -145
- vendor/rosell-dk/webp-convert/docs/v2.0/webp-on-demand/without-composer.md +0 -58
- vendor/rosell-dk/webp-convert/src/Convert/Converters/Cwebp.php +2 -2
- vendor/rosell-dk/webp-convert/src/Helpers/SanityCheck.txt +0 -255
- webp-express.php +1 -1
README.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: https://ko-fi.com/rosell
|
|
4 |
Tags: webp, images, performance
|
5 |
Requires at least: 4.0
|
6 |
Tested up to: 5.8
|
7 |
-
Stable tag: 0.25.
|
8 |
Requires PHP: 5.6
|
9 |
License: GPLv3
|
10 |
License URI: https://www.gnu.org/licenses/gpl-3.0.html
|
@@ -171,18 +171,16 @@ Bread on the table don't come for free, even though this plugin does, and always
|
|
171 |
|
172 |
== Supporters of WebP Express ==
|
173 |
|
174 |
-
**Persons currently backing the project via GitHub Sponsors or patreon - Thanks!**
|
175 |
-
|
176 |
-
* Max Kreminsky
|
177 |
-
* [Mathieu Gollain-Dupont](https://www.linkedin.com/in/mathieu-gollain-dupont-9938a4a/)
|
178 |
-
* Ruben Solvang
|
179 |
-
|
180 |
**Persons who recently contributed with [ko-fi](https://ko-fi.com/rosell) - Thanks!**
|
181 |
-
* 3
|
182 |
-
*
|
183 |
-
*
|
184 |
-
*
|
185 |
-
*
|
|
|
|
|
|
|
|
|
186 |
|
187 |
**Persons who contributed with extra generously amounts of coffee / lifetime backing (>30$) - thanks!:**
|
188 |
|
@@ -196,6 +194,10 @@ Bread on the table don't come for free, even though this plugin does, and always
|
|
196 |
* Erica Dreisbach ($50)
|
197 |
* Brian Laursen ($50)
|
198 |
|
|
|
|
|
|
|
|
|
199 |
== Frequently Asked Questions ==
|
200 |
|
201 |
= How do I verify that the plugin is working? =
|
@@ -253,7 +255,7 @@ Easy enough. Browsers looks at the *content type* header rather than the URL to
|
|
253 |
|
254 |
I am btw considering making an option to have the plugin redirect to the webp instead of serving immediately. That would remove the apparent mismatch between file extension and content type header. However, the cost of doing that will be an extra request for each image, which means extra time and worse performance. I believe you'd be ill advised to use that option, so I guess I will not implement it. But perhaps you have good reasons to use it? If you do, please let me know!
|
255 |
|
256 |
-
=
|
257 |
Well, first, if you don't know WP CLI, here is a [quick start](https://make.wordpress.org/cli/handbook/guides/quick-start/)
|
258 |
|
259 |
WebP Express currently supports commands for converting and flushing webp images throug the CLI. You can use the --help option to learn about the options:
|
@@ -814,6 +816,10 @@ If you want to make sure that my coffee supplies don't run dry, you can even buy
|
|
814 |
|
815 |
== Changelog ==
|
816 |
|
|
|
|
|
|
|
|
|
817 |
= 0.25.1 =
|
818 |
(released 7 dec 2021)
|
819 |
* An innocent text file triggered Windows Defender. It has been removed. Thanks to Javad Naroogheh from Iran for notifying
|
@@ -911,6 +917,9 @@ For older releases, check out changelog.txt
|
|
911 |
|
912 |
== Upgrade Notice ==
|
913 |
|
|
|
|
|
|
|
914 |
= 0.25.1 =
|
915 |
* An innocent text file was triggering Windows Defender.
|
916 |
|
4 |
Tags: webp, images, performance
|
5 |
Requires at least: 4.0
|
6 |
Tested up to: 5.8
|
7 |
+
Stable tag: 0.25.2
|
8 |
Requires PHP: 5.6
|
9 |
License: GPLv3
|
10 |
License URI: https://www.gnu.org/licenses/gpl-3.0.html
|
171 |
|
172 |
== Supporters of WebP Express ==
|
173 |
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
**Persons who recently contributed with [ko-fi](https://ko-fi.com/rosell) - Thanks!**
|
175 |
+
* 3 May: Jonas
|
176 |
+
* 27 Apr: Jonas
|
177 |
+
* 7 Apr: Anuar
|
178 |
+
* 30 Mar: Michael Schober
|
179 |
+
* 17 Mar: bluesix
|
180 |
+
* 13 Mar: Troglos
|
181 |
+
* 25 Feb: ItAdmin
|
182 |
+
* 31 Jan: MB
|
183 |
+
* 16 Dec: deepa
|
184 |
|
185 |
**Persons who contributed with extra generously amounts of coffee / lifetime backing (>30$) - thanks!:**
|
186 |
|
194 |
* Erica Dreisbach ($50)
|
195 |
* Brian Laursen ($50)
|
196 |
|
197 |
+
**Persons currently backing the project via GitHub Sponsors or patreon - Thanks!**
|
198 |
+
|
199 |
+
* [Mathieu Gollain-Dupont](https://www.linkedin.com/in/mathieu-gollain-dupont-9938a4a/)
|
200 |
+
|
201 |
== Frequently Asked Questions ==
|
202 |
|
203 |
= How do I verify that the plugin is working? =
|
255 |
|
256 |
I am btw considering making an option to have the plugin redirect to the webp instead of serving immediately. That would remove the apparent mismatch between file extension and content type header. However, the cost of doing that will be an extra request for each image, which means extra time and worse performance. I believe you'd be ill advised to use that option, so I guess I will not implement it. But perhaps you have good reasons to use it? If you do, please let me know!
|
257 |
|
258 |
+
= WP CLI, but how do I use it to bulk convert? =
|
259 |
Well, first, if you don't know WP CLI, here is a [quick start](https://make.wordpress.org/cli/handbook/guides/quick-start/)
|
260 |
|
261 |
WebP Express currently supports commands for converting and flushing webp images throug the CLI. You can use the --help option to learn about the options:
|
816 |
|
817 |
== Changelog ==
|
818 |
|
819 |
+
= 0.25.2 =
|
820 |
+
(released 4 May 2022)
|
821 |
+
* AlterHTML did not skip existing picture tags when they contained newlines, resulting in picture tags inside picture tags, which is invalid markup. Thanks to Jonas for being very helpful in solving this.
|
822 |
+
|
823 |
= 0.25.1 =
|
824 |
(released 7 dec 2021)
|
825 |
* An innocent text file triggered Windows Defender. It has been removed. Thanks to Javad Naroogheh from Iran for notifying
|
917 |
|
918 |
== Upgrade Notice ==
|
919 |
|
920 |
+
= 0.25.2 =
|
921 |
+
* Fixed bug in Alter HTML functionality. It did not skip existing picture tags when they contained newlines, resulting in picture tags inside picture tags
|
922 |
+
|
923 |
= 0.25.1 =
|
924 |
* An innocent text file was triggering Windows Defender.
|
925 |
|
changelog.txt
CHANGED
@@ -1,9 +1,13 @@
|
|
|
|
|
|
|
|
|
|
1 |
= 0.25.1 =
|
2 |
-
(released 7
|
3 |
* An innocent text file triggered Windows Defender. It has been removed. Thanks to Javad Naroogheh from Iran for notifying
|
4 |
|
5 |
= 0.25.0 =
|
6 |
-
(released 7
|
7 |
* No exec()? - We don't give up easily, but now emulates it if possible, using proc_open(), passthru() or other alternatives. The result is that the cwebp converter now is available on more systems. Quality detection of jpegs also works on more systems now. The fallback feature with the emulations is btw implemented in a new library, [exec-with-fallback](https://github.com/rosell-dk/exec-with-fallback)
|
8 |
* Bugfix: Our WP CLI command "webp-express" has a quality option, but it was not working
|
9 |
|
1 |
+
= 0.25.2 =
|
2 |
+
(released 4 May 2022)
|
3 |
+
* AlterHTML did not skip existing picture tags when they contained newlines, resulting in picture tags inside picture tags, which is invalid markup. Thanks to Jonas for being very helpful in solving this.
|
4 |
+
|
5 |
= 0.25.1 =
|
6 |
+
(released 7 Dec 2021)
|
7 |
* An innocent text file triggered Windows Defender. It has been removed. Thanks to Javad Naroogheh from Iran for notifying
|
8 |
|
9 |
= 0.25.0 =
|
10 |
+
(released 7 Dec 2021, on my daughters 10 year birthday!)
|
11 |
* No exec()? - We don't give up easily, but now emulates it if possible, using proc_open(), passthru() or other alternatives. The result is that the cwebp converter now is available on more systems. Quality detection of jpegs also works on more systems now. The fallback feature with the emulations is btw implemented in a new library, [exec-with-fallback](https://github.com/rosell-dk/exec-with-fallback)
|
12 |
* Bugfix: Our WP CLI command "webp-express" has a quality option, but it was not working
|
13 |
|
composer.json
CHANGED
@@ -7,7 +7,7 @@
|
|
7 |
"composer/installers": "^1.12.0",
|
8 |
"rosell-dk/webp-convert": "^2.9.0",
|
9 |
"rosell-dk/webp-convert-cloud-service": "^2.0.0",
|
10 |
-
"rosell-dk/dom-util-for-webp": "^0.
|
11 |
"rosell-dk/htaccess-capability-tester": "^0.9.0",
|
12 |
"rosell-dk/image-mime-type-guesser": "^0.4.0"
|
13 |
},
|
@@ -25,5 +25,10 @@
|
|
25 |
"homepage": "https://www.bitwise-it.dk/contact",
|
26 |
"role": "Project Author"
|
27 |
}
|
28 |
-
]
|
|
|
|
|
|
|
|
|
|
|
29 |
}
|
7 |
"composer/installers": "^1.12.0",
|
8 |
"rosell-dk/webp-convert": "^2.9.0",
|
9 |
"rosell-dk/webp-convert-cloud-service": "^2.0.0",
|
10 |
+
"rosell-dk/dom-util-for-webp": "^0.6.0",
|
11 |
"rosell-dk/htaccess-capability-tester": "^0.9.0",
|
12 |
"rosell-dk/image-mime-type-guesser": "^0.4.0"
|
13 |
},
|
25 |
"homepage": "https://www.bitwise-it.dk/contact",
|
26 |
"role": "Project Author"
|
27 |
}
|
28 |
+
],
|
29 |
+
"config": {
|
30 |
+
"allow-plugins": {
|
31 |
+
"composer/installers": true
|
32 |
+
}
|
33 |
+
}
|
34 |
}
|
docs/development.md
CHANGED
@@ -13,7 +13,6 @@ It actually seems that the mappings are not needed. It seems to work fine when I
|
|
13 |
```
|
14 |
rm -r vendor/rosell-dk/webp-convert/docs
|
15 |
rm -r vendor/rosell-dk/webp-convert/src/Helpers/*.txt
|
16 |
-
rm vendor/rosell-dk/dom-util-for-webp/phpstan.neon
|
17 |
rm composer.lock
|
18 |
rmdir vendor/bin
|
19 |
```
|
@@ -100,3 +99,13 @@ if [ $1 = "rsync-wc" ]; then
|
|
100 |
rsyncwc
|
101 |
fi
|
102 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
```
|
14 |
rm -r vendor/rosell-dk/webp-convert/docs
|
15 |
rm -r vendor/rosell-dk/webp-convert/src/Helpers/*.txt
|
|
|
16 |
rm composer.lock
|
17 |
rmdir vendor/bin
|
18 |
```
|
99 |
rsyncwc
|
100 |
fi
|
101 |
```
|
102 |
+
|
103 |
+
# Instruction for installing development version, for non-developers :)
|
104 |
+
|
105 |
+
To install the development version:
|
106 |
+
1) Go to https://wordpress.org/plugins/webp-express/advanced/
|
107 |
+
2) Find the place where it says “Please select a specific version to download”
|
108 |
+
3) Click “Download”
|
109 |
+
4) Browse to /wp-admin/plugin-install.php (ie by going to the the Plugins page and clicking “Add new” button in the top)
|
110 |
+
5) Click “Upload plugin” (button found in the top)
|
111 |
+
6) The rest is easy
|
docs/publishing.md
CHANGED
@@ -61,6 +61,8 @@ And then:
|
|
61 |
cd /var/www/we/svn
|
62 |
svn up
|
63 |
```
|
|
|
|
|
64 |
|
65 |
If you have deleted folders (check with rsync --dry-run), then do this:
|
66 |
```
|
@@ -114,12 +116,12 @@ svn status | grep '^!' | awk '{print $2}' | xargs svn delete --force (t
|
|
114 |
Then add a new tag
|
115 |
```
|
116 |
cd svn
|
117 |
-
svn cp trunk tags/0.25.
|
118 |
```
|
119 |
|
120 |
And commit!
|
121 |
```
|
122 |
-
svn ci -m '0.25.
|
123 |
```
|
124 |
|
125 |
|
61 |
cd /var/www/we/svn
|
62 |
svn up
|
63 |
```
|
64 |
+
PS: On a new computer? - checkout first: `svn co http://plugins.svn.wordpress.org/webp-express/``
|
65 |
+
|
66 |
|
67 |
If you have deleted folders (check with rsync --dry-run), then do this:
|
68 |
```
|
116 |
Then add a new tag
|
117 |
```
|
118 |
cd svn
|
119 |
+
svn cp trunk tags/0.25.1 (this will copy trunk into a new tag)
|
120 |
```
|
121 |
|
122 |
And commit!
|
123 |
```
|
124 |
+
svn ci -m '0.25.1'
|
125 |
```
|
126 |
|
127 |
|
lib/classes/AlterHtmlHelper.php
CHANGED
@@ -314,6 +314,7 @@ class AlterHtmlHelper
|
|
314 |
break;
|
315 |
}
|
316 |
|
|
|
317 |
//error_log('source url:' . $sourceUrl);
|
318 |
|
319 |
// Try all image roots
|
314 |
break;
|
315 |
}
|
316 |
|
317 |
+
|
318 |
//error_log('source url:' . $sourceUrl);
|
319 |
|
320 |
// Try all image roots
|
lib/classes/AlterHtmlPicture.php
CHANGED
@@ -13,6 +13,8 @@ use DOMUtilForWebP\PictureTags;
|
|
13 |
class AlterHtmlPicture extends PictureTags
|
14 |
{
|
15 |
public function replaceUrl($url) {
|
|
|
|
|
16 |
return AlterHtmlHelper::getWebPUrl($url, null);
|
17 |
}
|
18 |
}
|
13 |
class AlterHtmlPicture extends PictureTags
|
14 |
{
|
15 |
public function replaceUrl($url) {
|
16 |
+
return $url . '.webp';
|
17 |
+
//return $url . '.webp:' . AlterHtmlHelper::getWebPUrl($url, null) . ':' . $url;
|
18 |
return AlterHtmlHelper::getWebPUrl($url, null);
|
19 |
}
|
20 |
}
|
lib/classes/ConvertHelperIndependent.php
CHANGED
@@ -571,7 +571,7 @@ APACHE
|
|
571 |
$text = preg_replace('#' . preg_quote($_SERVER["DOCUMENT_ROOT"]) . '#', '[doc-root]', $text);
|
572 |
|
573 |
// TODO: Put version number somewhere else. Ie \WebPExpress\VersionNumber::version
|
574 |
-
$text = 'WebP Express 0.25.
|
575 |
|
576 |
$logFile = self::getLogFilename($source, $logDir);
|
577 |
|
571 |
$text = preg_replace('#' . preg_quote($_SERVER["DOCUMENT_ROOT"]) . '#', '[doc-root]', $text);
|
572 |
|
573 |
// TODO: Put version number somewhere else. Ie \WebPExpress\VersionNumber::version
|
574 |
+
$text = 'WebP Express 0.25.2. ' . $msgTop . ', ' . date("Y-m-d H:i:s") . "\n\r\n\r" . $text;
|
575 |
|
576 |
$logFile = self::getLogFilename($source, $logDir);
|
577 |
|
lib/options/options/alter-html/alter-html-options.inc
CHANGED
@@ -123,7 +123,7 @@ namespace WebPExpress;
|
|
123 |
'If you enable this option, a small script will be added which detects if picture tags are supported and loads ' .
|
124 |
'<a href="https://github.com/scottjehl/picturefill" target="_blank">picturefill.js</a> if not. ' .
|
125 |
'It is recommended to activate this option, unless your theme or another plugin adds such a script. ' .
|
126 |
-
'Picture tag support is currently <a href="https://caniuse.com/#feat=picture" target="_blank">~
|
127 |
);
|
128 |
?>
|
129 |
</div></li>
|
123 |
'If you enable this option, a small script will be added which detects if picture tags are supported and loads ' .
|
124 |
'<a href="https://github.com/scottjehl/picturefill" target="_blank">picturefill.js</a> if not. ' .
|
125 |
'It is recommended to activate this option, unless your theme or another plugin adds such a script. ' .
|
126 |
+
'Picture tag support is currently <a href="https://caniuse.com/#feat=picture" target="_blank">~94%</a>'
|
127 |
);
|
128 |
?>
|
129 |
</div></li>
|
vendor/autoload.php
CHANGED
@@ -2,6 +2,11 @@
|
|
2 |
|
3 |
// autoload.php @generated by Composer
|
4 |
|
|
|
|
|
|
|
|
|
|
|
5 |
require_once __DIR__ . '/composer/autoload_real.php';
|
6 |
|
7 |
return ComposerAutoloaderInit16597e36dd1bfcd787ed5a8e6d908243::getLoader();
|
2 |
|
3 |
// autoload.php @generated by Composer
|
4 |
|
5 |
+
if (PHP_VERSION_ID < 50600) {
|
6 |
+
echo 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL;
|
7 |
+
exit(1);
|
8 |
+
}
|
9 |
+
|
10 |
require_once __DIR__ . '/composer/autoload_real.php';
|
11 |
|
12 |
return ComposerAutoloaderInit16597e36dd1bfcd787ed5a8e6d908243::getLoader();
|
vendor/composer/ClassLoader.php
CHANGED
@@ -149,7 +149,7 @@ class ClassLoader
|
|
149 |
|
150 |
/**
|
151 |
* @return string[] Array of classname => path
|
152 |
-
* @psalm-
|
153 |
*/
|
154 |
public function getClassMap()
|
155 |
{
|
149 |
|
150 |
/**
|
151 |
* @return string[] Array of classname => path
|
152 |
+
* @psalm-return array<string, string>
|
153 |
*/
|
154 |
public function getClassMap()
|
155 |
{
|
vendor/composer/InstalledVersions.php
CHANGED
@@ -21,6 +21,8 @@ use Composer\Semver\VersionParser;
|
|
21 |
* See also https://getcomposer.org/doc/07-runtime.md#installed-versions
|
22 |
*
|
23 |
* To require its presence, you can require `composer-runtime-api ^2.0`
|
|
|
|
|
24 |
*/
|
25 |
class InstalledVersions
|
26 |
{
|
21 |
* See also https://getcomposer.org/doc/07-runtime.md#installed-versions
|
22 |
*
|
23 |
* To require its presence, you can require `composer-runtime-api ^2.0`
|
24 |
+
*
|
25 |
+
* @final
|
26 |
*/
|
27 |
class InstalledVersions
|
28 |
{
|
vendor/composer/autoload_classmap.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
// autoload_classmap.php @generated by Composer
|
4 |
|
5 |
-
$vendorDir = dirname(
|
6 |
$baseDir = dirname($vendorDir);
|
7 |
|
8 |
return array(
|
@@ -113,6 +113,7 @@ return array(
|
|
113 |
'DOMUtilForWebP\\PictureTags' => $vendorDir . '/rosell-dk/dom-util-for-webp/src/PictureTags.php',
|
114 |
'ExecWithFallback\\Availability' => $vendorDir . '/rosell-dk/exec-with-fallback/src/Availability.php',
|
115 |
'ExecWithFallback\\ExecWithFallback' => $vendorDir . '/rosell-dk/exec-with-fallback/src/ExecWithFallback.php',
|
|
|
116 |
'ExecWithFallback\\POpen' => $vendorDir . '/rosell-dk/exec-with-fallback/src/POpen.php',
|
117 |
'ExecWithFallback\\Passthru' => $vendorDir . '/rosell-dk/exec-with-fallback/src/Passthru.php',
|
118 |
'ExecWithFallback\\ProcOpen' => $vendorDir . '/rosell-dk/exec-with-fallback/src/ProcOpen.php',
|
2 |
|
3 |
// autoload_classmap.php @generated by Composer
|
4 |
|
5 |
+
$vendorDir = dirname(__DIR__);
|
6 |
$baseDir = dirname($vendorDir);
|
7 |
|
8 |
return array(
|
113 |
'DOMUtilForWebP\\PictureTags' => $vendorDir . '/rosell-dk/dom-util-for-webp/src/PictureTags.php',
|
114 |
'ExecWithFallback\\Availability' => $vendorDir . '/rosell-dk/exec-with-fallback/src/Availability.php',
|
115 |
'ExecWithFallback\\ExecWithFallback' => $vendorDir . '/rosell-dk/exec-with-fallback/src/ExecWithFallback.php',
|
116 |
+
'ExecWithFallback\\ExecWithFallbackNoMercy' => $vendorDir . '/rosell-dk/exec-with-fallback/src/ExecWithFallbackNoMercy.php',
|
117 |
'ExecWithFallback\\POpen' => $vendorDir . '/rosell-dk/exec-with-fallback/src/POpen.php',
|
118 |
'ExecWithFallback\\Passthru' => $vendorDir . '/rosell-dk/exec-with-fallback/src/Passthru.php',
|
119 |
'ExecWithFallback\\ProcOpen' => $vendorDir . '/rosell-dk/exec-with-fallback/src/ProcOpen.php',
|
vendor/composer/autoload_namespaces.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
// autoload_namespaces.php @generated by Composer
|
4 |
|
5 |
-
$vendorDir = dirname(
|
6 |
$baseDir = dirname($vendorDir);
|
7 |
|
8 |
return array(
|
2 |
|
3 |
// autoload_namespaces.php @generated by Composer
|
4 |
|
5 |
+
$vendorDir = dirname(__DIR__);
|
6 |
$baseDir = dirname($vendorDir);
|
7 |
|
8 |
return array(
|
vendor/composer/autoload_psr4.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
// autoload_psr4.php @generated by Composer
|
4 |
|
5 |
-
$vendorDir = dirname(
|
6 |
$baseDir = dirname($vendorDir);
|
7 |
|
8 |
return array(
|
2 |
|
3 |
// autoload_psr4.php @generated by Composer
|
4 |
|
5 |
+
$vendorDir = dirname(__DIR__);
|
6 |
$baseDir = dirname($vendorDir);
|
7 |
|
8 |
return array(
|
vendor/composer/autoload_real.php
CHANGED
@@ -25,30 +25,11 @@ class ComposerAutoloaderInit16597e36dd1bfcd787ed5a8e6d908243
|
|
25 |
require __DIR__ . '/platform_check.php';
|
26 |
|
27 |
spl_autoload_register(array('ComposerAutoloaderInit16597e36dd1bfcd787ed5a8e6d908243', 'loadClassLoader'), true, true);
|
28 |
-
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(
|
29 |
spl_autoload_unregister(array('ComposerAutoloaderInit16597e36dd1bfcd787ed5a8e6d908243', 'loadClassLoader'));
|
30 |
|
31 |
-
|
32 |
-
|
33 |
-
require __DIR__ . '/autoload_static.php';
|
34 |
-
|
35 |
-
call_user_func(\Composer\Autoload\ComposerStaticInit16597e36dd1bfcd787ed5a8e6d908243::getInitializer($loader));
|
36 |
-
} else {
|
37 |
-
$map = require __DIR__ . '/autoload_namespaces.php';
|
38 |
-
foreach ($map as $namespace => $path) {
|
39 |
-
$loader->set($namespace, $path);
|
40 |
-
}
|
41 |
-
|
42 |
-
$map = require __DIR__ . '/autoload_psr4.php';
|
43 |
-
foreach ($map as $namespace => $path) {
|
44 |
-
$loader->setPsr4($namespace, $path);
|
45 |
-
}
|
46 |
-
|
47 |
-
$classMap = require __DIR__ . '/autoload_classmap.php';
|
48 |
-
if ($classMap) {
|
49 |
-
$loader->addClassMap($classMap);
|
50 |
-
}
|
51 |
-
}
|
52 |
|
53 |
$loader->register(true);
|
54 |
|
25 |
require __DIR__ . '/platform_check.php';
|
26 |
|
27 |
spl_autoload_register(array('ComposerAutoloaderInit16597e36dd1bfcd787ed5a8e6d908243', 'loadClassLoader'), true, true);
|
28 |
+
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
29 |
spl_autoload_unregister(array('ComposerAutoloaderInit16597e36dd1bfcd787ed5a8e6d908243', 'loadClassLoader'));
|
30 |
|
31 |
+
require __DIR__ . '/autoload_static.php';
|
32 |
+
call_user_func(\Composer\Autoload\ComposerStaticInit16597e36dd1bfcd787ed5a8e6d908243::getInitializer($loader));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
$loader->register(true);
|
35 |
|
vendor/composer/autoload_static.php
CHANGED
@@ -183,6 +183,7 @@ class ComposerStaticInit16597e36dd1bfcd787ed5a8e6d908243
|
|
183 |
'DOMUtilForWebP\\PictureTags' => __DIR__ . '/..' . '/rosell-dk/dom-util-for-webp/src/PictureTags.php',
|
184 |
'ExecWithFallback\\Availability' => __DIR__ . '/..' . '/rosell-dk/exec-with-fallback/src/Availability.php',
|
185 |
'ExecWithFallback\\ExecWithFallback' => __DIR__ . '/..' . '/rosell-dk/exec-with-fallback/src/ExecWithFallback.php',
|
|
|
186 |
'ExecWithFallback\\POpen' => __DIR__ . '/..' . '/rosell-dk/exec-with-fallback/src/POpen.php',
|
187 |
'ExecWithFallback\\Passthru' => __DIR__ . '/..' . '/rosell-dk/exec-with-fallback/src/Passthru.php',
|
188 |
'ExecWithFallback\\ProcOpen' => __DIR__ . '/..' . '/rosell-dk/exec-with-fallback/src/ProcOpen.php',
|
183 |
'DOMUtilForWebP\\PictureTags' => __DIR__ . '/..' . '/rosell-dk/dom-util-for-webp/src/PictureTags.php',
|
184 |
'ExecWithFallback\\Availability' => __DIR__ . '/..' . '/rosell-dk/exec-with-fallback/src/Availability.php',
|
185 |
'ExecWithFallback\\ExecWithFallback' => __DIR__ . '/..' . '/rosell-dk/exec-with-fallback/src/ExecWithFallback.php',
|
186 |
+
'ExecWithFallback\\ExecWithFallbackNoMercy' => __DIR__ . '/..' . '/rosell-dk/exec-with-fallback/src/ExecWithFallbackNoMercy.php',
|
187 |
'ExecWithFallback\\POpen' => __DIR__ . '/..' . '/rosell-dk/exec-with-fallback/src/POpen.php',
|
188 |
'ExecWithFallback\\Passthru' => __DIR__ . '/..' . '/rosell-dk/exec-with-fallback/src/Passthru.php',
|
189 |
'ExecWithFallback\\ProcOpen' => __DIR__ . '/..' . '/rosell-dk/exec-with-fallback/src/ProcOpen.php',
|
vendor/composer/installed.json
CHANGED
@@ -209,17 +209,17 @@
|
|
209 |
},
|
210 |
{
|
211 |
"name": "rosell-dk/dom-util-for-webp",
|
212 |
-
"version": "0.
|
213 |
-
"version_normalized": "0.
|
214 |
"source": {
|
215 |
"type": "git",
|
216 |
"url": "https://github.com/rosell-dk/dom-util-for-webp.git",
|
217 |
-
"reference": "
|
218 |
},
|
219 |
"dist": {
|
220 |
"type": "zip",
|
221 |
-
"url": "https://api.github.com/repos/rosell-dk/dom-util-for-webp/zipball/
|
222 |
-
"reference": "
|
223 |
"shasum": ""
|
224 |
},
|
225 |
"require": {
|
@@ -227,10 +227,11 @@
|
|
227 |
},
|
228 |
"require-dev": {
|
229 |
"friendsofphp/php-cs-fixer": "^2.11",
|
|
|
230 |
"phpunit/phpunit": "^9.3",
|
231 |
"squizlabs/php_codesniffer": "3.*"
|
232 |
},
|
233 |
-
"time": "
|
234 |
"type": "library",
|
235 |
"extra": {
|
236 |
"scripts-descriptions": {
|
@@ -268,7 +269,7 @@
|
|
268 |
],
|
269 |
"support": {
|
270 |
"issues": "https://github.com/rosell-dk/dom-util-for-webp/issues",
|
271 |
-
"source": "https://github.com/rosell-dk/dom-util-for-webp/tree/0.
|
272 |
},
|
273 |
"funding": [
|
274 |
{
|
@@ -284,17 +285,17 @@
|
|
284 |
},
|
285 |
{
|
286 |
"name": "rosell-dk/exec-with-fallback",
|
287 |
-
"version": "1.
|
288 |
-
"version_normalized": "1.
|
289 |
"source": {
|
290 |
"type": "git",
|
291 |
"url": "https://github.com/rosell-dk/exec-with-fallback.git",
|
292 |
-
"reference": "
|
293 |
},
|
294 |
"dist": {
|
295 |
"type": "zip",
|
296 |
-
"url": "https://api.github.com/repos/rosell-dk/exec-with-fallback/zipball/
|
297 |
-
"reference": "
|
298 |
"shasum": ""
|
299 |
},
|
300 |
"require": {
|
@@ -308,7 +309,7 @@
|
|
308 |
"suggest": {
|
309 |
"php-stan/php-stan": "Suggested for dev, in order to analyse code before committing"
|
310 |
},
|
311 |
-
"time": "2021-12-
|
312 |
"type": "library",
|
313 |
"extra": {
|
314 |
"scripts-descriptions": {
|
@@ -348,7 +349,7 @@
|
|
348 |
],
|
349 |
"support": {
|
350 |
"issues": "https://github.com/rosell-dk/exec-with-fallback/issues",
|
351 |
-
"source": "https://github.com/rosell-dk/exec-with-fallback/tree/1.
|
352 |
},
|
353 |
"funding": [
|
354 |
{
|
@@ -512,17 +513,17 @@
|
|
512 |
},
|
513 |
{
|
514 |
"name": "rosell-dk/webp-convert",
|
515 |
-
"version": "2.9.
|
516 |
-
"version_normalized": "2.9.
|
517 |
"source": {
|
518 |
"type": "git",
|
519 |
"url": "https://github.com/rosell-dk/webp-convert.git",
|
520 |
-
"reference": "
|
521 |
},
|
522 |
"dist": {
|
523 |
"type": "zip",
|
524 |
-
"url": "https://api.github.com/repos/rosell-dk/webp-convert/zipball/
|
525 |
-
"reference": "
|
526 |
"shasum": ""
|
527 |
},
|
528 |
"require": {
|
@@ -541,7 +542,7 @@
|
|
541 |
"ext-vips": "to use Vips extension for converting.",
|
542 |
"php-stan/php-stan": "Suggested for dev, in order to analyse code before committing"
|
543 |
},
|
544 |
-
"time": "2021-12-
|
545 |
"type": "library",
|
546 |
"extra": {
|
547 |
"scripts-descriptions": {
|
@@ -590,7 +591,7 @@
|
|
590 |
],
|
591 |
"support": {
|
592 |
"issues": "https://github.com/rosell-dk/webp-convert/issues",
|
593 |
-
"source": "https://github.com/rosell-dk/webp-convert/tree/2.9.
|
594 |
},
|
595 |
"funding": [
|
596 |
{
|
209 |
},
|
210 |
{
|
211 |
"name": "rosell-dk/dom-util-for-webp",
|
212 |
+
"version": "0.6.0",
|
213 |
+
"version_normalized": "0.6.0.0",
|
214 |
"source": {
|
215 |
"type": "git",
|
216 |
"url": "https://github.com/rosell-dk/dom-util-for-webp.git",
|
217 |
+
"reference": "2c87ff72d8ce49408ed5b2fc1a2e13ee16ab7613"
|
218 |
},
|
219 |
"dist": {
|
220 |
"type": "zip",
|
221 |
+
"url": "https://api.github.com/repos/rosell-dk/dom-util-for-webp/zipball/2c87ff72d8ce49408ed5b2fc1a2e13ee16ab7613",
|
222 |
+
"reference": "2c87ff72d8ce49408ed5b2fc1a2e13ee16ab7613",
|
223 |
"shasum": ""
|
224 |
},
|
225 |
"require": {
|
227 |
},
|
228 |
"require-dev": {
|
229 |
"friendsofphp/php-cs-fixer": "^2.11",
|
230 |
+
"phpstan/phpstan": "^1.5",
|
231 |
"phpunit/phpunit": "^9.3",
|
232 |
"squizlabs/php_codesniffer": "3.*"
|
233 |
},
|
234 |
+
"time": "2022-05-04T08:15:56+00:00",
|
235 |
"type": "library",
|
236 |
"extra": {
|
237 |
"scripts-descriptions": {
|
269 |
],
|
270 |
"support": {
|
271 |
"issues": "https://github.com/rosell-dk/dom-util-for-webp/issues",
|
272 |
+
"source": "https://github.com/rosell-dk/dom-util-for-webp/tree/0.6.0"
|
273 |
},
|
274 |
"funding": [
|
275 |
{
|
285 |
},
|
286 |
{
|
287 |
"name": "rosell-dk/exec-with-fallback",
|
288 |
+
"version": "1.2.0",
|
289 |
+
"version_normalized": "1.2.0.0",
|
290 |
"source": {
|
291 |
"type": "git",
|
292 |
"url": "https://github.com/rosell-dk/exec-with-fallback.git",
|
293 |
+
"reference": "f88a6b29abd0b580566056b7c1eb0434eb5db20d"
|
294 |
},
|
295 |
"dist": {
|
296 |
"type": "zip",
|
297 |
+
"url": "https://api.github.com/repos/rosell-dk/exec-with-fallback/zipball/f88a6b29abd0b580566056b7c1eb0434eb5db20d",
|
298 |
+
"reference": "f88a6b29abd0b580566056b7c1eb0434eb5db20d",
|
299 |
"shasum": ""
|
300 |
},
|
301 |
"require": {
|
309 |
"suggest": {
|
310 |
"php-stan/php-stan": "Suggested for dev, in order to analyse code before committing"
|
311 |
},
|
312 |
+
"time": "2021-12-08T12:09:43+00:00",
|
313 |
"type": "library",
|
314 |
"extra": {
|
315 |
"scripts-descriptions": {
|
349 |
],
|
350 |
"support": {
|
351 |
"issues": "https://github.com/rosell-dk/exec-with-fallback/issues",
|
352 |
+
"source": "https://github.com/rosell-dk/exec-with-fallback/tree/1.2.0"
|
353 |
},
|
354 |
"funding": [
|
355 |
{
|
513 |
},
|
514 |
{
|
515 |
"name": "rosell-dk/webp-convert",
|
516 |
+
"version": "2.9.1",
|
517 |
+
"version_normalized": "2.9.1.0",
|
518 |
"source": {
|
519 |
"type": "git",
|
520 |
"url": "https://github.com/rosell-dk/webp-convert.git",
|
521 |
+
"reference": "bb29cadb423691c620f395513e82fa414c17e464"
|
522 |
},
|
523 |
"dist": {
|
524 |
"type": "zip",
|
525 |
+
"url": "https://api.github.com/repos/rosell-dk/webp-convert/zipball/bb29cadb423691c620f395513e82fa414c17e464",
|
526 |
+
"reference": "bb29cadb423691c620f395513e82fa414c17e464",
|
527 |
"shasum": ""
|
528 |
},
|
529 |
"require": {
|
542 |
"ext-vips": "to use Vips extension for converting.",
|
543 |
"php-stan/php-stan": "Suggested for dev, in order to analyse code before committing"
|
544 |
},
|
545 |
+
"time": "2021-12-09T13:07:20+00:00",
|
546 |
"type": "library",
|
547 |
"extra": {
|
548 |
"scripts-descriptions": {
|
591 |
],
|
592 |
"support": {
|
593 |
"issues": "https://github.com/rosell-dk/webp-convert/issues",
|
594 |
+
"source": "https://github.com/rosell-dk/webp-convert/tree/2.9.1"
|
595 |
},
|
596 |
"funding": [
|
597 |
{
|
vendor/composer/installed.php
CHANGED
@@ -5,7 +5,7 @@
|
|
5 |
'type' => 'wordpress-plugin',
|
6 |
'install_path' => __DIR__ . '/../../',
|
7 |
'aliases' => array(),
|
8 |
-
'reference' => '
|
9 |
'name' => 'rosell-dk/webp-express',
|
10 |
'dev' => true,
|
11 |
),
|
@@ -29,21 +29,21 @@
|
|
29 |
'dev_requirement' => false,
|
30 |
),
|
31 |
'rosell-dk/dom-util-for-webp' => array(
|
32 |
-
'pretty_version' => '0.
|
33 |
-
'version' => '0.
|
34 |
'type' => 'library',
|
35 |
'install_path' => __DIR__ . '/../rosell-dk/dom-util-for-webp',
|
36 |
'aliases' => array(),
|
37 |
-
'reference' => '
|
38 |
'dev_requirement' => false,
|
39 |
),
|
40 |
'rosell-dk/exec-with-fallback' => array(
|
41 |
-
'pretty_version' => '1.
|
42 |
-
'version' => '1.
|
43 |
'type' => 'library',
|
44 |
'install_path' => __DIR__ . '/../rosell-dk/exec-with-fallback',
|
45 |
'aliases' => array(),
|
46 |
-
'reference' => '
|
47 |
'dev_requirement' => false,
|
48 |
),
|
49 |
'rosell-dk/htaccess-capability-tester' => array(
|
@@ -65,12 +65,12 @@
|
|
65 |
'dev_requirement' => false,
|
66 |
),
|
67 |
'rosell-dk/webp-convert' => array(
|
68 |
-
'pretty_version' => '2.9.
|
69 |
-
'version' => '2.9.
|
70 |
'type' => 'library',
|
71 |
'install_path' => __DIR__ . '/../rosell-dk/webp-convert',
|
72 |
'aliases' => array(),
|
73 |
-
'reference' => '
|
74 |
'dev_requirement' => false,
|
75 |
),
|
76 |
'rosell-dk/webp-convert-cloud-service' => array(
|
@@ -88,7 +88,7 @@
|
|
88 |
'type' => 'wordpress-plugin',
|
89 |
'install_path' => __DIR__ . '/../../',
|
90 |
'aliases' => array(),
|
91 |
-
'reference' => '
|
92 |
'dev_requirement' => false,
|
93 |
),
|
94 |
'roundcube/plugin-installer' => array(
|
5 |
'type' => 'wordpress-plugin',
|
6 |
'install_path' => __DIR__ . '/../../',
|
7 |
'aliases' => array(),
|
8 |
+
'reference' => '58c4e035f587f8caa4c9f27faea0c91ce74fc1dc',
|
9 |
'name' => 'rosell-dk/webp-express',
|
10 |
'dev' => true,
|
11 |
),
|
29 |
'dev_requirement' => false,
|
30 |
),
|
31 |
'rosell-dk/dom-util-for-webp' => array(
|
32 |
+
'pretty_version' => '0.6.0',
|
33 |
+
'version' => '0.6.0.0',
|
34 |
'type' => 'library',
|
35 |
'install_path' => __DIR__ . '/../rosell-dk/dom-util-for-webp',
|
36 |
'aliases' => array(),
|
37 |
+
'reference' => '2c87ff72d8ce49408ed5b2fc1a2e13ee16ab7613',
|
38 |
'dev_requirement' => false,
|
39 |
),
|
40 |
'rosell-dk/exec-with-fallback' => array(
|
41 |
+
'pretty_version' => '1.2.0',
|
42 |
+
'version' => '1.2.0.0',
|
43 |
'type' => 'library',
|
44 |
'install_path' => __DIR__ . '/../rosell-dk/exec-with-fallback',
|
45 |
'aliases' => array(),
|
46 |
+
'reference' => 'f88a6b29abd0b580566056b7c1eb0434eb5db20d',
|
47 |
'dev_requirement' => false,
|
48 |
),
|
49 |
'rosell-dk/htaccess-capability-tester' => array(
|
65 |
'dev_requirement' => false,
|
66 |
),
|
67 |
'rosell-dk/webp-convert' => array(
|
68 |
+
'pretty_version' => '2.9.1',
|
69 |
+
'version' => '2.9.1.0',
|
70 |
'type' => 'library',
|
71 |
'install_path' => __DIR__ . '/../rosell-dk/webp-convert',
|
72 |
'aliases' => array(),
|
73 |
+
'reference' => 'bb29cadb423691c620f395513e82fa414c17e464',
|
74 |
'dev_requirement' => false,
|
75 |
),
|
76 |
'rosell-dk/webp-convert-cloud-service' => array(
|
88 |
'type' => 'wordpress-plugin',
|
89 |
'install_path' => __DIR__ . '/../../',
|
90 |
'aliases' => array(),
|
91 |
+
'reference' => '58c4e035f587f8caa4c9f27faea0c91ce74fc1dc',
|
92 |
'dev_requirement' => false,
|
93 |
),
|
94 |
'roundcube/plugin-installer' => array(
|
vendor/rosell-dk/dom-util-for-webp/README.md
CHANGED
@@ -3,8 +3,7 @@
|
|
3 |
[![Latest Stable Version](https://img.shields.io/packagist/v/rosell-dk/dom-util-for-webp.svg?style=flat-square)](https://packagist.org/packages/rosell-dk/dom-util-for-webp)
|
4 |
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%205.6-8892BF.svg?style=flat-square)](https://php.net)
|
5 |
[![Build Status](https://img.shields.io/github/workflow/status/rosell-dk/dom-util-for-webp/PHP?logo=GitHub&style=flat-square)](https://github.com/rosell-dk/dom-util-for-webp/actions/workflows/php.yml)
|
6 |
-
[![Coverage
|
7 |
-
[![Quality Score](https://img.shields.io/scrutinizer/g/rosell-dk/dom-util-for-webp.svg?style=flat-square)](https://scrutinizer-ci.com/g/rosell-dk/dom-util-for-webp/)
|
8 |
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](https://github.com/rosell-dk/dom-util-for-webp/blob/master/LICENSE)
|
9 |
|
10 |
*Replace image URLs found in HTML*
|
3 |
[![Latest Stable Version](https://img.shields.io/packagist/v/rosell-dk/dom-util-for-webp.svg?style=flat-square)](https://packagist.org/packages/rosell-dk/dom-util-for-webp)
|
4 |
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%205.6-8892BF.svg?style=flat-square)](https://php.net)
|
5 |
[![Build Status](https://img.shields.io/github/workflow/status/rosell-dk/dom-util-for-webp/PHP?logo=GitHub&style=flat-square)](https://github.com/rosell-dk/dom-util-for-webp/actions/workflows/php.yml)
|
6 |
+
[![Coverage](https://img.shields.io/endpoint?url=https://little-b.it/dom-util-for-webp/code-coverage/coverage-badge.json)](http://little-b.it/dom-util-for-webp/code-coverage/coverage/index.html)
|
|
|
7 |
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](https://github.com/rosell-dk/dom-util-for-webp/blob/master/LICENSE)
|
8 |
|
9 |
*Replace image URLs found in HTML*
|
vendor/rosell-dk/dom-util-for-webp/composer.json
CHANGED
@@ -18,11 +18,13 @@
|
|
18 |
],
|
19 |
"cs-fix": "php-cs-fixer fix",
|
20 |
"cs-dry": "php-cs-fixer fix --dry-run --diff",
|
21 |
-
"test": "phpunit
|
22 |
"test-41": "phpunit --coverage-text --configuration 'phpunit-41.xml.dist'",
|
|
|
23 |
"phpunit": "phpunit --no-coverage",
|
24 |
-
"phpcs": "phpcs --standard=
|
25 |
-
"
|
|
|
26 |
"phpstan": "vendor/bin/phpstan analyse src --level=4"
|
27 |
},
|
28 |
"extra": {
|
@@ -50,6 +52,7 @@
|
|
50 |
],
|
51 |
"require-dev": {
|
52 |
"friendsofphp/php-cs-fixer": "^2.11",
|
|
|
53 |
"phpunit/phpunit": "^9.3",
|
54 |
"squizlabs/php_codesniffer": "3.*"
|
55 |
},
|
18 |
],
|
19 |
"cs-fix": "php-cs-fixer fix",
|
20 |
"cs-dry": "php-cs-fixer fix --dry-run --diff",
|
21 |
+
"test": "phpunit --coverage-text=build/coverage.txt --coverage-clover=build/coverage.clover --coverage-html=build/coverage --whitelist=src tests",
|
22 |
"test-41": "phpunit --coverage-text --configuration 'phpunit-41.xml.dist'",
|
23 |
+
"test-no-cov": "phpunit --no-coverage tests",
|
24 |
"phpunit": "phpunit --no-coverage",
|
25 |
+
"phpcs": "phpcs --standard=phpcs-ruleset.xml",
|
26 |
+
"phpcs-all": "phpcs --standard=phpcs-ruleset.xml src",
|
27 |
+
"phpcbf": "phpcbf --standard=phpcs-ruleset.xml",
|
28 |
"phpstan": "vendor/bin/phpstan analyse src --level=4"
|
29 |
},
|
30 |
"extra": {
|
52 |
],
|
53 |
"require-dev": {
|
54 |
"friendsofphp/php-cs-fixer": "^2.11",
|
55 |
+
"phpstan/phpstan": "^1.5",
|
56 |
"phpunit/phpunit": "^9.3",
|
57 |
"squizlabs/php_codesniffer": "3.*"
|
58 |
},
|
vendor/rosell-dk/dom-util-for-webp/phpcs-ruleset.xml
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<ruleset name="Custom Standard">
|
3 |
+
<description>PSR2 without line ending rule - let git manage the EOL cross the platforms</description>
|
4 |
+
<rule ref="PSR2" />
|
5 |
+
<rule ref="Generic.Files.LineEndings">
|
6 |
+
<exclude name="Generic.Files.LineEndings.InvalidEOLChar"/>
|
7 |
+
</rule>
|
8 |
+
</ruleset>
|
vendor/rosell-dk/dom-util-for-webp/phpstan.neon
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
parameters:
|
2 |
-
ignoreErrors:
|
3 |
-
- '#Function str_get_html not found.#'
|
|
|
|
|
|
vendor/rosell-dk/dom-util-for-webp/phpunit.xml.dist
CHANGED
@@ -1,25 +1,8 @@
|
|
1 |
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" backupStaticAttributes="false" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="false" processIsolation="false" stopOnFailure="false" bootstrap="vendor/autoload.php">
|
3 |
-
<coverage>
|
4 |
-
<include>
|
5 |
-
<directory suffix=".php">src/</directory>
|
6 |
-
</include>
|
7 |
-
<exclude>
|
8 |
-
<directory>./vendor</directory>
|
9 |
-
<directory>./tests</directory>
|
10 |
-
</exclude>
|
11 |
-
<report>
|
12 |
-
<clover outputFile="build/logs/clover.xml"/>
|
13 |
-
<text outputFile="build/coverage.txt"/>
|
14 |
-
</report>
|
15 |
-
</coverage>
|
16 |
<testsuites>
|
17 |
<testsuite name="Dom util for WebP Test Suite">
|
18 |
<directory>./tests/</directory>
|
19 |
</testsuite>
|
20 |
</testsuites>
|
21 |
-
<logging>
|
22 |
-
<junit outputFile="build/report.junit.xml"/>
|
23 |
-
<!--<log type="coverage-html" target="build/coverage"/>-->
|
24 |
-
</logging>
|
25 |
</phpunit>
|
1 |
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" backupStaticAttributes="false" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="false" processIsolation="false" stopOnFailure="false" bootstrap="vendor/autoload.php">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
<testsuites>
|
4 |
<testsuite name="Dom util for WebP Test Suite">
|
5 |
<directory>./tests/</directory>
|
6 |
</testsuite>
|
7 |
</testsuites>
|
|
|
|
|
|
|
|
|
8 |
</phpunit>
|
vendor/rosell-dk/dom-util-for-webp/src/ImageUrlReplacer.php
CHANGED
@@ -50,7 +50,7 @@ class ImageUrlReplacer
|
|
50 |
* would be unsafe. See #21
|
51 |
* @return void
|
52 |
*/
|
53 |
-
public
|
54 |
{
|
55 |
}
|
56 |
|
@@ -160,7 +160,11 @@ class ImageUrlReplacer
|
|
160 |
foreach ($parts as &$part) {
|
161 |
//echo 'part:' . $part . "\n";
|
162 |
$regex = '#(url\\s*\\(([\\"\\\']?))([^\\\'\\";\\)]*)(\\2\\s*\\))#';
|
163 |
-
$part = preg_replace_callback(
|
|
|
|
|
|
|
|
|
164 |
//echo 'result:' . $part . "\n";
|
165 |
}
|
166 |
$declarations[$i] = implode(',', $parts);
|
50 |
* would be unsafe. See #21
|
51 |
* @return void
|
52 |
*/
|
53 |
+
final public function __construct()
|
54 |
{
|
55 |
}
|
56 |
|
160 |
foreach ($parts as &$part) {
|
161 |
//echo 'part:' . $part . "\n";
|
162 |
$regex = '#(url\\s*\\(([\\"\\\']?))([^\\\'\\";\\)]*)(\\2\\s*\\))#';
|
163 |
+
$part = preg_replace_callback(
|
164 |
+
$regex,
|
165 |
+
'\DOMUtilForWebP\ImageUrlReplacer::processCSSRegExCallback',
|
166 |
+
$part
|
167 |
+
);
|
168 |
//echo 'result:' . $part . "\n";
|
169 |
}
|
170 |
$declarations[$i] = implode(',', $parts);
|
vendor/rosell-dk/dom-util-for-webp/src/PictureTags.php
CHANGED
@@ -35,9 +35,9 @@ class PictureTags
|
|
35 |
* would be unsafe. See #21
|
36 |
* @return void
|
37 |
*/
|
38 |
-
public
|
39 |
{
|
40 |
-
|
41 |
}
|
42 |
|
43 |
private $existingPictureTags;
|
@@ -114,16 +114,13 @@ class PictureTags
|
|
114 |
|
115 |
private static function getAttributes($html)
|
116 |
{
|
117 |
-
if (function_exists("mb_convert_encoding")) {
|
118 |
-
$html = mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8');
|
119 |
-
}
|
120 |
if (class_exists('\\DOMDocument')) {
|
121 |
$dom = new \DOMDocument();
|
122 |
@$dom->loadHTML($html);
|
123 |
$image = $dom->getElementsByTagName('img')->item(0);
|
124 |
$attributes = [];
|
125 |
foreach ($image->attributes as $attr) {
|
126 |
-
|
127 |
}
|
128 |
return $attributes;
|
129 |
} else {
|
@@ -132,8 +129,11 @@ class PictureTags
|
|
132 |
require_once __DIR__ . '/../src-vendor/simple_html_dom/simple_html_dom.inc';
|
133 |
}*/
|
134 |
|
|
|
|
|
|
|
135 |
|
136 |
-
$dom = HtmlDomParser::str_get_html($html, false, false,
|
137 |
if ($dom !== false) {
|
138 |
$elems = $dom->find('img,IMG');
|
139 |
foreach ($elems as $index => $elem) {
|
@@ -210,7 +210,6 @@ class PictureTags
|
|
210 |
$width = null;
|
211 |
if ($result && count($result) >= 2) {
|
212 |
list($src, $width) = $result;
|
213 |
-
|
214 |
}
|
215 |
|
216 |
$webpUrl = $this->replaceUrlOr($src, false);
|
@@ -225,7 +224,6 @@ class PictureTags
|
|
225 |
}
|
226 |
|
227 |
foreach ($srcAttributes as $attrName => $attrValue) {
|
228 |
-
|
229 |
if (substr($attrValue, 0, 5) == 'data:') {
|
230 |
// ignore tags with data urls, such as <img src="data:...
|
231 |
return $imgTag;
|
@@ -312,7 +310,11 @@ class PictureTags
|
|
312 |
$this->existingPictureTags = [];
|
313 |
|
314 |
// Tempororily remove existing <picture> tags
|
315 |
-
$content = preg_replace_callback(
|
|
|
|
|
|
|
|
|
316 |
|
317 |
// Replace "<img>" tags
|
318 |
$content = preg_replace_callback('/<img[^>]*>/i', array($this, 'replaceCallback'), $content);
|
35 |
* would be unsafe. See #21
|
36 |
* @return void
|
37 |
*/
|
38 |
+
final public function __construct()
|
39 |
{
|
40 |
+
$this->existingPictureTags = [];
|
41 |
}
|
42 |
|
43 |
private $existingPictureTags;
|
114 |
|
115 |
private static function getAttributes($html)
|
116 |
{
|
|
|
|
|
|
|
117 |
if (class_exists('\\DOMDocument')) {
|
118 |
$dom = new \DOMDocument();
|
119 |
@$dom->loadHTML($html);
|
120 |
$image = $dom->getElementsByTagName('img')->item(0);
|
121 |
$attributes = [];
|
122 |
foreach ($image->attributes as $attr) {
|
123 |
+
$attributes[$attr->nodeName] = $attr->nodeValue;
|
124 |
}
|
125 |
return $attributes;
|
126 |
} else {
|
129 |
require_once __DIR__ . '/../src-vendor/simple_html_dom/simple_html_dom.inc';
|
130 |
}*/
|
131 |
|
132 |
+
// Took detection from here:
|
133 |
+
// https://github.com/symfony/symfony/blob/d31ea7c230160b3930f4789ed38c959c5db4f723/src/Symfony/Component/DomCrawler/Crawler.php
|
134 |
+
$charset = preg_match('//u', $html) ? 'UTF-8' : 'ISO-8859-1';
|
135 |
|
136 |
+
$dom = HtmlDomParser::str_get_html($html, false, false, $charset, false);
|
137 |
if ($dom !== false) {
|
138 |
$elems = $dom->find('img,IMG');
|
139 |
foreach ($elems as $index => $elem) {
|
210 |
$width = null;
|
211 |
if ($result && count($result) >= 2) {
|
212 |
list($src, $width) = $result;
|
|
|
213 |
}
|
214 |
|
215 |
$webpUrl = $this->replaceUrlOr($src, false);
|
224 |
}
|
225 |
|
226 |
foreach ($srcAttributes as $attrName => $attrValue) {
|
|
|
227 |
if (substr($attrValue, 0, 5) == 'data:') {
|
228 |
// ignore tags with data urls, such as <img src="data:...
|
229 |
return $imgTag;
|
310 |
$this->existingPictureTags = [];
|
311 |
|
312 |
// Tempororily remove existing <picture> tags
|
313 |
+
$content = preg_replace_callback(
|
314 |
+
'/<picture[^>]*>.*?<\/picture>/is',
|
315 |
+
array($this, 'removePictureTagsTemporarily'),
|
316 |
+
$content
|
317 |
+
);
|
318 |
|
319 |
// Replace "<img>" tags
|
320 |
$content = preg_replace_callback('/<img[^>]*>/i', array($this, 'replaceCallback'), $content);
|
vendor/rosell-dk/exec-with-fallback/README.md
CHANGED
@@ -11,7 +11,7 @@ Some shared hosts may have disabled *exec()*, but leaved *proc_open()*, *passthr
|
|
11 |
This library can be useful if you a writing code that is meant to run on a broad spectrum of systems, as it makes your exec() call succeed on more of these systems.
|
12 |
|
13 |
## Usage:
|
14 |
-
Simply swap out your current *exec()* calls with *ExecWithFallback::exec()*. The signatures are exactly the same
|
15 |
|
16 |
```php
|
17 |
use ExecWithFallback\ExecWithFallback;
|
@@ -21,7 +21,9 @@ $result = ExecWithFallback::exec('echo "hi"', $output, $result_code);
|
|
21 |
// $return (string | false) is now false in case of failure or the last line of the output
|
22 |
```
|
23 |
|
24 |
-
|
|
|
|
|
25 |
|
26 |
## Installing
|
27 |
`composer require rosell-dk/exec-with-fallback`
|
@@ -34,7 +36,9 @@ If you have `function_exists('exec')` in your code, you can change it to `ExecWi
|
|
34 |
- proc_open()
|
35 |
- shell_exec()
|
36 |
|
37 |
-
In case all functions are unavailable,
|
|
|
|
|
38 |
|
39 |
PS: As *shell_exec()* does not support *$result_code*, it will only be used when $result_code isn't supplied. *system()* is not implemented, as it cannot return the last line of output and there is no way to detect if your code relies on that.
|
40 |
|
@@ -55,6 +59,9 @@ I made sure that the function behaves exactly like *exec()*, and wrote a lot of
|
|
55 |
**going to be maintained**\
|
56 |
I'm going to use this library in [webp-convert](https://github.com/rosell-dk/webp-convert), which is used in many projects. So it is going to be widely used. While I don't expect much need for maintenance for this project, it is going to be there, if needed.
|
57 |
|
|
|
|
|
|
|
58 |
## Do you like what I do?
|
59 |
Perhaps you want to support my work, so I can continue doing it :)
|
60 |
|
11 |
This library can be useful if you a writing code that is meant to run on a broad spectrum of systems, as it makes your exec() call succeed on more of these systems.
|
12 |
|
13 |
## Usage:
|
14 |
+
Simply swap out your current *exec()* calls with *ExecWithFallback::exec()*. The signatures are exactly the same.
|
15 |
|
16 |
```php
|
17 |
use ExecWithFallback\ExecWithFallback;
|
21 |
// $return (string | false) is now false in case of failure or the last line of the output
|
22 |
```
|
23 |
|
24 |
+
Note that while the signatures are the same, errors are not exactly the same. There is a reason for that. On some systems, a real `exec()` call results in a FATAL error when the function has been disabled. That is: An error, that cannot be catched. You probably don't want to halt execution on some systems, but not on other. But if you do, use `ExecWithFallback::execNoMercy` instead of `ExecWithFallback::exec`. In case no emulations are available, it calls *exec()*, ensuring exact same error handling as normal *exec()*.
|
25 |
+
|
26 |
+
If you have `function_exists('exec')` in your code, you probably want to change them to `ExecWithFallback::anyAvailable()`
|
27 |
|
28 |
## Installing
|
29 |
`composer require rosell-dk/exec-with-fallback`
|
36 |
- proc_open()
|
37 |
- shell_exec()
|
38 |
|
39 |
+
In case all functions are unavailable, a normal exception is thrown (class: Exception). This is more gentle behavior than real exec(), which on some systems throws FATAL error when the function is disabled. If you want exactly same errors, use `ExecWithFallback::execNoMercy` instead, which instead of throwing an exception calls *exec*, which will result in a throw (to support older PHP, you need to catch both Exception and Throwable. And note that you cannot catch on all systems, because some throws FATAL)
|
40 |
+
|
41 |
+
In case none succeeded, but at least one failed by returning false, false is returned. Again to mimic *exec()* behavior.
|
42 |
|
43 |
PS: As *shell_exec()* does not support *$result_code*, it will only be used when $result_code isn't supplied. *system()* is not implemented, as it cannot return the last line of output and there is no way to detect if your code relies on that.
|
44 |
|
59 |
**going to be maintained**\
|
60 |
I'm going to use this library in [webp-convert](https://github.com/rosell-dk/webp-convert), which is used in many projects. So it is going to be widely used. While I don't expect much need for maintenance for this project, it is going to be there, if needed.
|
61 |
|
62 |
+
**Con: risk of being recognized as malware**
|
63 |
+
There is a slight risk that a lazy malware creator uses this library for his malware. The risk is however very small, as the library isn't suitable for malware. First off, the library doesn't try *system()*, as that function does not return output and thus cannot be used to emulate *exec()*. A malware creator would desire to try all possible ways to get his malware executed. Secondly, malware creators probably don't use composer for their malware and would probably want a single function instead of having it spread over multiple files. Third, the library here use a lot of efford in getting the emululated functions to behave exactly as exec(). This concern is probably non-existant for malware creators, who probably cares more about the effect of running the malware. Lastly, a malware creator would want to write his own function instead of copying code found on the internet. Copying stuff would impose a chance that the code is used by another malware creator which increases the risk of anti malware software recognizing it as malware.
|
64 |
+
|
65 |
## Do you like what I do?
|
66 |
Perhaps you want to support my work, so I can continue doing it :)
|
67 |
|
vendor/rosell-dk/exec-with-fallback/src/Availability.php
CHANGED
@@ -28,7 +28,7 @@ class Availability extends ExecWithFallback
|
|
28 |
|
29 |
public static function methodAvailable($method, $needResultCode = true)
|
30 |
{
|
31 |
-
if (!
|
32 |
return false;
|
33 |
}
|
34 |
if ($needResultCode) {
|
28 |
|
29 |
public static function methodAvailable($method, $needResultCode = true)
|
30 |
{
|
31 |
+
if (!ExecWithFallback::functionEnabled($method)) {
|
32 |
return false;
|
33 |
}
|
34 |
if ($needResultCode) {
|
vendor/rosell-dk/exec-with-fallback/src/ExecWithFallback.php
CHANGED
@@ -23,25 +23,62 @@ class ExecWithFallback
|
|
23 |
return Availability::anyAvailable($needResultCode);
|
24 |
}
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
/**
|
27 |
* Execute. - A substitute for exec()
|
28 |
*
|
29 |
* Same signature and results as exec(): https://www.php.net/manual/en/function.exec.php
|
|
|
|
|
|
|
30 |
*
|
31 |
* @param string $command The command to execute
|
32 |
* @param string &$output (optional)
|
33 |
* @param int &$result_code (optional)
|
34 |
*
|
35 |
* @return string | false The last line of output or false in case of failure
|
|
|
36 |
*/
|
37 |
public static function exec($command, &$output = null, &$result_code = null)
|
38 |
{
|
39 |
foreach (self::$methods as $method) {
|
40 |
-
if (
|
41 |
-
if (
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
43 |
}
|
44 |
-
$result = self::runExec($method, $command, $output, $result_code);
|
45 |
if ($result !== false) {
|
46 |
return $result;
|
47 |
}
|
@@ -50,7 +87,21 @@ class ExecWithFallback
|
|
50 |
if (isset($result) && ($result === false)) {
|
51 |
return false;
|
52 |
}
|
53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
}
|
55 |
|
56 |
public static function runExec($method, $command, &$output = null, &$result_code = null)
|
23 |
return Availability::anyAvailable($needResultCode);
|
24 |
}
|
25 |
|
26 |
+
/**
|
27 |
+
* Check if a function is enabled (function_exists as well as ini is tested)
|
28 |
+
*
|
29 |
+
* @param string $functionName The name of the function
|
30 |
+
*
|
31 |
+
* @return boolean If the function is enabled
|
32 |
+
*/
|
33 |
+
public static function functionEnabled($functionName)
|
34 |
+
{
|
35 |
+
if (!function_exists($functionName)) {
|
36 |
+
return false;
|
37 |
+
}
|
38 |
+
if (function_exists('ini_get')) {
|
39 |
+
if (ini_get('safe_mode')) {
|
40 |
+
return false;
|
41 |
+
}
|
42 |
+
$d = ini_get('disable_functions') . ',' . ini_get('suhosin.executor.func.blacklist');
|
43 |
+
if ($d === false) {
|
44 |
+
$d = '';
|
45 |
+
}
|
46 |
+
$d = preg_replace('/,\s*/', ',', $d);
|
47 |
+
if (strpos(',' . $d . ',', ',' . $functionName . ',') !== false) {
|
48 |
+
return false;
|
49 |
+
}
|
50 |
+
}
|
51 |
+
return is_callable($functionName);
|
52 |
+
}
|
53 |
+
|
54 |
+
|
55 |
/**
|
56 |
* Execute. - A substitute for exec()
|
57 |
*
|
58 |
* Same signature and results as exec(): https://www.php.net/manual/en/function.exec.php
|
59 |
+
* In case neither exec(), nor emulations are available, it throws an Exception.
|
60 |
+
* This is more gentle than real exec(), which on some systems throws a FATAL when exec() is disabled
|
61 |
+
* If you want the more acurate substitute, which might halt execution, use execNoMercy() instead.
|
62 |
*
|
63 |
* @param string $command The command to execute
|
64 |
* @param string &$output (optional)
|
65 |
* @param int &$result_code (optional)
|
66 |
*
|
67 |
* @return string | false The last line of output or false in case of failure
|
68 |
+
* @throws \Exception If no methods are available
|
69 |
*/
|
70 |
public static function exec($command, &$output = null, &$result_code = null)
|
71 |
{
|
72 |
foreach (self::$methods as $method) {
|
73 |
+
if (self::functionEnabled($method)) {
|
74 |
+
if (func_num_args() >= 3) {
|
75 |
+
if ($method == 'shell_exec') {
|
76 |
+
continue;
|
77 |
+
}
|
78 |
+
$result = self::runExec($method, $command, $output, $result_code);
|
79 |
+
} else {
|
80 |
+
$result = self::runExec($method, $command, $output);
|
81 |
}
|
|
|
82 |
if ($result !== false) {
|
83 |
return $result;
|
84 |
}
|
87 |
if (isset($result) && ($result === false)) {
|
88 |
return false;
|
89 |
}
|
90 |
+
throw new \Exception('exec() is not available');
|
91 |
+
}
|
92 |
+
|
93 |
+
/**
|
94 |
+
* Execute. - A substitute for exec(), with exact same errors thrown if exec() is missing.
|
95 |
+
*
|
96 |
+
* Danger: On some systems, this results in a fatal (non-catchable) error.
|
97 |
+
*/
|
98 |
+
public static function execNoMercy($command, &$output = null, &$result_code = null)
|
99 |
+
{
|
100 |
+
if (func_num_args() == 3) {
|
101 |
+
return ExecWithFallbackNoMercy::exec($command, $output, $result_code);
|
102 |
+
} else {
|
103 |
+
return ExecWithFallbackNoMercy::exec($command, $output);
|
104 |
+
}
|
105 |
}
|
106 |
|
107 |
public static function runExec($method, $command, &$output = null, &$result_code = null)
|
vendor/rosell-dk/exec-with-fallback/src/ExecWithFallbackNoMercy.php
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
namespace ExecWithFallback;
|
3 |
+
|
4 |
+
/**
|
5 |
+
* Execute command with exec(), open_proc() or whatever available
|
6 |
+
*
|
7 |
+
* @package ExecWithFallback
|
8 |
+
* @author Bjørn Rosell <it@rosell.dk>
|
9 |
+
*/
|
10 |
+
class ExecWithFallbackNoMercy
|
11 |
+
{
|
12 |
+
|
13 |
+
/**
|
14 |
+
* Execute. - A substitute for exec()
|
15 |
+
*
|
16 |
+
* Same signature and results as exec(): https://www.php.net/manual/en/function.exec.php
|
17 |
+
*
|
18 |
+
* This is our hardcore version of our exec(). It does not merely throw an Exception, if
|
19 |
+
* no methods are available. It calls exec().
|
20 |
+
* This ensures exactly same behavior as normal exec() - the same error is thrown.
|
21 |
+
* You might want that. But do you really?
|
22 |
+
* DANGER: On some systems, calling a disabled exec() results in a fatal (non-catchable) error.
|
23 |
+
*
|
24 |
+
* @param string $command The command to execute
|
25 |
+
* @param string &$output (optional)
|
26 |
+
* @param int &$result_code (optional)
|
27 |
+
*
|
28 |
+
* @return string | false The last line of output or false in case of failure
|
29 |
+
* @throws \Exception|\Error If no methods are available. Note: On some systems, it is FATAL!
|
30 |
+
*/
|
31 |
+
public static function exec($command, &$output = null, &$result_code = null)
|
32 |
+
{
|
33 |
+
foreach (self::$methods as $method) {
|
34 |
+
if (self::functionEnabled($method)) {
|
35 |
+
if (func_num_args() >= 3) {
|
36 |
+
if ($method == 'shell_exec') {
|
37 |
+
continue;
|
38 |
+
}
|
39 |
+
$result = self::runExec($method, $command, $output, $result_code);
|
40 |
+
} else {
|
41 |
+
$result = self::runExec($method, $command, $output);
|
42 |
+
}
|
43 |
+
if ($result !== false) {
|
44 |
+
return $result;
|
45 |
+
}
|
46 |
+
}
|
47 |
+
}
|
48 |
+
if (isset($result) && ($result === false)) {
|
49 |
+
return false;
|
50 |
+
}
|
51 |
+
// MIGHT THROW FATAL!
|
52 |
+
return exec($command, $output, $result_code);
|
53 |
+
}
|
54 |
+
|
55 |
+
|
56 |
+
}
|
vendor/rosell-dk/exec-with-fallback/src/ShellExec.php
CHANGED
@@ -12,7 +12,7 @@ class ShellExec
|
|
12 |
{
|
13 |
|
14 |
/**
|
15 |
-
* Emulate exec() with
|
16 |
*
|
17 |
* @param string $command The command to execute
|
18 |
* @param string &$output (optional)
|
@@ -22,11 +22,9 @@ class ShellExec
|
|
22 |
*/
|
23 |
public static function exec($command, &$output = null, &$result_code = null)
|
24 |
{
|
25 |
-
//echo "\NSHELL:" . $command . ':' . func_num_args() . "\n";
|
26 |
-
|
27 |
$resultCodeSupplied = (func_num_args() >= 3);
|
28 |
if ($resultCodeSupplied) {
|
29 |
-
|
30 |
}
|
31 |
|
32 |
$result = shell_exec($command);
|
12 |
{
|
13 |
|
14 |
/**
|
15 |
+
* Emulate exec() with shell_exec()
|
16 |
*
|
17 |
* @param string $command The command to execute
|
18 |
* @param string &$output (optional)
|
22 |
*/
|
23 |
public static function exec($command, &$output = null, &$result_code = null)
|
24 |
{
|
|
|
|
|
25 |
$resultCodeSupplied = (func_num_args() >= 3);
|
26 |
if ($resultCodeSupplied) {
|
27 |
+
throw new \Exception('ShellExec::exec() does not support $result_code argument');
|
28 |
}
|
29 |
|
30 |
$result = shell_exec($command);
|
vendor/rosell-dk/webp-convert/README.md
CHANGED
@@ -1,11 +1,11 @@
|
|
1 |
# WebP Convert
|
2 |
|
3 |
-
[![Latest Stable Version](https://img.shields.io/packagist/v/rosell-dk/webp-convert.svg
|
4 |
-
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%205.6-8892BF.svg
|
5 |
-
[![Build Status](https://img.shields.io/github/workflow/status/rosell-dk/webp-convert/PHP?logo=GitHub
|
6 |
-
[![
|
7 |
-
[![
|
8 |
-
[![
|
9 |
|
10 |
*Convert JPEG & PNG to WebP with PHP*
|
11 |
|
@@ -126,11 +126,11 @@ Bread on the table don't come for free, even though this library does, and alway
|
|
126 |
- Ruben Solvang
|
127 |
|
128 |
*Persons who recently contributed with [ko-fi](https://ko-fi.com/rosell) - Thanks!*
|
|
|
|
|
129 |
* 20 Nov: Ben J
|
130 |
* 13 Nov: @sween
|
131 |
* 9 Nov: @utrenkner
|
132 |
-
* 26 Oct: Anonymous
|
133 |
-
* 29 Aug: Pawa Tecnologia
|
134 |
|
135 |
*Persons who contributed with extra generously amounts of coffee / lifetime backing (>50$) - thanks!:*
|
136 |
|
1 |
# WebP Convert
|
2 |
|
3 |
+
[![Latest Stable Version](https://img.shields.io/packagist/v/rosell-dk/webp-convert.svg)](https://packagist.org/packages/rosell-dk/webp-convert)
|
4 |
+
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%205.6-8892BF.svg)](https://php.net)
|
5 |
+
[![Build Status](https://img.shields.io/github/workflow/status/rosell-dk/webp-convert/PHP?logo=GitHub)](https://github.com/rosell-dk/webp-convert/actions/workflows/php.yml)
|
6 |
+
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://github.com/rosell-dk/webp-convert/blob/master/LICENSE)
|
7 |
+
[![Monthly Downloads](http://poser.pugx.org/rosell-dk/webp-convert/d/monthly)](https://packagist.org/packages/rosell-dk/webp-convert)
|
8 |
+
[![Dependents](http://poser.pugx.org/rosell-dk/webp-convert/dependents)](https://packagist.org/packages/rosell-dk/webp-convert/dependents?order_by=downloads)
|
9 |
|
10 |
*Convert JPEG & PNG to WebP with PHP*
|
11 |
|
126 |
- Ruben Solvang
|
127 |
|
128 |
*Persons who recently contributed with [ko-fi](https://ko-fi.com/rosell) - Thanks!*
|
129 |
+
* 3 Dec: Dallas
|
130 |
+
* 29 Nov: tadesco.org
|
131 |
* 20 Nov: Ben J
|
132 |
* 13 Nov: @sween
|
133 |
* 9 Nov: @utrenkner
|
|
|
|
|
134 |
|
135 |
*Persons who contributed with extra generously amounts of coffee / lifetime backing (>50$) - thanks!:*
|
136 |
|
vendor/rosell-dk/webp-convert/docs/development.md
DELETED
@@ -1,79 +0,0 @@
|
|
1 |
-
# Development
|
2 |
-
|
3 |
-
## Setting up the environment.
|
4 |
-
|
5 |
-
First, clone the repository:
|
6 |
-
```
|
7 |
-
cd whatever/folder/you/want
|
8 |
-
git clone https://github.com/rosell-dk/webp-convert.git
|
9 |
-
```
|
10 |
-
|
11 |
-
Then install the dev tools with composer:
|
12 |
-
|
13 |
-
```
|
14 |
-
composer install
|
15 |
-
```
|
16 |
-
|
17 |
-
If you don't have composer yet:
|
18 |
-
- Get it ([download phar](https://getcomposer.org/composer.phar) and move it to /usr/local/bin/composer)
|
19 |
-
- PS: PHPUnit requires php-xml, php-mbstring and php-curl. To install: `sudo apt install php-xml php-mbstring curl php-curl`
|
20 |
-
|
21 |
-
|
22 |
-
## Unit Testing
|
23 |
-
To run all the unit tests do this:
|
24 |
-
```
|
25 |
-
composer test
|
26 |
-
```
|
27 |
-
This also runs tests on the builds.
|
28 |
-
|
29 |
-
|
30 |
-
Individual test files can be executed like this:
|
31 |
-
```
|
32 |
-
composer phpunit tests/Convert/Converters/WPCTest
|
33 |
-
composer phpunit tests/Serve/ServeConvertedTest
|
34 |
-
```
|
35 |
-
|
36 |
-
|
37 |
-
## Coding styles
|
38 |
-
WebPConvert complies with the [PSR-2](https://www.php-fig.org/psr/psr-2/) coding standard.
|
39 |
-
|
40 |
-
To validate coding style of all files, do this:
|
41 |
-
```
|
42 |
-
composer phpcs src
|
43 |
-
```
|
44 |
-
|
45 |
-
To automatically fix the coding style of all files, using [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer), do this:
|
46 |
-
```
|
47 |
-
composer phpcbf src
|
48 |
-
```
|
49 |
-
|
50 |
-
Or, alternatively, you can fix with the use the [PHP-CS-FIXER](https://github.com/FriendsOfPHP/PHP-CS-Fixer) library instead:
|
51 |
-
```
|
52 |
-
composer cs-fix
|
53 |
-
```
|
54 |
-
|
55 |
-
## Running all tests in one command
|
56 |
-
The following script runs the unit tests, checks the coding styles, validates `composer.json` and runs the builds.
|
57 |
-
Run this before pushing anything to github. "ci" btw stands for *continuous integration*.
|
58 |
-
```
|
59 |
-
composer ci
|
60 |
-
```
|
61 |
-
|
62 |
-
## Generating api docs
|
63 |
-
Install phpdox and run it in the project root:
|
64 |
-
```
|
65 |
-
phpdox
|
66 |
-
```
|
67 |
-
|
68 |
-
## Committing
|
69 |
-
Before committing, first make sure to:
|
70 |
-
- run `composer ci`
|
71 |
-
|
72 |
-
## Releasing
|
73 |
-
Before releasing:
|
74 |
-
- Update the version number in `Converters/AbstractConverter.php` (search for "WebP Convert")
|
75 |
-
- Make sure that ci build is successful
|
76 |
-
|
77 |
-
When releasing:
|
78 |
-
- update the [webp-convert-concat](https://github.com/rosell-dk/webp-convert-concat) library
|
79 |
-
- consider updating the require in the composer file in libraries that uses webp-convert (ie `webp-convert-cloud-service` and `webp-express`)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vendor/rosell-dk/webp-convert/docs/v1.3/converting/convert-options.md
DELETED
@@ -1,322 +0,0 @@
|
|
1 |
-
# The webp converters
|
2 |
-
|
3 |
-
## The converters at a glance
|
4 |
-
When it comes to webp conversion, there is actually only one library in town: *libwebp* from Google. All conversion methods below ultimately uses that very same library for conversion. This means that it does not matter much, which conversion method you use. Whatever works. There is however one thing to take note of, if you set *quality* to *auto*, and your system cannot determine the quality of the source (this requires imagick or gmagick), and you do not have access to install those, then the only way to get quality-detection is to connect to a *wpc* cloud converter. However, with *cwebp*, you can specify the desired reduction (the *size-in-percentage* option) - at the cost of doubling the conversion time. Read more about those considerations in the API.
|
5 |
-
|
6 |
-
Speed-wise, there is too little difference for it to matter, considering that images usually needs to be converted just once. Anyway, here are the results: *cweb* is the fastest (with method=3). *gd* is right behind, merely 3% slower than *cwebp*. *gmagick* are third place, ~8% slower than *cwebp*. *imagick* comes in ~22% slower than *cwebp*. *ewww* depends on connection speed. On my *digital ocean* account, it takes ~2 seconds to upload, convert, and download a tiny image (10 times longer than the local *cwebp*). A 1MB image however only takes ~4.5 seconds to upload, convert and download (1.5 seconds longer). A 2 MB image takes ~5 seconds to convert (only 16% longer than my *cwebp*). The *ewww* thus converts at a very decent speeds. Probably faster than your average shared host. If multiple big images needs to be converted at the same time, *ewww* will probably perform much better than the local converters.
|
7 |
-
|
8 |
-
[`cwebp`](#cwebp) works by executing the *cwebp* binary from Google, which is build upon the *libwebp* (also from Google). That library is actually the only library in town for generating webp images, which means that the other conversion methods ultimately uses that very same library. Which again means that the results using the different methods are very similar. However, with *cwebp*, we have more parameters to tweak than with the rest. We for example have the *method* option, which controls the trade off between encoding speed and the compressed file size and quality. Setting this to max, we can squeeze the images a few percent extra - without loosing quality (the converter is still pretty fast, so in most cases it is probably worth it).
|
9 |
-
|
10 |
-
Of course, as we here have to call a binary directly, *cwebp* requires the *exec* function to be enabled, and that the webserver user is allowed to execute the `cwebp` binary (either at known system locations, or one of the precompiled binaries, that comes with this library).
|
11 |
-
|
12 |
-
[`vips`](#vips) (**new in 2.0**) works by using the vips extension, if available. Vips is great! It offers many webp options, it is fast and installation is easier than imagick and gd, as it does not need to be configured for webp support.
|
13 |
-
|
14 |
-
[`imagick`](#imagick) does not support any special webp options, but is at least able to strip all metadata, if metadata is set to none. Imagick has a very nice feature - that it is able to detect the quality of a jpeg file. This enables it to automatically use same quality for destination as for source, which eliminates the risk of setting quality higher for the destination than for source (the result of that is that the file size gets higher, but the quality remains the same). As the other converters lends this capability from Imagick, this is however no reason for using Imagick rather than the other converters. Requirements: Imagick PHP extension compiled with WebP support
|
15 |
-
|
16 |
-
[`gmagick`](#gmagick) uses the *gmagick* extension. It is very similar to *imagick*. Requirements: Gmagick PHP extension compiled with WebP support.
|
17 |
-
|
18 |
-
[`gd`](#gd) uses the *Gd* extension to do the conversion. The *Gd* extension is pretty common, so the main feature of this converter is that it may work out of the box. It does not support any webp options, and does not support stripping metadata. Requirements: GD PHP extension compiled with WebP support.
|
19 |
-
|
20 |
-
[`wpc`](#wpc) is an open source cloud service for converting images to webp. To use it, you must either install [webp-convert-cloud-service](https://github.com/rosell-dk/webp-convert-cloud-service) directly on a remote server, or install the Wordpress plugin, [WebP Express](https://github.com/rosell-dk/webp-express) in Wordpress. Btw: Beware that upload limits will prevent conversion of big images. The converter checks your *php.ini* settings and abandons upload right away, if an image is larger than your *upload_max_filesize* or your *post_max_size* setting. Requirements: Access to a running service. The service can be installed [directly](https://github.com/rosell-dk/webp-convert-cloud-service) or by using [this Wordpress plugin](https://wordpress.org/plugins/webp-express/)
|
21 |
-
|
22 |
-
[`ewww`](#ewww) is also a cloud service. Not free, but cheap enough to be considered *practically* free. It supports lossless encoding, but this cannot be controlled. *Ewww* always uses lossy encoding for jpeg and lossless for png. For jpegs this is usually a good choice, however, many pngs are compressed better using lossy encoding. As lossless cannot be controlled, the "lossless:auto" option cannot be used for automatically trying both lossy and lossless and picking the smallest file. Also, unfortunately, *ewww* does not support quality=auto, like *wpc*, and it does not support *size-in-percentage* like *cwebp*, either. I have requested such features, and he is considering... As with *wpc*, beware of upload limits. Requirements: A key to the *EWWW Image Optimizer* cloud service. Can be purchaced [here](https://ewww.io/plans/)
|
23 |
-
|
24 |
-
[`stack`](#stack) takes a stack of converters and tries it from the top, until success. The main convert method actually calls this converter. Stacks within stacks are supported (not really needed, though).
|
25 |
-
|
26 |
-
|
27 |
-
**Summary:**
|
28 |
-
|
29 |
-
| | cwebp | vips | imagick / gmagick | imagickbinary | gd | ewww |
|
30 |
-
| ------------------------------------------ | --------- | ------ | ----------------- | ------------- | --------- | ------ |
|
31 |
-
| supports lossless encoding ? | yes | yes | no | no | no | yes |
|
32 |
-
| supports lossless auto ? | yes | yes | no | no | no | no |
|
33 |
-
| supports near-lossless ? | yes | yes | no | no | no | ? |
|
34 |
-
| supports metadata stripping / preserving | yes | yes | yes | no | no | ? |
|
35 |
-
| supports setting alpha quality | no | yes | no | no | no | no |
|
36 |
-
| supports fixed quality (for lossy) | yes | yes | yes | yes | yes | yes |
|
37 |
-
| supports auto quality without help | no | no | yes | yes | no | no |
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
*WebPConvert* currently supports the following converters:
|
42 |
-
|
43 |
-
| Converter | Method | Requirements |
|
44 |
-
| ------------------------------------ | ------------------------------------------------ | -------------------------------------------------- |
|
45 |
-
| [`cwebp`](#cwebp) | Calls `cwebp` binary directly | `exec()` function *and* that the webserver user has permission to run `cwebp` binary |
|
46 |
-
| [`vips`](#vips) (new in 2.0) | Vips extension | Vips extension |
|
47 |
-
| [`imagick`](#imagick) | Imagick extension (`ImageMagick` wrapper) | Imagick PHP extension compiled with WebP support |
|
48 |
-
| [`gmagick`](#gmagick) | Gmagick extension (`ImageMagick` wrapper) | Gmagick PHP extension compiled with WebP support |
|
49 |
-
| [`gd`](#gd) | GD Graphics (Draw) extension (`LibGD` wrapper) | GD PHP extension compiled with WebP support |
|
50 |
-
| [`imagickbinary`](#imagickbinary) | Calls imagick binary directly | exec() and imagick installed and compiled with WebP support |
|
51 |
-
| [`wpc`](#wpc) | Connects to an open source cloud service | Access to a running service. The service can be installed [directly](https://github.com/rosell-dk/webp-convert-cloud-service) or by using [this Wordpress plugin](https://wordpress.org/plugins/webp-express/).
|
52 |
-
| [`ewww`](#ewww) | Connects to *EWWW Image Optimizer* cloud service | Purchasing a key |
|
53 |
-
|
54 |
-
## Installation
|
55 |
-
Instructions regarding getting the individual converters to work are [on the wiki](https://github.com/rosell-dk/webp-convert/wiki)
|
56 |
-
|
57 |
-
## cwebp
|
58 |
-
<table>
|
59 |
-
<tr><th>Requirements</th><td><code>exec()</code> function and that the webserver has permission to run `cwebp` binary (either found in system path, or a precompiled version supplied with this library)</td></tr>
|
60 |
-
<tr><th>Performance</th><td>~40-120ms to convert a 40kb image (depending on *method* option)</td></tr>
|
61 |
-
<tr><th>Reliability</th><td>No problems detected so far!</td></tr>
|
62 |
-
<tr><th>Availability</th><td>According to ewww docs, requirements are met on surprisingly many webhosts. Look <a href="https://docs.ewww.io/article/43-supported-web-hosts">here</a> for a list</td></tr>
|
63 |
-
<tr><th>General options supported</th><td>All (`quality`, `metadata`, `lossless`)</td></tr>
|
64 |
-
<tr><th>Extra options</th><td>`method` (0-6)<br>`use-nice` (boolean)<br>`try-common-system-paths` (boolean)<br> `try-supplied-binary-for-os` (boolean)<br>`autofilter` (boolean)<br>`size-in-percentage` (number / null)<br>`command-line-options` (string)<br>`low-memory` (boolean)</td></tr>
|
65 |
-
</table>
|
66 |
-
|
67 |
-
[cwebp](https://developers.google.com/speed/webp/docs/cwebp) is a WebP conversion command line converter released by Google. Our implementation ships with precompiled binaries for Linux, FreeBSD, WinNT, Darwin and SunOS. If however a cwebp binary is found in a usual location, that binary will be preferred. It is executed with [exec()](http://php.net/manual/en/function.exec.php).
|
68 |
-
|
69 |
-
In more detail, the implementation does this:
|
70 |
-
- It is tested whether cwebp is available in a common system path (eg `/usr/bin/cwebp`, ..)
|
71 |
-
- If not, then supplied binary is selected from `Converters/Binaries` (according to OS) - after validating checksum
|
72 |
-
- Command-line options are generated from the options
|
73 |
-
- If [`nice`]( https://en.wikipedia.org/wiki/Nice_(Unix)) command is found on host, binary is executed with low priority in order to save system resources
|
74 |
-
- Permissions of the generated file are set to be the same as parent folder
|
75 |
-
|
76 |
-
### Cwebp options
|
77 |
-
|
78 |
-
The following options are supported, besides the general options (such as quality, lossless etc):
|
79 |
-
|
80 |
-
| Option | Type | Default |
|
81 |
-
| -------------------------- | ------------------------- | -------------------------- |
|
82 |
-
| autofilter | boolean | false |
|
83 |
-
| command-line-options | string | '' |
|
84 |
-
| low-memory | boolean | false |
|
85 |
-
| method | integer (0-6) | 6 |
|
86 |
-
| near-lossless | integer (0-100) | 60 |
|
87 |
-
| size-in-percentage | integer (0-100) (or null) | null |
|
88 |
-
| rel-path-to-precompiled-binaries | string | './Binaries' |
|
89 |
-
| size-in-percentage | number (or null) | is_null |
|
90 |
-
| try-common-system-paths | boolean | true |
|
91 |
-
| try-supplied-binary-for-os | boolean | true |
|
92 |
-
| use-nice | boolean | false |
|
93 |
-
|
94 |
-
Descriptions (only of some of the options):
|
95 |
-
|
96 |
-
#### the `autofilter` option
|
97 |
-
Turns auto-filter on. This algorithm will spend additional time optimizing the filtering strength to reach a well-balanced quality. Unfortunately, it is extremely expensive in terms of computation. It takes about 5-10 times longer to do a conversion. A 1MB picture which perhaps typically takes about 2 seconds to convert, will takes about 15 seconds to convert with auto-filter. So in most cases, you will want to leave this at its default, which is off.
|
98 |
-
|
99 |
-
#### the `command-line-options` option
|
100 |
-
This allows you to set any parameter available for cwebp in the same way as you would do when executing *cwebp*. You could ie set it to "-sharpness 5 -mt -crop 10 10 40 40". Read more about all the available parameters in [the docs](https://developers.google.com/speed/webp/docs/cwebp)
|
101 |
-
|
102 |
-
#### the `low-memory` option
|
103 |
-
Reduce memory usage of lossy encoding at the cost of ~30% longer encoding time and marginally larger output size. Default: `false`. Read more in [the docs](https://developers.google.com/speed/webp/docs/cwebp). Default: *false*
|
104 |
-
|
105 |
-
#### The `method` option
|
106 |
-
This parameter controls the trade off between encoding speed and the compressed file size and quality. Possible values range from 0 to 6. 0 is fastest. 6 results in best quality.
|
107 |
-
|
108 |
-
#### the `near-lossless` option
|
109 |
-
Specify the level of near-lossless image preprocessing. This option adjusts pixel values to help compressibility, but has minimal impact on the visual quality. It triggers lossless compression mode automatically. The range is 0 (maximum preprocessing) to 100 (no preprocessing). The typical value is around 60. Read more [here](https://groups.google.com/a/webmproject.org/forum/#!topic/webp-discuss/0GmxDmlexek). Default: 60
|
110 |
-
|
111 |
-
#### The `size-in-percentage` option
|
112 |
-
This option sets the file size, *cwebp* should aim for, in percentage of the original. If you for example set it to *45*, and the source file is 100 kb, *cwebp* will try to create a file with size 45 kb (we use the `-size` option). This is an excellent alternative to the "quality:auto" option. If the quality detection isn't working on your system (and you do not have the rights to install imagick or gmagick), you should consider using this options instead. *Cwebp* is generally able to create webp files with the same quality at about 45% the size. So *45* would be a good choice. The option overrides the quality option. And note that it slows down the conversion - it takes about 2.5 times longer to do a conversion this way, than when quality is specified. Default is *off* (null)
|
113 |
-
|
114 |
-
|
115 |
-
#### final words on cwebp
|
116 |
-
The implementation is based on the work of Shane Bishop for his plugin, [EWWW Image Optimizer](https://ewww.io). Thanks for letting us do that!
|
117 |
-
|
118 |
-
See [the wiki](https://github.com/rosell-dk/webp-convert/wiki/Installing-cwebp---using-official-precompilations) for instructions regarding installing cwebp or using official precompilations.
|
119 |
-
|
120 |
-
## vips
|
121 |
-
<table>
|
122 |
-
<tr><th>Requirements</th><td>Vips extension</td></tr>
|
123 |
-
<tr><th>Performance</th><td>Great</td></tr>
|
124 |
-
<tr><th>Reliability</th><td>No problems detected so far!</td></tr>
|
125 |
-
<tr><th>Availability</th><td>Not that widespread yet, but gaining popularity</td></tr>
|
126 |
-
<tr><th>General options supported</th><td>All (`quality`, `metadata`, `lossless`)</td></tr>
|
127 |
-
<tr><th>Extra options</th><td>`smart-subsample`(boolean)<br>`alpha-quality`(0-100)<br>`near-lossless` (0-100)<br> `preset` (0-6)</td></tr>
|
128 |
-
</table>
|
129 |
-
|
130 |
-
For installation instructions, go [here](https://github.com/libvips/php-vips-ext).
|
131 |
-
|
132 |
-
The options are described [here](https://jcupitt.github.io/libvips/API/current/VipsForeignSave.html#vips-webpsave)
|
133 |
-
|
134 |
-
*near-lossless* is however an integer (0-100), in order to have the option behave like in cwebp.
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
## wpc
|
139 |
-
*WebPConvert Cloud Service*
|
140 |
-
|
141 |
-
<table>
|
142 |
-
<tr><th>Requirements</th><td>Access to a server with [webp-convert-cloud-service](https://github.com/rosell-dk/webp-convert-cloud-service) installed, <code>cURL</code> and PHP >= 5.5.0</td></tr>
|
143 |
-
<tr><th>Performance</th><td>Depends on the server where [webp-convert-cloud-service](https://github.com/rosell-dk/webp-convert-cloud-service) is set up, and the speed of internet connections. But perhaps ~1000ms to convert a 40kb image</td></tr>
|
144 |
-
<tr><th>Reliability</th><td>Great (depends on the reliability on the server where it is set up)</td></tr>
|
145 |
-
<tr><th>Availability</th><td>Should work on <em>almost</em> any webhost</td></tr>
|
146 |
-
<tr><th>General options supported</th><td>All (`quality`, `metadata`, `lossless`)</td></tr>
|
147 |
-
<tr><th>Extra options (old api)</th><td>`url`, `secret`</td></tr>
|
148 |
-
<tr><th>Extra options (new api)</th><td>`url`, `api-version`, `api-key`, `crypt-api-key-in-transfer`</td></tr>
|
149 |
-
</table>
|
150 |
-
|
151 |
-
[wpc](https://github.com/rosell-dk/webp-convert-cloud-service) is an open source cloud service. You do not buy a key, you set it up on a server, or you set up [the Wordpress plugin](https://wordpress.org/plugins/webp-express/). As WebPConvert Cloud Service itself is based on WebPConvert, all options are supported.
|
152 |
-
|
153 |
-
To use it, you need to set the `converter-options` (to add url etc).
|
154 |
-
|
155 |
-
#### Example, where api-key is not crypted, on new API:
|
156 |
-
|
157 |
-
```php
|
158 |
-
WebPConvert::convert($source, $destination, [
|
159 |
-
'max-quality' => 80,
|
160 |
-
'converters' => ['cwebp', 'wpc'],
|
161 |
-
'converter-options' => [
|
162 |
-
'wpc' => [
|
163 |
-
'api-version' => 1, /* from wpc release 1.0.0 */
|
164 |
-
'url' => 'http://example.com/wpc.php',
|
165 |
-
'api-key' => 'my dog is white',
|
166 |
-
'crypt-api-key-in-transfer' => false
|
167 |
-
]
|
168 |
-
]
|
169 |
-
));
|
170 |
-
```
|
171 |
-
|
172 |
-
#### Example, where api-key is crypted:
|
173 |
-
|
174 |
-
```php
|
175 |
-
|
176 |
-
WebPConvert::convert($source, $destination, [
|
177 |
-
'max-quality' => 80,
|
178 |
-
'converters' => ['cwebp', 'wpc'],
|
179 |
-
'converter-options' => [
|
180 |
-
'wpc' => [
|
181 |
-
'api-version' => 1,
|
182 |
-
'url' => 'https://example.com/wpc.php',
|
183 |
-
'api-key' => 'my dog is white',
|
184 |
-
'crypt-api-key-in-transfer' => true
|
185 |
-
],
|
186 |
-
]
|
187 |
-
));
|
188 |
-
```
|
189 |
-
|
190 |
-
In 2.0, you can alternatively set the api key and urls through through the *WPC_API_KEY* and *WPC_API_URL* environment variables. This is a safer place to store it.
|
191 |
-
|
192 |
-
To set an environment variable in Apache, you can use the `SetEnv` directory. Ie, place something like the following in your virtual host / or .htaccess file (replace the key with the one you purchased!)
|
193 |
-
|
194 |
-
```
|
195 |
-
SetEnv WPC_API_KEY my-dog-is-dashed
|
196 |
-
SetEnv WPC_API_URL https://wpc.example.com/wpc.php
|
197 |
-
```
|
198 |
-
|
199 |
-
|
200 |
-
#### Example, old API:
|
201 |
-
|
202 |
-
```php
|
203 |
-
WebPConvert::convert($source, $destination, [
|
204 |
-
'max-quality' => 80,
|
205 |
-
'converters' => ['cwebp', 'wpc'],
|
206 |
-
'converter-options' => [
|
207 |
-
'wpc' => [
|
208 |
-
'url' => 'https://example.com/wpc.php',
|
209 |
-
'secret' => 'my dog is white',
|
210 |
-
],
|
211 |
-
]
|
212 |
-
));
|
213 |
-
```
|
214 |
-
|
215 |
-
|
216 |
-
## ewww
|
217 |
-
|
218 |
-
<table>
|
219 |
-
<tr><th>Requirements</th><td>Valid EWWW Image Optimizer <a href="https://ewww.io/plans/">API key</a>, <code>cURL</code> and PHP >= 5.5.0</td></tr>
|
220 |
-
<tr><th>Performance</th><td>~1300ms to convert a 40kb image</td></tr>
|
221 |
-
<tr><th>Reliability</th><td>Great (but, as with any cloud service, there is a risk of downtime)</td></tr>
|
222 |
-
<tr><th>Availability</th><td>Should work on <em>almost</em> any webhost</td></tr>
|
223 |
-
<tr><th>General options supported</th><td>`quality`, `metadata` (partly)</td></tr>
|
224 |
-
<tr><th>Extra options</th><td>`key`</td></tr>
|
225 |
-
</table>
|
226 |
-
|
227 |
-
EWWW Image Optimizer is a very cheap cloud service for optimizing images. After purchasing an API key, add the converter in the `extra-converters` option, with `key` set to the key. Be aware that the `key` should be stored safely to avoid exploitation - preferably in the environment, ie with [dotenv](https://github.com/vlucas/phpdotenv).
|
228 |
-
|
229 |
-
The EWWW api doesn't support the `lossless` option, but it does automatically convert PNG's losslessly. Metadata is either all or none. If you have set it to something else than one of these, all metadata will be preserved.
|
230 |
-
|
231 |
-
In more detail, the implementation does this:
|
232 |
-
- Validates that there is a key, and that `curl` extension is working
|
233 |
-
- Validates the key, using the [/verify/ endpoint](https://ewww.io/api/) (in order to [protect the EWWW service from unnecessary file uploads, when key has expired](https://github.com/rosell-dk/webp-convert/issues/38))
|
234 |
-
- Converts, using the [/ endpoint](https://ewww.io/api/).
|
235 |
-
|
236 |
-
<details>
|
237 |
-
<summary><strong>Roadmap</strong> 👁</summary>
|
238 |
-
|
239 |
-
The converter could be improved by using `fsockopen` when `cURL` is not available - which is extremely rare. PHP >= 5.5.0 is also widely available (PHP 5.4.0 reached end of life [more than two years ago!](http://php.net/supported-versions.php)).
|
240 |
-
</details>
|
241 |
-
|
242 |
-
#### Example:
|
243 |
-
|
244 |
-
```php
|
245 |
-
WebPConvert::convert($source, $destination, [
|
246 |
-
'max-quality' => 80,
|
247 |
-
'converters' => ['gd', 'ewww'],
|
248 |
-
'converter-options' => [
|
249 |
-
'ewww' => [
|
250 |
-
'key' => 'your-api-key-here'
|
251 |
-
],
|
252 |
-
]
|
253 |
-
));
|
254 |
-
```
|
255 |
-
In 2.0, you can alternatively set the api key by through the *EWWW_API_KEY* environment variable. This is a safer place to store it.
|
256 |
-
|
257 |
-
To set an environment variable in Apache, you can use the `SetEnv` directory. Ie, place something like the following in your virtual host / or .htaccess file (replace the key with the one you purchased!)
|
258 |
-
|
259 |
-
```
|
260 |
-
SetEnv EWWW_API_KEY sP3LyPpsKWZy8CVBTYegzEGN6VsKKKKA
|
261 |
-
```
|
262 |
-
|
263 |
-
## gd
|
264 |
-
|
265 |
-
<table>
|
266 |
-
<tr><th>Requirements</th><td>GD PHP extension and PHP >= 5.5.0 (compiled with WebP support)</td></tr>
|
267 |
-
<tr><th>Performance</th><td>~30ms to convert a 40kb image</td></tr>
|
268 |
-
<tr><th>Reliability</th><td>Not sure - I have experienced corrupted images, but cannot reproduce</td></tr>
|
269 |
-
<tr><th>Availability</th><td>Unfortunately, according to <a href="https://stackoverflow.com/questions/25248382/how-to-create-a-webp-image-in-php">this link</a>, WebP support on shared hosts is rare.</td></tr>
|
270 |
-
<tr><th>General options supported</th><td>`quality`</td></tr>
|
271 |
-
<tr><th>Extra options</th><td>`skip-pngs`</td></tr>
|
272 |
-
</table>
|
273 |
-
|
274 |
-
[imagewebp](http://php.net/manual/en/function.imagewebp.php) is a function that comes with PHP (>5.5.0), *provided* that PHP has been compiled with WebP support.
|
275 |
-
|
276 |
-
`gd` neither supports copying metadata nor exposes any WebP options. Lacking the option to set lossless encoding results in poor encoding of PNGs - the filesize is generally much larger than the original. For this reason, PNG conversion is *disabled* by default, but it can be enabled my setting `skip-pngs` option to `false`.
|
277 |
-
|
278 |
-
Installaition instructions are [available in the wiki](https://github.com/rosell-dk/webp-convert/wiki/Installing-Gd-extension).
|
279 |
-
|
280 |
-
<details>
|
281 |
-
<summary><strong>Known bugs</strong> 👁</summary>
|
282 |
-
Due to a [bug](https://bugs.php.net/bug.php?id=66590), some versions sometimes created corrupted images. That bug can however easily be fixed in PHP (fix was released [here](https://stackoverflow.com/questions/30078090/imagewebp-php-creates-corrupted-webp-files)). However, I have experienced corrupted images *anyway* (but cannot reproduce that bug). So use this converter with caution. The corrupted images look completely transparent in Google Chrome, but have the correct size.
|
283 |
-
</details>
|
284 |
-
|
285 |
-
## imagick
|
286 |
-
|
287 |
-
<table>
|
288 |
-
<tr><th>Requirements</th><td>Imagick PHP extension (compiled with WebP support)</td></tr>
|
289 |
-
<tr><th>Quality</th><td>Poor. [See this issue]( https://github.com/rosell-dk/webp-convert/issues/43)</td></tr>
|
290 |
-
<tr><th>General options supported</th><td>`quality`</td></tr>
|
291 |
-
<tr><th>Extra options</th><td>None</td></tr>
|
292 |
-
<tr><th>Performance</th><td>~20-320ms to convert a 40kb image</td></tr>
|
293 |
-
<tr><th>Reliability</th><td>No problems detected so far</td></tr>
|
294 |
-
<tr><th>Availability</th><td>Probably only available on few shared hosts (if any)</td></tr>
|
295 |
-
</table>
|
296 |
-
|
297 |
-
WebP conversion with `imagick` is fast and [exposes many WebP options](http://www.imagemagick.org/script/webp.php). Unfortunately, WebP support for the `imagick` extension is pretty uncommon. At least not on the systems I have tried (Ubuntu 16.04 and Ubuntu 17.04). But if installed, it works great and has several WebP options.
|
298 |
-
|
299 |
-
See [this page](https://github.com/rosell-dk/webp-convert/wiki/Installing-Imagick-extension) in the Wiki for instructions on installing the extension.
|
300 |
-
|
301 |
-
## imagickbinary
|
302 |
-
<table>
|
303 |
-
<tr><th>Requirements</th><td><code>exec()</code> function and that imagick is installed on webserver, compiled with webp support</td></tr>
|
304 |
-
<tr><th>Performance</th><td>just fine</td></tr>
|
305 |
-
<tr><th>Reliability</th><td>No problems detected so far!</td></tr>
|
306 |
-
<tr><th>Availability</th><td>Not sure</td></tr>
|
307 |
-
<tr><th>General options supported</th><td>`quality`</td></tr>
|
308 |
-
<tr><th>Extra options</th><td>`use-nice` (boolean)</td></tr>
|
309 |
-
</table>
|
310 |
-
|
311 |
-
This converter tryes to execute `convert source.jpg webp:destination.jpg.webp`.
|
312 |
-
|
313 |
-
## stack
|
314 |
-
|
315 |
-
<table>
|
316 |
-
<tr><th>General options supported</th><td>all (passed to the converters in the stack )</td></tr>
|
317 |
-
<tr><th>Extra options</th><td>`converters` (array) and `converter-options` (array)</td></tr>
|
318 |
-
</table>
|
319 |
-
|
320 |
-
Stack implements the functionality you know from `WebPConvert::convert`. In fact, all `WebPConvert::convert` does is to call `Stack::convert($source, $destination, $options, $logger);`
|
321 |
-
|
322 |
-
It has two special options: `converters` and `converter-options`. You can read about those in `docs/api/convert.md`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vendor/rosell-dk/webp-convert/docs/v1.3/converting/convert.md
DELETED
@@ -1,96 +0,0 @@
|
|
1 |
-
# API: The convert() method
|
2 |
-
|
3 |
-
**WebPConvert::convert($source, $destination, $options, $logger)**
|
4 |
-
|
5 |
-
| Parameter | Type | Description |
|
6 |
-
| ---------------- | ------- | ------------------------------------------------------------------------------------------ |
|
7 |
-
| `$source` | String | Absolute path to source image (only forward slashes allowed) |
|
8 |
-
| `$destination` | String | Absolute path to converted image (only forward slashes allowed) |
|
9 |
-
| `$options` (optional) | Array | Array of conversion (option) options |
|
10 |
-
| `$logger` (optional) | Baselogger | Information about the conversion process will be passed to this object. Read more below |
|
11 |
-
|
12 |
-
Returns true if success or false if no converters are *operational*. If any converter seems to have its requirements met (are *operational*), but fails anyway, and no other converters in the stack could convert the image, an the exception from that converter is rethrown (either *ConverterFailedException* or *ConversionDeclinedException*). Exceptions are also thrown if something is wrong entirely (*InvalidFileExtensionException*, *TargetNotFoundException*, *ConverterNotFoundException*, *CreateDestinationFileException*, *CreateDestinationFolderException*, or any unanticipated exceptions thrown by the converters).
|
13 |
-
|
14 |
-
### Available options for all converters
|
15 |
-
|
16 |
-
Many options correspond to options of *cwebp*. These are documented [here](https://developers.google.com/speed/webp/docs/cwebp)
|
17 |
-
|
18 |
-
|
19 |
-
| Option | Type | Default | Description |
|
20 |
-
| ----------------- | ------- | -------------------------- | -------------------------------------------------------------------- |
|
21 |
-
| quality | An integer between 0-100, or "auto" | "auto" | Lossy quality of converted image (JPEG only - PNGs are always losless).<br><br> If set to "auto", *WebPConvert* will try to determine the quality of the JPEG (this is only possible, if Imagick or GraphicsMagic is installed). If successfully determined, the quality of the webp will be set to the same as that of the JPEG. however not to more than specified in the new `max-quality` option. If quality cannot be determined, quality will be set to what is specified in the new `default-quality` option (however, if you use the *wpc* converter, it will also get a shot at detecting the quality) |
|
22 |
-
| max-quality | An integer between 0-100 | 85 | See the `quality` option. Only relevant, when quality is set to "auto".
|
23 |
-
| default-quality | An integer between 0-100 | 75 | See the `quality` option. Only relevant, when quality is set to "auto".
|
24 |
-
| metadata | String | 'none' | Valid values: all, none, exif, icc, xmp. Note: Only *cwebp* supports all values. *gd* will always remove all metadata. *ewww*, *imagick* and *gmagick* can either strip all, or keep all (they will keep all, unless metadata is set to *none*) |
|
25 |
-
| lossless | Boolean | false ("auto" for pngs in 2.0) | Encode the image without any loss. The option is ignored for PNG's (forced true). In 2.0, it can also be "auto", and it is not forced to anything - rather it deafaults to false for Jpegs and "auto" for PNGs |
|
26 |
-
| converters | Array | ['cwebp', 'gd', 'imagick'] | Specify conversion methods to use, and their order. Also optionally set converter options (see below) |
|
27 |
-
| converter-options | Array | [] | Set options of the individual converters (see below) |
|
28 |
-
| jpeg | Array | null | These options will be merged into the other options when source is jpeg |
|
29 |
-
| png | Array | null | These options will be merged into the other options when source is jpeg |
|
30 |
-
| skip (new in 2.0) | Boolean | false | If true, conversion will be skipped (ie for skipping png conversion for some converters) |
|
31 |
-
| skip-png (removed in 2.0) | Boolean | false | If true, conversion will be skipped for png (ie for skipping png conversion for some converters) |
|
32 |
-
|
33 |
-
#### More on quality=auto
|
34 |
-
Unfortunately, *libwebp* does not provide a way to use the same quality for the converted image, as for source. This feature is implemented by *imagick* and *gmagick*. No matter which conversion method you choose, if you set *quality* to *auto*, our library will try to detect the quality of the source file using one of these libraries. If this isn't available, it will revert to the value set in the *default-quality* option (75 per default). *However*, with the *wpc* converter you have a second chance: If quality cannot be detected locally, it will send quality="auto" to *wpc*.
|
35 |
-
|
36 |
-
The bottom line is: If you do not have imagick or gmagick installed on your host (and have no way to install it), your best option quality-wise is to install *wpc* on a server that you do have access to, and connect to that. However,... read on:
|
37 |
-
|
38 |
-
**How much does it matter?**
|
39 |
-
The effect of not having quality detection is that jpeg images with medium quality (say 50) will be converted with higher quality (say 75). Converting a q=50 to a q=50 would typically result in a ~60% reduction. But converting it to q=75 will only result in a ~45% reduction. When converting low quality jpeg images, it gets worse. Converting q=30 to q=75 only achieves ~25% reduction.
|
40 |
-
|
41 |
-
I guess it is a rare case having jpeg images in low quality. Even having middle quality is rare, as there seems to have been a tendency to choose higher quality than actually needed for web. So, in many cases, the impact of not having quality detection is minor. If you set the *default-quality* a bit low, ie 65, you will further minimize the effect.
|
42 |
-
|
43 |
-
To determine if *webp-convert* is able to autodetect quality on your system, run a conversion with the *$logger* parameter set to `new EchoLogger()` (see api).
|
44 |
-
|
45 |
-
#### More on the `converter-options` option
|
46 |
-
You use this option to set options for the individual converters. Example:
|
47 |
-
|
48 |
-
```
|
49 |
-
'converter-options' => [
|
50 |
-
'ewww' => [
|
51 |
-
'key' => 'your-api-key-here'
|
52 |
-
],
|
53 |
-
'wpc' => [
|
54 |
-
'url' => 'https://example.com/wpc.php',
|
55 |
-
'secret' => 'my dog is white'
|
56 |
-
]
|
57 |
-
]
|
58 |
-
```
|
59 |
-
Besides options that are special to a converter, you can also override general options. For example, you may generally want the `max-quality` to be 85, but for a single converter, you would like it to be 100 (sorry, it is hard to come up with a useful example).
|
60 |
-
|
61 |
-
#### More on the `converters` option
|
62 |
-
The *converters* option specifies the conversion methods to use and their order. But it can also be used as an alternative way of setting converter options. Usually, you probably want to use the *converter-options* for that, but there may be cases where it is more convenient to specify them here. Also, specifying here allows you to put the same converter method to the stack multiple times, with different options (this could for example be used to have an extra *ewww* converter as a fallback).
|
63 |
-
|
64 |
-
Example:
|
65 |
-
```
|
66 |
-
WebPConvert::convert($source, $destination, [
|
67 |
-
'converters' => [
|
68 |
-
'cwebp',
|
69 |
-
'imagick',
|
70 |
-
[
|
71 |
-
'converter' => 'ewww',
|
72 |
-
'options' => [
|
73 |
-
'key' => 'your api key here',
|
74 |
-
],
|
75 |
-
],
|
76 |
-
];
|
77 |
-
)
|
78 |
-
```
|
79 |
-
In 2.0, it will be possible to use your own custom converter. Instead of the "converter id" (ie "ewww"), specify the full class name of your custom converter. Ie '\\MyProject\\BraveConverter'. The converter must extend `\WebPConvert\Convert\Converters\AbstractConverters\AbstractConverter` and you must implement `doConvert()` and the define the extra options it takes (check out how it is done in the build-in converters).
|
80 |
-
|
81 |
-
### More on the `$logger` parameter
|
82 |
-
WebPConvert and the individual converters can provide information regarding the conversion process. Per default (when the parameter isn't provided), they write this to `\WebPConvert\Loggers\VoidLogger`, which does nothing with it.
|
83 |
-
In order to get this information echoed out, you can use `\WebPConvert\Loggers\EchoLogger` - like this:
|
84 |
-
|
85 |
-
```php
|
86 |
-
use WebPConvert\Loggers\EchoLogger;
|
87 |
-
|
88 |
-
WebPConvert::convert($source, $destination, $options, new EchoLogger());
|
89 |
-
```
|
90 |
-
|
91 |
-
In order to do something else with the information (perhaps write it to a log file?), you can extend `\WebPConvert\Loggers\BaseLogger`.
|
92 |
-
|
93 |
-
## Converters
|
94 |
-
In the most basic design, a converter consists of a static convert function which takes the same arguments as `WebPConvert::convert`. Its job is then to convert `$source` to WebP and save it at `$destination`, preferably taking the options specified in $options into account.
|
95 |
-
|
96 |
-
The converters may be called directly. But you probably don't want to do that, as it really doesn't hurt having other converters ready to take over, in case your preferred converter should fail.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vendor/rosell-dk/webp-convert/docs/v1.3/converting/converters.md
DELETED
@@ -1,322 +0,0 @@
|
|
1 |
-
# The webp converters
|
2 |
-
|
3 |
-
## The converters at a glance
|
4 |
-
When it comes to webp conversion, there is actually only one library in town: *libwebp* from Google. All conversion methods below ultimately uses that very same library for conversion. This means that it does not matter much, which conversion method you use. Whatever works. There is however one thing to take note of, if you set *quality* to *auto*, and your system cannot determine the quality of the source (this requires imagick or gmagick), and you do not have access to install those, then the only way to get quality-detection is to connect to a *wpc* cloud converter. However, with *cwebp*, you can specify the desired reduction (the *size-in-percentage* option) - at the cost of doubling the conversion time. Read more about those considerations in the API.
|
5 |
-
|
6 |
-
Speed-wise, there is too little difference for it to matter, considering that images usually needs to be converted just once. Anyway, here are the results: *cweb* is the fastest (with method=3). *gd* is right behind, merely 3% slower than *cwebp*. *gmagick* are third place, ~8% slower than *cwebp*. *imagick* comes in ~22% slower than *cwebp*. *ewww* depends on connection speed. On my *digital ocean* account, it takes ~2 seconds to upload, convert, and download a tiny image (10 times longer than the local *cwebp*). A 1MB image however only takes ~4.5 seconds to upload, convert and download (1.5 seconds longer). A 2 MB image takes ~5 seconds to convert (only 16% longer than my *cwebp*). The *ewww* thus converts at a very decent speeds. Probably faster than your average shared host. If multiple big images needs to be converted at the same time, *ewww* will probably perform much better than the local converters.
|
7 |
-
|
8 |
-
[`cwebp`](#cwebp) works by executing the *cwebp* binary from Google, which is build upon the *libwebp* (also from Google). That library is actually the only library in town for generating webp images, which means that the other conversion methods ultimately uses that very same library. Which again means that the results using the different methods are very similar. However, with *cwebp*, we have more parameters to tweak than with the rest. We for example have the *method* option, which controls the trade off between encoding speed and the compressed file size and quality. Setting this to max, we can squeeze the images a few percent extra - without loosing quality (the converter is still pretty fast, so in most cases it is probably worth it).
|
9 |
-
|
10 |
-
Of course, as we here have to call a binary directly, *cwebp* requires the *exec* function to be enabled, and that the webserver user is allowed to execute the `cwebp` binary (either at known system locations, or one of the precompiled binaries, that comes with this library).
|
11 |
-
|
12 |
-
[`vips`](#vips) (**new in 2.0**) works by using the vips extension, if available. Vips is great! It offers many webp options, it is fast and installation is easier than imagick and gd, as it does not need to be configured for webp support.
|
13 |
-
|
14 |
-
[`imagick`](#imagick) does not support any special webp options, but is at least able to strip all metadata, if metadata is set to none. Imagick has a very nice feature - that it is able to detect the quality of a jpeg file. This enables it to automatically use same quality for destination as for source, which eliminates the risk of setting quality higher for the destination than for source (the result of that is that the file size gets higher, but the quality remains the same). As the other converters lends this capability from Imagick, this is however no reason for using Imagick rather than the other converters. Requirements: Imagick PHP extension compiled with WebP support
|
15 |
-
|
16 |
-
[`gmagick`](#gmagick) uses the *gmagick* extension. It is very similar to *imagick*. Requirements: Gmagick PHP extension compiled with WebP support.
|
17 |
-
|
18 |
-
[`gd`](#gd) uses the *Gd* extension to do the conversion. The *Gd* extension is pretty common, so the main feature of this converter is that it may work out of the box. It does not support any webp options, and does not support stripping metadata. Requirements: GD PHP extension compiled with WebP support.
|
19 |
-
|
20 |
-
[`wpc`](#wpc) is an open source cloud service for converting images to webp. To use it, you must either install [webp-convert-cloud-service](https://github.com/rosell-dk/webp-convert-cloud-service) directly on a remote server, or install the Wordpress plugin, [WebP Express](https://github.com/rosell-dk/webp-express) in Wordpress. Btw: Beware that upload limits will prevent conversion of big images. The converter checks your *php.ini* settings and abandons upload right away, if an image is larger than your *upload_max_filesize* or your *post_max_size* setting. Requirements: Access to a running service. The service can be installed [directly](https://github.com/rosell-dk/webp-convert-cloud-service) or by using [this Wordpress plugin](https://wordpress.org/plugins/webp-express/)
|
21 |
-
|
22 |
-
[`ewww`](#ewww) is also a cloud service. Not free, but cheap enough to be considered *practically* free. It supports lossless encoding, but this cannot be controlled. *Ewww* always uses lossy encoding for jpeg and lossless for png. For jpegs this is usually a good choice, however, many pngs are compressed better using lossy encoding. As lossless cannot be controlled, the "lossless:auto" option cannot be used for automatically trying both lossy and lossless and picking the smallest file. Also, unfortunately, *ewww* does not support quality=auto, like *wpc*, and it does not support *size-in-percentage* like *cwebp*, either. I have requested such features, and he is considering... As with *wpc*, beware of upload limits. Requirements: A key to the *EWWW Image Optimizer* cloud service. Can be purchaced [here](https://ewww.io/plans/)
|
23 |
-
|
24 |
-
[`stack`](#stack) takes a stack of converters and tries it from the top, until success. The main convert method actually calls this converter. Stacks within stacks are supported (not really needed, though).
|
25 |
-
|
26 |
-
|
27 |
-
**Summary:**
|
28 |
-
|
29 |
-
| | cwebp | vips | imagickbinary | imagick / gmagick | gd | ewww |
|
30 |
-
| ------------------------------------------ | --------- | ------ | -------------- | ----------------- | --------- | ------ |
|
31 |
-
| supports lossless encoding ? | yes | yes | yes | no | no | yes |
|
32 |
-
| supports lossless auto ? | yes | yes | yes | no | no | no |
|
33 |
-
| supports near-lossless ? | yes | yes | no | no | no | ? |
|
34 |
-
| supports metadata stripping / preserving | yes | yes | yes | yes | no | ? |
|
35 |
-
| supports setting alpha quality | yes | yes | yes | no | no | no |
|
36 |
-
| supports fixed quality (for lossy) | yes | yes | yes | yes | yes | yes |
|
37 |
-
| supports auto quality without help | no | no | yes | yes | no | no |
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
*WebPConvert* currently supports the following converters:
|
42 |
-
|
43 |
-
| Converter | Method | Requirements |
|
44 |
-
| ------------------------------------ | ------------------------------------------------ | -------------------------------------------------- |
|
45 |
-
| [`cwebp`](#cwebp) | Calls `cwebp` binary directly | `exec()` function *and* that the webserver user has permission to run `cwebp` binary |
|
46 |
-
| [`vips`](#vips) (new in 2.0) | Vips extension | Vips extension |
|
47 |
-
| [`imagick`](#imagick) | Imagick extension (`ImageMagick` wrapper) | Imagick PHP extension compiled with WebP support |
|
48 |
-
| [`gmagick`](#gmagick) | Gmagick extension (`ImageMagick` wrapper) | Gmagick PHP extension compiled with WebP support |
|
49 |
-
| [`gd`](#gd) | GD Graphics (Draw) extension (`LibGD` wrapper) | GD PHP extension compiled with WebP support |
|
50 |
-
| [`imagickbinary`](#imagickbinary) | Calls imagick binary directly | exec() and imagick installed and compiled with WebP support |
|
51 |
-
| [`wpc`](#wpc) | Connects to an open source cloud service | Access to a running service. The service can be installed [directly](https://github.com/rosell-dk/webp-convert-cloud-service) or by using [this Wordpress plugin](https://wordpress.org/plugins/webp-express/).
|
52 |
-
| [`ewww`](#ewww) | Connects to *EWWW Image Optimizer* cloud service | Purchasing a key |
|
53 |
-
|
54 |
-
## Installation
|
55 |
-
Instructions regarding getting the individual converters to work are [on the wiki](https://github.com/rosell-dk/webp-convert/wiki)
|
56 |
-
|
57 |
-
## cwebp
|
58 |
-
<table>
|
59 |
-
<tr><th>Requirements</th><td><code>exec()</code> function and that the webserver has permission to run `cwebp` binary (either found in system path, or a precompiled version supplied with this library)</td></tr>
|
60 |
-
<tr><th>Performance</th><td>~40-120ms to convert a 40kb image (depending on *method* option)</td></tr>
|
61 |
-
<tr><th>Reliability</th><td>No problems detected so far!</td></tr>
|
62 |
-
<tr><th>Availability</th><td>According to ewww docs, requirements are met on surprisingly many webhosts. Look <a href="https://docs.ewww.io/article/43-supported-web-hosts">here</a> for a list</td></tr>
|
63 |
-
<tr><th>General options supported</th><td>All (`quality`, `metadata`, `lossless`)</td></tr>
|
64 |
-
<tr><th>Extra options</th><td>`method` (0-6)<br>`use-nice` (boolean)<br>`try-common-system-paths` (boolean)<br> `try-supplied-binary-for-os` (boolean)<br>`autofilter` (boolean)<br>`size-in-percentage` (number / null)<br>`command-line-options` (string)<br>`low-memory` (boolean)</td></tr>
|
65 |
-
</table>
|
66 |
-
|
67 |
-
[cwebp](https://developers.google.com/speed/webp/docs/cwebp) is a WebP conversion command line converter released by Google. Our implementation ships with precompiled binaries for Linux, FreeBSD, WinNT, Darwin and SunOS. If however a cwebp binary is found in a usual location, that binary will be preferred. It is executed with [exec()](http://php.net/manual/en/function.exec.php).
|
68 |
-
|
69 |
-
In more detail, the implementation does this:
|
70 |
-
- It is tested whether cwebp is available in a common system path (eg `/usr/bin/cwebp`, ..)
|
71 |
-
- If not, then supplied binary is selected from `Converters/Binaries` (according to OS) - after validating checksum
|
72 |
-
- Command-line options are generated from the options
|
73 |
-
- If [`nice`]( https://en.wikipedia.org/wiki/Nice_(Unix)) command is found on host, binary is executed with low priority in order to save system resources
|
74 |
-
- Permissions of the generated file are set to be the same as parent folder
|
75 |
-
|
76 |
-
### Cwebp options
|
77 |
-
|
78 |
-
The following options are supported, besides the general options (such as quality, lossless etc):
|
79 |
-
|
80 |
-
| Option | Type | Default |
|
81 |
-
| -------------------------- | ------------------------- | -------------------------- |
|
82 |
-
| autofilter | boolean | false |
|
83 |
-
| command-line-options | string | '' |
|
84 |
-
| low-memory | boolean | false |
|
85 |
-
| method | integer (0-6) | 6 |
|
86 |
-
| near-lossless | integer (0-100) | 60 |
|
87 |
-
| size-in-percentage | integer (0-100) (or null) | null |
|
88 |
-
| rel-path-to-precompiled-binaries | string | './Binaries' |
|
89 |
-
| size-in-percentage | number (or null) | is_null |
|
90 |
-
| try-common-system-paths | boolean | true |
|
91 |
-
| try-supplied-binary-for-os | boolean | true |
|
92 |
-
| use-nice | boolean | false |
|
93 |
-
|
94 |
-
Descriptions (only of some of the options):
|
95 |
-
|
96 |
-
#### the `autofilter` option
|
97 |
-
Turns auto-filter on. This algorithm will spend additional time optimizing the filtering strength to reach a well-balanced quality. Unfortunately, it is extremely expensive in terms of computation. It takes about 5-10 times longer to do a conversion. A 1MB picture which perhaps typically takes about 2 seconds to convert, will takes about 15 seconds to convert with auto-filter. So in most cases, you will want to leave this at its default, which is off.
|
98 |
-
|
99 |
-
#### the `command-line-options` option
|
100 |
-
This allows you to set any parameter available for cwebp in the same way as you would do when executing *cwebp*. You could ie set it to "-sharpness 5 -mt -crop 10 10 40 40". Read more about all the available parameters in [the docs](https://developers.google.com/speed/webp/docs/cwebp)
|
101 |
-
|
102 |
-
#### the `low-memory` option
|
103 |
-
Reduce memory usage of lossy encoding at the cost of ~30% longer encoding time and marginally larger output size. Default: `false`. Read more in [the docs](https://developers.google.com/speed/webp/docs/cwebp). Default: *false*
|
104 |
-
|
105 |
-
#### The `method` option
|
106 |
-
This parameter controls the trade off between encoding speed and the compressed file size and quality. Possible values range from 0 to 6. 0 is fastest. 6 results in best quality.
|
107 |
-
|
108 |
-
#### the `near-lossless` option
|
109 |
-
Specify the level of near-lossless image preprocessing. This option adjusts pixel values to help compressibility, but has minimal impact on the visual quality. It triggers lossless compression mode automatically. The range is 0 (maximum preprocessing) to 100 (no preprocessing). The typical value is around 60. Read more [here](https://groups.google.com/a/webmproject.org/forum/#!topic/webp-discuss/0GmxDmlexek). Default: 60
|
110 |
-
|
111 |
-
#### The `size-in-percentage` option
|
112 |
-
This option sets the file size, *cwebp* should aim for, in percentage of the original. If you for example set it to *45*, and the source file is 100 kb, *cwebp* will try to create a file with size 45 kb (we use the `-size` option). This is an excellent alternative to the "quality:auto" option. If the quality detection isn't working on your system (and you do not have the rights to install imagick or gmagick), you should consider using this options instead. *Cwebp* is generally able to create webp files with the same quality at about 45% the size. So *45* would be a good choice. The option overrides the quality option. And note that it slows down the conversion - it takes about 2.5 times longer to do a conversion this way, than when quality is specified. Default is *off* (null)
|
113 |
-
|
114 |
-
|
115 |
-
#### final words on cwebp
|
116 |
-
The implementation is based on the work of Shane Bishop for his plugin, [EWWW Image Optimizer](https://ewww.io). Thanks for letting us do that!
|
117 |
-
|
118 |
-
See [the wiki](https://github.com/rosell-dk/webp-convert/wiki/Installing-cwebp---using-official-precompilations) for instructions regarding installing cwebp or using official precompilations.
|
119 |
-
|
120 |
-
## vips
|
121 |
-
<table>
|
122 |
-
<tr><th>Requirements</th><td>Vips extension</td></tr>
|
123 |
-
<tr><th>Performance</th><td>Great</td></tr>
|
124 |
-
<tr><th>Reliability</th><td>No problems detected so far!</td></tr>
|
125 |
-
<tr><th>Availability</th><td>Not that widespread yet, but gaining popularity</td></tr>
|
126 |
-
<tr><th>General options supported</th><td>All (`quality`, `metadata`, `lossless`)</td></tr>
|
127 |
-
<tr><th>Extra options</th><td>`smart-subsample`(boolean)<br>`alpha-quality`(0-100)<br>`near-lossless` (0-100)<br> `preset` (0-6)</td></tr>
|
128 |
-
</table>
|
129 |
-
|
130 |
-
For installation instructions, go [here](https://github.com/libvips/php-vips-ext).
|
131 |
-
|
132 |
-
The options are described [here](https://jcupitt.github.io/libvips/API/current/VipsForeignSave.html#vips-webpsave)
|
133 |
-
|
134 |
-
*near-lossless* is however an integer (0-100), in order to have the option behave like in cwebp.
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
## wpc
|
139 |
-
*WebPConvert Cloud Service*
|
140 |
-
|
141 |
-
<table>
|
142 |
-
<tr><th>Requirements</th><td>Access to a server with [webp-convert-cloud-service](https://github.com/rosell-dk/webp-convert-cloud-service) installed, <code>cURL</code> and PHP >= 5.5.0</td></tr>
|
143 |
-
<tr><th>Performance</th><td>Depends on the server where [webp-convert-cloud-service](https://github.com/rosell-dk/webp-convert-cloud-service) is set up, and the speed of internet connections. But perhaps ~1000ms to convert a 40kb image</td></tr>
|
144 |
-
<tr><th>Reliability</th><td>Great (depends on the reliability on the server where it is set up)</td></tr>
|
145 |
-
<tr><th>Availability</th><td>Should work on <em>almost</em> any webhost</td></tr>
|
146 |
-
<tr><th>General options supported</th><td>All (`quality`, `metadata`, `lossless`)</td></tr>
|
147 |
-
<tr><th>Extra options (old api)</th><td>`url`, `secret`</td></tr>
|
148 |
-
<tr><th>Extra options (new api)</th><td>`url`, `api-version`, `api-key`, `crypt-api-key-in-transfer`</td></tr>
|
149 |
-
</table>
|
150 |
-
|
151 |
-
[wpc](https://github.com/rosell-dk/webp-convert-cloud-service) is an open source cloud service. You do not buy a key, you set it up on a server, or you set up [the Wordpress plugin](https://wordpress.org/plugins/webp-express/). As WebPConvert Cloud Service itself is based on WebPConvert, all options are supported.
|
152 |
-
|
153 |
-
To use it, you need to set the `converter-options` (to add url etc).
|
154 |
-
|
155 |
-
#### Example, where api-key is not crypted, on new API:
|
156 |
-
|
157 |
-
```php
|
158 |
-
WebPConvert::convert($source, $destination, [
|
159 |
-
'max-quality' => 80,
|
160 |
-
'converters' => ['cwebp', 'wpc'],
|
161 |
-
'converter-options' => [
|
162 |
-
'wpc' => [
|
163 |
-
'api-version' => 1, /* from wpc release 1.0.0 */
|
164 |
-
'url' => 'http://example.com/wpc.php',
|
165 |
-
'api-key' => 'my dog is white',
|
166 |
-
'crypt-api-key-in-transfer' => false
|
167 |
-
]
|
168 |
-
]
|
169 |
-
));
|
170 |
-
```
|
171 |
-
|
172 |
-
#### Example, where api-key is crypted:
|
173 |
-
|
174 |
-
```php
|
175 |
-
|
176 |
-
WebPConvert::convert($source, $destination, [
|
177 |
-
'max-quality' => 80,
|
178 |
-
'converters' => ['cwebp', 'wpc'],
|
179 |
-
'converter-options' => [
|
180 |
-
'wpc' => [
|
181 |
-
'api-version' => 1,
|
182 |
-
'url' => 'https://example.com/wpc.php',
|
183 |
-
'api-key' => 'my dog is white',
|
184 |
-
'crypt-api-key-in-transfer' => true
|
185 |
-
],
|
186 |
-
]
|
187 |
-
));
|
188 |
-
```
|
189 |
-
|
190 |
-
In 2.0, you can alternatively set the api key and urls through through the *WPC_API_KEY* and *WPC_API_URL* environment variables. This is a safer place to store it.
|
191 |
-
|
192 |
-
To set an environment variable in Apache, you can use the `SetEnv` directory. Ie, place something like the following in your virtual host / or .htaccess file (replace the key with the one you purchased!)
|
193 |
-
|
194 |
-
```
|
195 |
-
SetEnv WPC_API_KEY my-dog-is-dashed
|
196 |
-
SetEnv WPC_API_URL https://wpc.example.com/wpc.php
|
197 |
-
```
|
198 |
-
|
199 |
-
|
200 |
-
#### Example, old API:
|
201 |
-
|
202 |
-
```php
|
203 |
-
WebPConvert::convert($source, $destination, [
|
204 |
-
'max-quality' => 80,
|
205 |
-
'converters' => ['cwebp', 'wpc'],
|
206 |
-
'converter-options' => [
|
207 |
-
'wpc' => [
|
208 |
-
'url' => 'https://example.com/wpc.php',
|
209 |
-
'secret' => 'my dog is white',
|
210 |
-
],
|
211 |
-
]
|
212 |
-
));
|
213 |
-
```
|
214 |
-
|
215 |
-
|
216 |
-
## ewww
|
217 |
-
|
218 |
-
<table>
|
219 |
-
<tr><th>Requirements</th><td>Valid EWWW Image Optimizer <a href="https://ewww.io/plans/">API key</a>, <code>cURL</code> and PHP >= 5.5.0</td></tr>
|
220 |
-
<tr><th>Performance</th><td>~1300ms to convert a 40kb image</td></tr>
|
221 |
-
<tr><th>Reliability</th><td>Great (but, as with any cloud service, there is a risk of downtime)</td></tr>
|
222 |
-
<tr><th>Availability</th><td>Should work on <em>almost</em> any webhost</td></tr>
|
223 |
-
<tr><th>General options supported</th><td>`quality`, `metadata` (partly)</td></tr>
|
224 |
-
<tr><th>Extra options</th><td>`key`</td></tr>
|
225 |
-
</table>
|
226 |
-
|
227 |
-
EWWW Image Optimizer is a very cheap cloud service for optimizing images. After purchasing an API key, add the converter in the `extra-converters` option, with `key` set to the key. Be aware that the `key` should be stored safely to avoid exploitation - preferably in the environment, ie with [dotenv](https://github.com/vlucas/phpdotenv).
|
228 |
-
|
229 |
-
The EWWW api doesn't support the `lossless` option, but it does automatically convert PNG's losslessly. Metadata is either all or none. If you have set it to something else than one of these, all metadata will be preserved.
|
230 |
-
|
231 |
-
In more detail, the implementation does this:
|
232 |
-
- Validates that there is a key, and that `curl` extension is working
|
233 |
-
- Validates the key, using the [/verify/ endpoint](https://ewww.io/api/) (in order to [protect the EWWW service from unnecessary file uploads, when key has expired](https://github.com/rosell-dk/webp-convert/issues/38))
|
234 |
-
- Converts, using the [/ endpoint](https://ewww.io/api/).
|
235 |
-
|
236 |
-
<details>
|
237 |
-
<summary><strong>Roadmap</strong> 👁</summary>
|
238 |
-
|
239 |
-
The converter could be improved by using `fsockopen` when `cURL` is not available - which is extremely rare. PHP >= 5.5.0 is also widely available (PHP 5.4.0 reached end of life [more than two years ago!](http://php.net/supported-versions.php)).
|
240 |
-
</details>
|
241 |
-
|
242 |
-
#### Example:
|
243 |
-
|
244 |
-
```php
|
245 |
-
WebPConvert::convert($source, $destination, [
|
246 |
-
'max-quality' => 80,
|
247 |
-
'converters' => ['gd', 'ewww'],
|
248 |
-
'converter-options' => [
|
249 |
-
'ewww' => [
|
250 |
-
'key' => 'your-api-key-here'
|
251 |
-
],
|
252 |
-
]
|
253 |
-
));
|
254 |
-
```
|
255 |
-
In 2.0, you can alternatively set the api key by through the *EWWW_API_KEY* environment variable. This is a safer place to store it.
|
256 |
-
|
257 |
-
To set an environment variable in Apache, you can use the `SetEnv` directory. Ie, place something like the following in your virtual host / or .htaccess file (replace the key with the one you purchased!)
|
258 |
-
|
259 |
-
```
|
260 |
-
SetEnv EWWW_API_KEY sP3LyPpsKWZy8CVBTYegzEGN6VsKKKKA
|
261 |
-
```
|
262 |
-
|
263 |
-
## gd
|
264 |
-
|
265 |
-
<table>
|
266 |
-
<tr><th>Requirements</th><td>GD PHP extension and PHP >= 5.5.0 (compiled with WebP support)</td></tr>
|
267 |
-
<tr><th>Performance</th><td>~30ms to convert a 40kb image</td></tr>
|
268 |
-
<tr><th>Reliability</th><td>Not sure - I have experienced corrupted images, but cannot reproduce</td></tr>
|
269 |
-
<tr><th>Availability</th><td>Unfortunately, according to <a href="https://stackoverflow.com/questions/25248382/how-to-create-a-webp-image-in-php">this link</a>, WebP support on shared hosts is rare.</td></tr>
|
270 |
-
<tr><th>General options supported</th><td>`quality`</td></tr>
|
271 |
-
<tr><th>Extra options</th><td>`skip-pngs`</td></tr>
|
272 |
-
</table>
|
273 |
-
|
274 |
-
[imagewebp](http://php.net/manual/en/function.imagewebp.php) is a function that comes with PHP (>5.5.0), *provided* that PHP has been compiled with WebP support.
|
275 |
-
|
276 |
-
`gd` neither supports copying metadata nor exposes any WebP options. Lacking the option to set lossless encoding results in poor encoding of PNGs - the filesize is generally much larger than the original. For this reason, PNG conversion is *disabled* by default, but it can be enabled my setting `skip-pngs` option to `false`.
|
277 |
-
|
278 |
-
Installaition instructions are [available in the wiki](https://github.com/rosell-dk/webp-convert/wiki/Installing-Gd-extension).
|
279 |
-
|
280 |
-
<details>
|
281 |
-
<summary><strong>Known bugs</strong> 👁</summary>
|
282 |
-
Due to a [bug](https://bugs.php.net/bug.php?id=66590), some versions sometimes created corrupted images. That bug can however easily be fixed in PHP (fix was released [here](https://stackoverflow.com/questions/30078090/imagewebp-php-creates-corrupted-webp-files)). However, I have experienced corrupted images *anyway* (but cannot reproduce that bug). So use this converter with caution. The corrupted images look completely transparent in Google Chrome, but have the correct size.
|
283 |
-
</details>
|
284 |
-
|
285 |
-
## imagick
|
286 |
-
|
287 |
-
<table>
|
288 |
-
<tr><th>Requirements</th><td>Imagick PHP extension (compiled with WebP support)</td></tr>
|
289 |
-
<tr><th>Quality</th><td>Poor. [See this issue]( https://github.com/rosell-dk/webp-convert/issues/43)</td></tr>
|
290 |
-
<tr><th>General options supported</th><td>`quality`</td></tr>
|
291 |
-
<tr><th>Extra options</th><td>None</td></tr>
|
292 |
-
<tr><th>Performance</th><td>~20-320ms to convert a 40kb image</td></tr>
|
293 |
-
<tr><th>Reliability</th><td>No problems detected so far</td></tr>
|
294 |
-
<tr><th>Availability</th><td>Probably only available on few shared hosts (if any)</td></tr>
|
295 |
-
</table>
|
296 |
-
|
297 |
-
WebP conversion with `imagick` is fast and [exposes many WebP options](http://www.imagemagick.org/script/webp.php). Unfortunately, WebP support for the `imagick` extension is pretty uncommon. At least not on the systems I have tried (Ubuntu 16.04 and Ubuntu 17.04). But if installed, it works great and has several WebP options.
|
298 |
-
|
299 |
-
See [this page](https://github.com/rosell-dk/webp-convert/wiki/Installing-Imagick-extension) in the Wiki for instructions on installing the extension.
|
300 |
-
|
301 |
-
## imagickbinary
|
302 |
-
<table>
|
303 |
-
<tr><th>Requirements</th><td><code>exec()</code> function and that imagick is installed on webserver, compiled with webp support</td></tr>
|
304 |
-
<tr><th>Performance</th><td>just fine</td></tr>
|
305 |
-
<tr><th>Reliability</th><td>No problems detected so far!</td></tr>
|
306 |
-
<tr><th>Availability</th><td>Not sure</td></tr>
|
307 |
-
<tr><th>General options supported</th><td>`quality`</td></tr>
|
308 |
-
<tr><th>Extra options</th><td>`use-nice` (boolean)</td></tr>
|
309 |
-
</table>
|
310 |
-
|
311 |
-
This converter tryes to execute `convert source.jpg webp:destination.jpg.webp`.
|
312 |
-
|
313 |
-
## stack
|
314 |
-
|
315 |
-
<table>
|
316 |
-
<tr><th>General options supported</th><td>all (passed to the converters in the stack )</td></tr>
|
317 |
-
<tr><th>Extra options</th><td>`converters` (array) and `converter-options` (array)</td></tr>
|
318 |
-
</table>
|
319 |
-
|
320 |
-
Stack implements the functionality you know from `WebPConvert::convert`. In fact, all `WebPConvert::convert` does is to call `Stack::convert($source, $destination, $options, $logger);`
|
321 |
-
|
322 |
-
It has two special options: `converters` and `converter-options`. You can read about those in `docs/api/convert.md`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vendor/rosell-dk/webp-convert/docs/v1.3/serving/convert-and-serve.md
DELETED
@@ -1,167 +0,0 @@
|
|
1 |
-
# API: The WebPConvert::convertAndServe() method
|
2 |
-
|
3 |
-
*NOTE:* In 2.0, the method is renamed to *serveConverted* ("convertAndServe" was implying that a conversion was always made, but the method simply serves destination if it exists and is smaller and newer than source)
|
4 |
-
|
5 |
-
The method tries to serve a converted image. If destination already exists, the already converted image will be served. Unless the original is newer or smaller. If the method fails, it will serve original image, a 404, or whatever the 'fail' option is set to.
|
6 |
-
|
7 |
-
**WebPConvert::convertAndServe($source, $destination, $options)**
|
8 |
-
|
9 |
-
| Parameter | Type | Description |
|
10 |
-
| ---------------- | ------- | ------------------------------------------------------------------- |
|
11 |
-
| `$source` | String | Absolute path to source image (only forward slashes allowed) |
|
12 |
-
| `$destination` | String | Absolute path to converted image (only forward slashes allowed) |
|
13 |
-
| `$options` | Array | Array of options (see below) |
|
14 |
-
|
15 |
-
## The *$options* argument
|
16 |
-
The options argument is a named array. Besides the options described below, you can also use any options that the *convert* method takes (if a fresh convertion needs to be created, this method will call the *convert* method and hand over the options argument)
|
17 |
-
|
18 |
-
### *convert*
|
19 |
-
Conversion options, handed over to the convert method, in case a conversion needs to be made. The convert options are documented [here](https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/converting/options.md).
|
20 |
-
|
21 |
-
### *fail*
|
22 |
-
Indicate what to do, in case of normal conversion failure.
|
23 |
-
Default value: *"original"*
|
24 |
-
|
25 |
-
| Possible values | Meaning |
|
26 |
-
| ----------------- | ----------------------------------------------- |
|
27 |
-
| "serve-original" | Serve the original image. |
|
28 |
-
| "404" | Serve 404 status (not found) |
|
29 |
-
| "report-as-image" | Serve an image with text explaining the problem |
|
30 |
-
| "report" | Serve a textual report explaining the problem |
|
31 |
-
|
32 |
-
### *fail-when-original-unavailable*
|
33 |
-
Possible values: Same as above, except that "original" is not an option.
|
34 |
-
Default value: *"404"*
|
35 |
-
|
36 |
-
### *show-report*
|
37 |
-
Produce a report rather than serve an image.
|
38 |
-
Default value: *false*
|
39 |
-
|
40 |
-
### *reconvert*
|
41 |
-
Force a conversion, discarding existing converted image (if any).
|
42 |
-
Default value: *false*
|
43 |
-
|
44 |
-
### *serve-original*
|
45 |
-
Forces serving original image. This will skip conversion.
|
46 |
-
Default value: *false*
|
47 |
-
|
48 |
-
### *add-x-header-status*
|
49 |
-
When set to *true*, a *X-WebP-Convert-Status* header will be added describing how things went.
|
50 |
-
Default value: *true*
|
51 |
-
|
52 |
-
Depending on how things goes, the header will be set to one of the following:
|
53 |
-
- "Failed (missing source argument)"
|
54 |
-
- "Failed (source not found)""
|
55 |
-
- "Failed (missing destination argument)"
|
56 |
-
- "Reporting..."
|
57 |
-
- "Serving original image (was explicitly told to)"
|
58 |
-
- "Serving original image - because it is smaller than the converted!"
|
59 |
-
- "Serving freshly converted image (the original had changed)"
|
60 |
-
- "Serving existing converted image"
|
61 |
-
- "Converting image (handed over to WebPConvertAndServe)"
|
62 |
-
- "Serving freshly converted image"
|
63 |
-
- "Failed (could not convert image)"
|
64 |
-
|
65 |
-
### *add-vary-header*
|
66 |
-
Add a "Vary: Accept" header when an image is served. Experimental.
|
67 |
-
Default value: *true*
|
68 |
-
|
69 |
-
### *add-content-type-header*
|
70 |
-
Add a "Content-Type" header
|
71 |
-
Default value: *true*
|
72 |
-
If set, a *Content-Type* header will be added. It will be set to "image/webp" if a converted image is served, "image/jpeg" or "image/png", if the original is served or "image/gif", if an error message is served (as image). You can set it to false when debugging (to check if any errors are being outputted)
|
73 |
-
|
74 |
-
### *add-last-modified-header*
|
75 |
-
Add a "Last-Modified" header
|
76 |
-
Default value: *true*
|
77 |
-
If set, a *Last-Modified* header will be added. When a cached image is served, it will be set to the modified time of the converted file. When a fresh image is served, it is set to current time.
|
78 |
-
|
79 |
-
### *cache-control-header*
|
80 |
-
Specify a cache control header, which will be served when caching is appropriate.
|
81 |
-
Default value: "public, max-age=86400" (1 day)
|
82 |
-
Caching is "deemed appropriate", when destination is served, source is served, because it is lighter or a fresh conversion is made, due to there not being any converted image at the destination yet. Caching is not deemed appropriate when something fails, a report is requested, or the *reconvert* option have been set. Note: in version 1.3.2 and below, the *serve-original* option also prevented caching, but it no longer does. previous In those cases, standard headers will be used for preventing caching.
|
83 |
-
For your convenience, here is a little table:
|
84 |
-
|
85 |
-
| duration | max-age |
|
86 |
-
| -------- | ---------------- |
|
87 |
-
| 1 second | max-age=1 |
|
88 |
-
| 1 minute | max-age=60 |
|
89 |
-
| 1 hour | max-age=3600 |
|
90 |
-
| 1 day | max-age=86400 |
|
91 |
-
| 1 week | max-age=604800 |
|
92 |
-
| 1 month | max-age=2592000 |
|
93 |
-
| 1 year | max-age=31536000 |
|
94 |
-
|
95 |
-
To learn about the options for the Cache-Control header, go [here](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control)
|
96 |
-
|
97 |
-
### *error-reporting*
|
98 |
-
Set error reporting
|
99 |
-
Allowed values: *"auto"*, *"dont-mess"*, *true*, *false*
|
100 |
-
Default value: *"auto"*
|
101 |
-
|
102 |
-
If set to true, error reporting will be turned on, like this:
|
103 |
-
```
|
104 |
-
error_reporting(E_ALL);
|
105 |
-
ini_set('display_errors', 'On');
|
106 |
-
```
|
107 |
-
|
108 |
-
If set to false, error reporting will be turned off, like this:
|
109 |
-
```
|
110 |
-
error_reporting(0);
|
111 |
-
ini_set('display_errors', 'Off');
|
112 |
-
```
|
113 |
-
If set to "auto", errors will be turned off, unless the `show-report` option is set, in which case errors will be turned off.
|
114 |
-
If set to "dont-mess", error reporting will not be touched.
|
115 |
-
|
116 |
-
### *aboutToServeImageCallBack*
|
117 |
-
This callback is called right before response headers and image is served. This is a great chance to adding headers. You can stop the image and the headers from being served by returning *false*.
|
118 |
-
|
119 |
-
**Arguments:**
|
120 |
-
The first argument to the callback contains a string that tells what is about to be served. It can be 'fresh-conversion', 'destination' or 'source'.
|
121 |
-
|
122 |
-
The second argument tells you why that is served. It can be one of the following:
|
123 |
-
for 'source':
|
124 |
-
- "explicitly-told-to" (when the "serve-original" option is set)
|
125 |
-
- "source-lighter" (when original image is actually smaller than the converted)
|
126 |
-
|
127 |
-
for 'fresh-conversion':
|
128 |
-
- "explicitly-told-to" (when the "reconvert" option is set)
|
129 |
-
- "source-modified" (when source is newer than existing)
|
130 |
-
- "no-existing" (when there is no existing at the destination)
|
131 |
-
|
132 |
-
for 'destination':
|
133 |
-
- "no-reason-not-to" (it is lighter than source, its not older, and we were not told to do otherwise)
|
134 |
-
|
135 |
-
Example of callback:
|
136 |
-
```
|
137 |
-
function aboutToServeImageCallBack($servingWhat, $whyServingThis, $obj)
|
138 |
-
{
|
139 |
-
echo 'about to serve: ' . $servingWhat . '<br>';
|
140 |
-
echo 'Why? - because: ' . $whyServingThis;
|
141 |
-
return false; // Do not serve! (this also prevents any response headers from being added)
|
142 |
-
}
|
143 |
-
```
|
144 |
-
|
145 |
-
### *aboutToPerformFailActionCallback*
|
146 |
-
This callback is called right before doing the action specified in the `fail` option, or the `fail-when-original-unavailable` option. You can stop the fail action from being executod by returning *false*.
|
147 |
-
|
148 |
-
Documentation by example:
|
149 |
-
```
|
150 |
-
function aboutToPerformFailActionCallback($errorTitle, $errorDescription, $actionAboutToBeTaken, $serveConvertedObj)
|
151 |
-
{
|
152 |
-
echo '<h1>' . $errorTitle . '</h1>';
|
153 |
-
echo $errorDescription;
|
154 |
-
if (actionAboutToBeTaken == '404') {
|
155 |
-
// handle 404 differently than webp-convert would
|
156 |
-
$protocol = isset($_SERVER["SERVER_PROTOCOL"]) ? $_SERVER["SERVER_PROTOCOL"] : 'HTTP/1.0';
|
157 |
-
$serveConvertedObj->header($protocol . " 404 Not Found. We take this very seriously. Heads will roll.");
|
158 |
-
|
159 |
-
return false; // stop webp-convert from doing what it would do
|
160 |
-
}
|
161 |
-
|
162 |
-
}
|
163 |
-
```
|
164 |
-
|
165 |
-
### *require-for-conversion*
|
166 |
-
If set, makes the library 'require in' a file just before doing an actual conversion with `ConvertAndServe::convertAndServe()`. This is not needed for composer projects, as composer takes care of autoloading classes when needed.
|
167 |
-
Default value: *null*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vendor/rosell-dk/webp-convert/docs/v1.3/webp-on-demand/tweaks.md
DELETED
@@ -1,167 +0,0 @@
|
|
1 |
-
# Tweaks
|
2 |
-
|
3 |
-
## Store converted images in separate folder
|
4 |
-
|
5 |
-
In most cases, you probably want the cache of converted images to be stored in their own folder rather than have them mingled with the source files.
|
6 |
-
|
7 |
-
To have have the cache folder contain a file structure mirroring the structure of the original files, you can do this:
|
8 |
-
|
9 |
-
```php
|
10 |
-
$applicationRoot = $_SERVER["DOCUMENT_ROOT"]; // If your application is not in document root, you can change accordingly.
|
11 |
-
$imageRoot = $applicationRoot . '/webp-images'; // Change to where you want the webp images to be saved
|
12 |
-
$sourceRel = substr($source, strlen($applicationRoot));
|
13 |
-
$destination = $imageRoot . $sourceRel . '.webp';
|
14 |
-
```
|
15 |
-
|
16 |
-
If your images are stored outside document root (a rare case), you can simply use the complete absolute path:
|
17 |
-
```php
|
18 |
-
$destination = $imageRoot . $source . '.webp'; // pst: $source is an absolute path, and starts with '/'
|
19 |
-
```
|
20 |
-
This will ie store a converted image in */var/www/example.com/public_html/app/webp-images/var/www/example.com/images/logo.jpg.webp*
|
21 |
-
|
22 |
-
If your application can be configured to store outside document root, but rarely is, you can go for this structure:
|
23 |
-
|
24 |
-
```php
|
25 |
-
$docRoot = $_SERVER["DOCUMENT_ROOT"];
|
26 |
-
$imageRoot = $contentDirAbs . '/webp-images';
|
27 |
-
|
28 |
-
if (substr($source, 0, strlen($docRoot)) === $docRoot) {
|
29 |
-
// Source file is residing inside document root.
|
30 |
-
// We can store relative to that.
|
31 |
-
$sourceRel = substr($source, strlen($docRoot));
|
32 |
-
$destination = $imageRoot . '/doc-root' . $sourceRel . '.webp';
|
33 |
-
} else {
|
34 |
-
// Source file is residing outside document root.
|
35 |
-
// we must add complete path to structure
|
36 |
-
$destination = $imageRoot . '/abs' . $source . '.webp';
|
37 |
-
}
|
38 |
-
```
|
39 |
-
|
40 |
-
If you do not know the application root beforehand, and thus do not know the appropriate root for the converted images, see next tweak.
|
41 |
-
|
42 |
-
|
43 |
-
## Get the application root automatically
|
44 |
-
When you want destination files to be put in their own folder, you need to know the root of the application (the folder in which the .htaccess rules resides). In most applications, you know the root. In many cases, it is simply the document root. However, if you are writing an extension, plugin or module to a framework that can be installed in a subfolder, you may have trouble finding it. Many applications have a *index.php* in the root, which can get it with `__DIR__`. However, you do not want to run an entire bootstrap each time you serve an image. Obviously, to get around this, you can place *webp-on-demand.php* in the webroot. However, some frameworks, such as Wordpress, will not allow a plugin to put a file in the root. Now, how could we determine the application root from a file inside some subdir? Here are three suggestions:
|
45 |
-
|
46 |
-
1. You could traverse parent folders until you find a file you expect to be in application root (ie a .htaccess containing the string "webp-on-demand.php"). This should work.
|
47 |
-
2. If the rules in the *.htaccess* file are generated by your application, you probably have access to the path at generation time. You can then simply put the path in the *.htaccess*, as an extra parameter to the script (or better: the relative path from document root to the application).
|
48 |
-
3. You can use the following hack:
|
49 |
-
|
50 |
-
### The hack
|
51 |
-
The idea is to grab the URL path of the image in the *.htaccess* and pass it to the script. Assuming that the URL paths always matches the file paths, we can get the application root by subtracting that relative path to source from the absolute path to source.
|
52 |
-
|
53 |
-
In *.htaccess*, we grab the url-path by appending "&url-path=$1.$2" to the rewrite rule:
|
54 |
-
```
|
55 |
-
RewriteRule ^(.*)\.(jpe?g|png)$ webp-on-demand.php?source=%{SCRIPT_FILENAME}&url-path=$1.$2 [NC,L]
|
56 |
-
```
|
57 |
-
|
58 |
-
In the script, we can then calculate the application root like this:
|
59 |
-
|
60 |
-
```php
|
61 |
-
$applicationRoot = substr($_GET['source'], 0, -strlen($_GET['url-path']));
|
62 |
-
```
|
63 |
-
|
64 |
-
## CDN
|
65 |
-
To work properly with a CDN, a "Vary Accept" header should be added when serving images. This is a declaration that the response varies with the *Accept* header (recall that we inspect *Accept* header in the .htaccess to determine if the browsers supports webp images). If this header is missing, the CDN will see no reason to cache separate images depending on the Accept header.
|
66 |
-
|
67 |
-
Add this snippet to the *.htaccess* to make webp-on-demand work with CDN's:
|
68 |
-
|
69 |
-
```
|
70 |
-
<IfModule mod_headers.c>
|
71 |
-
SetEnvIf Request_URI "\.(jpe?g|png)" ADDVARY
|
72 |
-
|
73 |
-
# Declare that the response varies depending on the accept header.
|
74 |
-
# The purpose is to make CDN cache both original images and converted images.
|
75 |
-
Header append "Vary" "Accept" env=ADDVARY
|
76 |
-
</IfModule>
|
77 |
-
```
|
78 |
-
|
79 |
-
***Note:*** When configuring the CDN, you must make sure to set it up to forward the the "Accept" header to your origin server.
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
## Make .htaccess route directly to existing images
|
84 |
-
|
85 |
-
There may be a performance benefit of using the *.htaccess* file to route to already converted images, instead of letting the PHP script serve it. Note however:
|
86 |
-
- If you do the routing in .htaccess, the solution will not be able to discard converted images when original images are updated.
|
87 |
-
- Performance benefit may be insignificant (*WebPConvertAndServe* class is not autoloaded when serving existing images)
|
88 |
-
|
89 |
-
Add the following to the *.htaccess* to make it route to existing converted images. Place it above the # Redirect images to webp-on-demand.php" comment. Take care of replacing [[your-base-path]] with the directory your *.htaccess* lives in (relative to document root, and [[your-destination-root]] with the directory the converted images resides.
|
90 |
-
```
|
91 |
-
# Redirect to existing converted image (under appropriate circumstances)
|
92 |
-
RewriteCond %{HTTP_ACCEPT} image/webp
|
93 |
-
RewriteCond %{DOCUMENT_ROOT}/[[your-base-path]]/[[your-destination-root]]/$1.$2.webp -f
|
94 |
-
RewriteRule ^\/?(.*)\.(jpe?g|png)$ /[[your-base-path]]/[[your-destination-root]]/$1.$2.webp [NC,T=image/webp,L]
|
95 |
-
```
|
96 |
-
*edit:* Removed the QSD flag from the RewriteRule because it is not supported in Apache < 2.4 (and it [triggers error](https://github.com/rosell-dk/webp-express/issues/155))
|
97 |
-
|
98 |
-
### Redirect with CDN support
|
99 |
-
If you are using a CDN, and want to redirect to existing images with the .htaccess, it is a good idea to add a "Vary Accept" header. This instructs the CDN that the response varies with the *Accept* header (we do not need to do that when routing to webp-on-demand.php, because the script takes care of adding this header, when appropriate.)
|
100 |
-
|
101 |
-
You can achieve redirect with CDN support with the following rules:
|
102 |
-
```
|
103 |
-
<IfModule mod_rewrite.c>
|
104 |
-
|
105 |
-
RewriteEngine On
|
106 |
-
|
107 |
-
# Redirect to existing converted image (under appropriate circumstances)
|
108 |
-
RewriteCond %{HTTP_ACCEPT} image/webp
|
109 |
-
RewriteCond %{DOCUMENT_ROOT}/[[your-base-path]]/[[your-destination-root]]/$1.$2.webp -f
|
110 |
-
RewriteRule ^\/?(.*)\.(jpe?g|png)$ /[[your-base-path]]/[[your-destination-root]]/$1.$2.webp [NC,T=image/webp,QSD,E=WEBPACCEPT:1,L]
|
111 |
-
|
112 |
-
# Redirect images to webp-on-demand.php (if browser supports webp)
|
113 |
-
RewriteCond %{HTTP_ACCEPT} image/webp
|
114 |
-
RewriteRule ^(.*)\.(jpe?g|png)$ webp-on-demand.php?source=%{SCRIPT_FILENAME}&url-path=$1.$2 [NC,L]
|
115 |
-
|
116 |
-
</IfModule>
|
117 |
-
|
118 |
-
<IfModule mod_headers.c>
|
119 |
-
# Apache appends "REDIRECT_" in front of the environment variables, but LiteSpeed does not.
|
120 |
-
# These next line is for Apache, in order to set environment variables without "REDIRECT_"
|
121 |
-
SetEnvIf REDIRECT_WEBPACCEPT 1 WEBPACCEPT=1
|
122 |
-
|
123 |
-
# Make CDN caching possible.
|
124 |
-
# The effect is that the CDN will cache both the webp image and the jpeg/png image and return the proper
|
125 |
-
# image to the proper clients (for this to work, make sure to set up CDN to forward the "Accept" header)
|
126 |
-
Header append Vary Accept env=WEBPACCEPT
|
127 |
-
</IfModule>
|
128 |
-
|
129 |
-
AddType image/webp .webp
|
130 |
-
```
|
131 |
-
|
132 |
-
## Forward the querystring
|
133 |
-
By forwarding the query string, you can allow control directly from the URL. You could for example make it possible to add "?debug" to an image URL, and thereby getting a conversion report. Or make "?reconvert" force reconversion.
|
134 |
-
|
135 |
-
In order to forward the query string, you need to add this condition before the RewriteRule that redirects to *webp-on-demand.php*:
|
136 |
-
```
|
137 |
-
RewriteCond %{QUERY_STRING} (.*)
|
138 |
-
```
|
139 |
-
That condition will always be met. The side effect is that it stores the match (the complete querystring). That match will be available as %1 in the RewriteRule. So, in the RewriteRule, we will have to add "&%1" after the last argument. Here is a complete solution:
|
140 |
-
```
|
141 |
-
<IfModule mod_rewrite.c>
|
142 |
-
RewriteEngine On
|
143 |
-
|
144 |
-
# Redirect images to webp-on-demand.php (if browser supports webp)
|
145 |
-
RewriteCond %{HTTP_ACCEPT} image/webp
|
146 |
-
RewriteCond %{QUERY_STRING} (.*)
|
147 |
-
RewriteRule ^(.*)\.(jpe?g|png)$ webp-on-demand.php?source=%{SCRIPT_FILENAME}&%1 [NC,L]
|
148 |
-
</IfModule>
|
149 |
-
|
150 |
-
AddType image/webp .webp
|
151 |
-
```
|
152 |
-
|
153 |
-
Of course, in order to *do* something with that querystring, you must use them in your *webp-on-demand.php* script. You could for example use them directly in the options array sent to the *convertAndServe()* method. To achieve the mentioned "debug" and "reconvert" features, do this:
|
154 |
-
```php
|
155 |
-
$options = [
|
156 |
-
'show-report' => isset($_GET['debug']),
|
157 |
-
'reconvert' => isset($_GET['reconvert']),
|
158 |
-
'serve-original' => isset($_GET['original']),
|
159 |
-
];
|
160 |
-
```
|
161 |
-
|
162 |
-
*EDIT:*
|
163 |
-
I have just discovered a simpler way to achieve the querystring forward: The [QSA flag](https://httpd.apache.org/docs/trunk/rewrite/flags.html).
|
164 |
-
So, simply set the QSA flag in the RewriteRule, and nothing more:
|
165 |
-
```
|
166 |
-
RewriteRule ^(.*)\.(jpe?g|png)$ webp-on-demand.php?source=%{SCRIPT_FILENAME} [NC,QSA,L]
|
167 |
-
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vendor/rosell-dk/webp-convert/docs/v1.3/webp-on-demand/webp-on-demand.md
DELETED
@@ -1,133 +0,0 @@
|
|
1 |
-
# WebP on demand
|
2 |
-
|
3 |
-
This is a solution for automatically serving WebP images instead of jpeg/pngs [for browsers that supports WebP](https://caniuse.com/#feat=webp) (At the time of writing, 78% of all mobile users and 72% of all desktop users uses browsers supporting webp)
|
4 |
-
|
5 |
-
Once set up, it will automatically convert images, no matter how they are referenced. It for example also works on images referenced in CSS. As the solution does not require any change in the HTML, it can easily be integrated into any website / framework
|
6 |
-
|
7 |
-
## Overview
|
8 |
-
|
9 |
-
A setup consists of a PHP script that serves converted images and some *redirect rules* that redirects JPG/PNG images to the script.
|
10 |
-
|
11 |
-
|
12 |
-
## Requirements
|
13 |
-
|
14 |
-
* *Apache* or *LiteSpeed* web server. Can be made to work with *NGINX* as well. Documentation is on the roadmap.
|
15 |
-
* *mod_rewrite* module for Apache
|
16 |
-
* PHP >= 5.6 (we are only testing down to 5.6. It should however work in 5.5 as well)
|
17 |
-
* That one of the *webp-convert* converters are working (these have different requirements)
|
18 |
-
|
19 |
-
## Installation
|
20 |
-
|
21 |
-
Here we assume you are using Composer. [Not using composer? - Follow me!](https://github.com/rosell-dk/webp-convert/blob/master/docs/v1.3/webp-on-demand/without-composer.md)
|
22 |
-
|
23 |
-
### 1. Require the webp-convert library with composer
|
24 |
-
```
|
25 |
-
composer require rosell-dk/webp-convert
|
26 |
-
```
|
27 |
-
|
28 |
-
|
29 |
-
### 2. Create the script
|
30 |
-
|
31 |
-
Create a file *webp-on-demand.php*, and place it in webroot, or where-ever you like in you web-application.
|
32 |
-
|
33 |
-
Here is a minimal example to get started with:
|
34 |
-
|
35 |
-
```php
|
36 |
-
<?php
|
37 |
-
require 'vendor/autoload.php'; // Make sure to point this correctly
|
38 |
-
|
39 |
-
use WebPConvert\WebPConvert;
|
40 |
-
|
41 |
-
$source = $_GET['source']; // Absolute file path to source file. Comes from the .htaccess
|
42 |
-
$destination = $source . '.webp'; // Store the converted images besides the original images (other options are available!)
|
43 |
-
|
44 |
-
$options = [
|
45 |
-
|
46 |
-
// UNCOMMENT NEXT LINE, WHEN YOU ARE UP AND RUNNING!
|
47 |
-
'show-report' => true // Show a conversion report instead of serving the converted image.
|
48 |
-
|
49 |
-
// More options available!
|
50 |
-
];
|
51 |
-
WebPConvert::convertAndServe($source, $destination, $options);
|
52 |
-
```
|
53 |
-
|
54 |
-
### 3. Add redirect rules
|
55 |
-
Place the following rewrite rules in a *.htaccess* file in the directory where you want the solution to take effect:
|
56 |
-
|
57 |
-
```
|
58 |
-
<IfModule mod_rewrite.c>
|
59 |
-
RewriteEngine On
|
60 |
-
|
61 |
-
# Redirect images to webp-on-demand.php (if browser supports webp)
|
62 |
-
RewriteCond %{HTTP_ACCEPT} image/webp
|
63 |
-
RewriteCond %{REQUEST_FILENAME} -f
|
64 |
-
RewriteRule ^(.*)\.(jpe?g|png)$ webp-on-demand.php?source=%{SCRIPT_FILENAME} [NC,L]
|
65 |
-
</IfModule>
|
66 |
-
|
67 |
-
AddType image/webp .webp
|
68 |
-
```
|
69 |
-
If you have placed *webp-on-demand.php* in a subfolder, you will need to change the rewrite rule accordingly.
|
70 |
-
|
71 |
-
The `RewriteCond %{REQUEST_FILENAME} -f` is not strictly necessary, but there to be sure that we got an existing file, and it could perhaps also prevent some undiscovered way of misuse.
|
72 |
-
|
73 |
-
### 4. Validate that it works
|
74 |
-
|
75 |
-
Browse to a JPEG image. Instead of an image, you should see a conversion report. Hopefully, you get a success. Otherwise, you need to hook up to a cloud converter or try to meet the requirements for cwebp, gd or imagick.
|
76 |
-
|
77 |
-
Once you get a successful conversion, you can uncomment the "show-report" option in the script.
|
78 |
-
|
79 |
-
It should work now, but to be absolute sure:
|
80 |
-
|
81 |
-
- Visit a page on your site with an image on it, using *Google Chrome*.
|
82 |
-
- Right-click the page and choose "Inspect"
|
83 |
-
- Click the "Network" tab
|
84 |
-
- Reload the page
|
85 |
-
- Find a jpeg or png image in the list. In the "type" column, it should say "webp". There should also be a *X-WebP-Convert-Status* header on the image that provides some insights on how things went.
|
86 |
-
|
87 |
-
|
88 |
-
### 5. Try this improvement and see if it works
|
89 |
-
|
90 |
-
It seems that it is not necessary to pass the filename in the query string.
|
91 |
-
|
92 |
-
Try replacing `$source = $_GET['source'];` in the script with the following:
|
93 |
-
|
94 |
-
```php
|
95 |
-
$docRoot = rtrim($_SERVER["DOCUMENT_ROOT"], '/');
|
96 |
-
$requestUriNoQS = explode('?', $_SERVER['REQUEST_URI'])[0];
|
97 |
-
$source = $docRoot . urldecode($requestUriNoQS);
|
98 |
-
```
|
99 |
-
|
100 |
-
And you can then remove `?source=%{SCRIPT_FILENAME}` from the `.htaccess` file.
|
101 |
-
|
102 |
-
There are some benefits of not passing in query string:
|
103 |
-
1. Passing a path in the query string may be blocked by a firewall, as it looks suspicious.
|
104 |
-
2. The script called to convert arbitrary files
|
105 |
-
3. One person experienced problems with spaces in filenames passed in the query string. See [this issue](https://github.com/rosell-dk/webp-convert/issues/95)
|
106 |
-
|
107 |
-
|
108 |
-
### 6. Customizing and tweaking
|
109 |
-
|
110 |
-
Basic customizing is done by setting options in the `$options` array. Check out the [docs on convert()](https://github.com/rosell-dk/webp-convert/blob/master/docs/v1.3/converting/convert.md) and the [docs on convertAndServe()](https://github.com/rosell-dk/webp-convert/blob/master/docs/v1.3/serving/convert-and-serve.md)
|
111 |
-
|
112 |
-
Other tweaking is described in *docs/webp-on-demand/tweaks.md*:
|
113 |
-
- [Store converted images in separate folder](https://github.com/rosell-dk/webp-convert/blob/master/docs/v1.3/webp-on-demand/tweaks.md#store-converted-images-in-separate-folder)
|
114 |
-
- [CDN](https://github.com/rosell-dk/webp-convert/blob/master/docs/v1.3/webp-on-demand/tweaks.md#cdn)
|
115 |
-
- [Make .htaccess route directly to existing images](https://github.com/rosell-dk/webp-convert/blob/master/docs/v1.3/webp-on-demand/tweaks.md#make-htaccess-route-directly-to-existing-images)
|
116 |
-
- [Forward the query string](https://github.com/rosell-dk/webp-convert/blob/master/docs/v1.3/webp-on-demand/tweaks.md#forward-the-querystring)
|
117 |
-
|
118 |
-
|
119 |
-
## Troubleshooting
|
120 |
-
|
121 |
-
### The redirect rule doesn't seem to be working
|
122 |
-
If images are neither routed to the converter or a 404, it means that the redirect rule isn't taking effect. Common reasons for this includes:
|
123 |
-
|
124 |
-
- Perhaps there are other rules in your *.htaccess* that interfere with the rules?
|
125 |
-
- Perhaps your site is on *Apache*, but it has been configured to use *Nginx* to serve image files. To find out which server that is handling the images, browse to an image and eximine the "Server" response header. In case *NGINX* are serving images, see if you can reconfigure your server setup. Alternatively, you can create *NGINX* rewrite rules. There are some [here](https://github.com/S1SYPHOS/kirby-webp#nginx) and [there](https://github.com/uhop/grunt-tight-sprite/wiki/Recipe:-serve-WebP-with-nginx-conditionally).
|
126 |
-
- Perhaps the server isn't configured to allow *.htaccess* files? Try inserting rubbish in the top of the *.htaccess* file and refresh. You should now see an *Internal Server Error* error page. If you don't, your *.htaccess* file is ignored. Probably you will need to set *AllowOverride All* in your Virtual Host. [Look here for more help](
|
127 |
-
https://docs.bolt.cm/3.4/howto/making-sure-htaccess-works#test-if-htaccess-is-working)
|
128 |
-
- Perhaps the Apache *mod_rewrite* extension isn't enabled? Try removing both `<IfModule mod_rewrite.c>` and `</IfModule>` lines: if you get an *Internal Server Error* error page after this change, it's probably that it's indeed not enabled.
|
129 |
-
|
130 |
-
|
131 |
-
## Related
|
132 |
-
* https://www.maxcdn.com/blog/how-to-reduce-image-size-with-webp-automagically/
|
133 |
-
* https://www.digitalocean.com/community/tutorials/how-to-create-and-serve-webp-images-to-speed-up-your-website
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vendor/rosell-dk/webp-convert/docs/v1.3/webp-on-demand/without-composer.md
DELETED
@@ -1,45 +0,0 @@
|
|
1 |
-
# WebP On Demand without composer
|
2 |
-
|
3 |
-
For your convenience, the library has been cooked down to two files: *webp-on-demand-1.inc* and *webp-on-demand-2.inc*. The second one is loaded when the first one decides it needs to do a conversion (and not simply serve existing image).
|
4 |
-
|
5 |
-
## Installing
|
6 |
-
|
7 |
-
### 1. Copy the latest build files into your website
|
8 |
-
Copy *webp-on-demand-1.inc* and *webp-on-demand-2.inc* from the *build* folder into your website (in 2.0, they are located in "src-build"). They can be located wherever you like.
|
9 |
-
|
10 |
-
### 2. Create a *webp-on-demand.php*
|
11 |
-
|
12 |
-
Create a file *webp-on-demand.php*, and place it in webroot, or where-ever you like in you web-application.
|
13 |
-
|
14 |
-
Here is a minimal example to get started with. Note that this example only works in version 1.x. In 2.0, the `require-for-conversion` option has been removed, so the [procedure is different](https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/webp-on-demand/without-composer.md).
|
15 |
-
|
16 |
-
```php
|
17 |
-
<?php
|
18 |
-
// To start with, lets display any errors.
|
19 |
-
// You can later comment these out
|
20 |
-
error_reporting(E_ALL);
|
21 |
-
ini_set("display_errors", 1);
|
22 |
-
|
23 |
-
require 'webp-on-demand-1.inc';
|
24 |
-
|
25 |
-
use WebPConvert\WebPConvert;
|
26 |
-
|
27 |
-
$source = $_GET['source']; // Absolute file path to source file. Comes from the .htaccess
|
28 |
-
$destination = $source . '.webp'; // Store the converted images besides the original images (other options are available!)
|
29 |
-
|
30 |
-
$options = [
|
31 |
-
|
32 |
-
// Tell where to find the webp-convert-and-serve library, which will
|
33 |
-
// be dynamically loaded, if need be.
|
34 |
-
'require-for-conversion' => 'webp-on-demand-2.inc',
|
35 |
-
|
36 |
-
// UNCOMMENT NEXT LINE, WHEN YOU ARE UP AND RUNNING!
|
37 |
-
'show-report' => true // Show a conversion report instead of serving the converted image.
|
38 |
-
|
39 |
-
// More options available!
|
40 |
-
];
|
41 |
-
WebPConvert::convertAndServe($source, $destination, $options);
|
42 |
-
```
|
43 |
-
|
44 |
-
### 3. Continue the main install instructions from step 3
|
45 |
-
[Click here to continue...](https://github.com/rosell-dk/webp-on-demand#3-add-redirect-rules)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vendor/rosell-dk/webp-convert/docs/v2.0/converting/architecture-q50-w600.jpg
DELETED
Binary file
|
vendor/rosell-dk/webp-convert/docs/v2.0/converting/converters/stack.md
DELETED
@@ -1,248 +0,0 @@
|
|
1 |
-
# Stack converter
|
2 |
-
|
3 |
-
The stack converter is a mechanism for trying all available converters until success. Well, the default is to try all converters, but this can be configured.
|
4 |
-
|
5 |
-
When calling `WebPConvert::convert($source, $destination, $options);`, you are actually invoking the stack converter.
|
6 |
-
|
7 |
-
## Passing options down to the individual converters
|
8 |
-
|
9 |
-
Any option that you pass to the Stack converter will be passed on to the individual converters. For example, setting options to the following will set the metadata option on all converters:
|
10 |
-
|
11 |
-
```php
|
12 |
-
$options = [
|
13 |
-
'metadata' => 'all',
|
14 |
-
];
|
15 |
-
```
|
16 |
-
|
17 |
-
If you need the option to be different for a single converter there are several ways to do it:
|
18 |
-
|
19 |
-
#### 1. Prefixing
|
20 |
-
|
21 |
-
Options prefixed with a converter id are only effective for that converter, and overrides the non-prefixed option.
|
22 |
-
|
23 |
-
Ie, the following will set "metadata" to "all" for all converters, except *cwebp*, where "metadata" is set to "exif"
|
24 |
-
|
25 |
-
```php
|
26 |
-
$options = [
|
27 |
-
'metadata' => 'all',
|
28 |
-
'cwebp-metadata' => 'exif'
|
29 |
-
];
|
30 |
-
```
|
31 |
-
|
32 |
-
Prefixing is by the way a general feature in the way options are handled and thus not confined to the stack converter. (though it admittedly only finds its use in the context of a stack converter).
|
33 |
-
|
34 |
-
|
35 |
-
#### 2. Using the `converter-options` option
|
36 |
-
The *converter-options* option is convenient for setting a whole bunch of converter-specific options in one go.
|
37 |
-
|
38 |
-
Example:
|
39 |
-
```php
|
40 |
-
$options = [
|
41 |
-
'converter-options' => [
|
42 |
-
'wpc' => [
|
43 |
-
'crypt-api-key-in-transfer' => true
|
44 |
-
'api-key' => 'my dog is white',
|
45 |
-
'api-url' => 'https://example.com/wpc.php',
|
46 |
-
'api-version' => 1,
|
47 |
-
],
|
48 |
-
],
|
49 |
-
]
|
50 |
-
```
|
51 |
-
|
52 |
-
#### 3. As part of the `converters` option
|
53 |
-
This option is explained further down this document.
|
54 |
-
|
55 |
-
|
56 |
-
## Modifying the stack
|
57 |
-
|
58 |
-
The default stack consists of the following converters:
|
59 |
-
- cwebp
|
60 |
-
- vips
|
61 |
-
- imagick
|
62 |
-
- gmagick
|
63 |
-
- imagemagick
|
64 |
-
- graphicsmagick
|
65 |
-
- wpc
|
66 |
-
- ewww
|
67 |
-
- gd
|
68 |
-
|
69 |
-
The order has carefully been chosen based on the capabilities of the converters. It is a rank, if you will.
|
70 |
-
|
71 |
-
Now, say that on your system, you only have *gd* working. With the default stack, this means that eight converters will be tested for operationality before getting to *gd* – each time a conversion is made. You might be tempted to optimizing the flow by putting *gd* on the top. *I would generally advise against this* for the following reasons:
|
72 |
-
|
73 |
-
1. It might be that one of the other (and better) converters starts working without you noticing. You will then miss out.
|
74 |
-
2. All converters have all been designed to exit very quickly when they are not operational. It only takes a few milliseconds for the library to detect that a converter is not operational - literally. For example, if no api key is provided for ewww, it will exit immediately.
|
75 |
-
|
76 |
-
However, there are valid reasons to modify the stack. For example, you may prefer *vips* over *cwebp*, or you may wish to remove a converter completely due to problems with that converter on your platform.
|
77 |
-
|
78 |
-
### Changing the order of the converters
|
79 |
-
To change the order, you can use the `preferred-converters` option. With this option you move selected converters to the top of the stack.
|
80 |
-
|
81 |
-
So, if you want the stack to start with *vips* and then *ewww*, but keep the rest of the order, you can set the following:
|
82 |
-
|
83 |
-
```php
|
84 |
-
$options[
|
85 |
-
'preferred-converters' => ['vips', 'ewww'];
|
86 |
-
];
|
87 |
-
```
|
88 |
-
|
89 |
-
### Removing converters from the stack
|
90 |
-
To remove converters, you can use the `skip` option and prefixing. For example, to remove *cwebp* and *gd*:
|
91 |
-
|
92 |
-
```php
|
93 |
-
$options = [
|
94 |
-
'ewww-skip' => true,
|
95 |
-
'cwebp-skip' => true,
|
96 |
-
];
|
97 |
-
```
|
98 |
-
|
99 |
-
### Adding converters to the stack
|
100 |
-
If you are using a custom converter, you can add it to the stack like this:
|
101 |
-
|
102 |
-
```php
|
103 |
-
$options = [
|
104 |
-
'extra-converters' => [
|
105 |
-
'\\MyNameSpace\\WonderConverter'
|
106 |
-
],
|
107 |
-
];
|
108 |
-
```
|
109 |
-
|
110 |
-
It will be added to the bottom of the stack. To place it differently, use the `preferred-converters` option and set it to ie `'preferred-converters' => ['vips','\\MyNameSpace\\WonderConverter']`
|
111 |
-
|
112 |
-
|
113 |
-
Here is an example which adds an extra ewww converter. This way you can have a backup api-key in case the quota of the first has been exceeded.
|
114 |
-
|
115 |
-
```
|
116 |
-
$options = [
|
117 |
-
'extra-converters' => [
|
118 |
-
[
|
119 |
-
'converter' => 'ewww',
|
120 |
-
'options' => [
|
121 |
-
'api-key' => 'provide-backup-key-here',
|
122 |
-
]
|
123 |
-
]
|
124 |
-
]
|
125 |
-
];
|
126 |
-
```
|
127 |
-
Note however that you will not be able to reorder that new ewww converter using `preferred-converters`, as there are now two converters with id=ewww, and that option has not been designed for that. Instead, you can add a sub-stack of ewww converters - see the "Stacking" section below.
|
128 |
-
|
129 |
-
|
130 |
-
### Setting the converter array explicitly
|
131 |
-
Using the `converters` option, you can set the converter array explicitly. What differentiates this from the `preferred-converters` option (besides that it completely redefines the converter ordering) is that it allows you to set both the converters *and* options for each converter in one go and that it allows a complex structure - such as a stack within a stack. Also, this structure can simplify things in some cases, such as when the options is generated by a GUI, as it is in WebP Express.
|
132 |
-
|
133 |
-
The array specifies the converters to try and their order. Each item can be:
|
134 |
-
|
135 |
-
- An id (ie "cwebp")
|
136 |
-
- A fully qualified class name (in case you have programmed your own custom converter)
|
137 |
-
- An array with two keys: "converter" and "options".
|
138 |
-
|
139 |
-
Example:
|
140 |
-
|
141 |
-
```php
|
142 |
-
$options = [
|
143 |
-
'quality' => 71,
|
144 |
-
'converters' => [
|
145 |
-
'cwebp',
|
146 |
-
[
|
147 |
-
'converter' => 'vips',
|
148 |
-
'options' => [
|
149 |
-
'quality' => 72
|
150 |
-
]
|
151 |
-
],
|
152 |
-
[
|
153 |
-
'converter' => 'ewww',
|
154 |
-
'options' => [
|
155 |
-
'quality' => 73
|
156 |
-
]
|
157 |
-
],
|
158 |
-
'wpc',
|
159 |
-
'imagemagick',
|
160 |
-
'\\MyNameSpace\\WonderConverter'
|
161 |
-
],
|
162 |
-
];
|
163 |
-
```
|
164 |
-
|
165 |
-
### Stacking
|
166 |
-
Stack converters behave just like regular converters. They ARE in fact "regular", as they extend the same base class as all converters. This means that you can have a stack within a stack. You can for example utilize this for supplying a backup api key for the ewww converter. Like this:
|
167 |
-
|
168 |
-
```php
|
169 |
-
$options = [
|
170 |
-
'ewww-skip' => true, // skip the default ewww converter (we use stack of ewww converters instead)
|
171 |
-
'extra-converters' => [
|
172 |
-
[
|
173 |
-
// stack of ewww converters
|
174 |
-
'converter' => 'stack',
|
175 |
-
'options' => [
|
176 |
-
'ewww-skip' => false, // do not skip ewww from here on
|
177 |
-
'converters' => [
|
178 |
-
[
|
179 |
-
'converter' => 'ewww',
|
180 |
-
'options' => [
|
181 |
-
'api-key' => 'provide-preferred-key-here',
|
182 |
-
]
|
183 |
-
],
|
184 |
-
[
|
185 |
-
'converter' => 'ewww',
|
186 |
-
'options' => [
|
187 |
-
'api-key' => 'provide-backup-key-here',
|
188 |
-
]
|
189 |
-
]
|
190 |
-
],
|
191 |
-
]
|
192 |
-
]
|
193 |
-
],
|
194 |
-
'preferred-converters' => ['cwebp', 'vips', 'stack'], // set our stack of ewww converters third in queue
|
195 |
-
];
|
196 |
-
```
|
197 |
-
Note that we set `ewww-skip` in order to disable the *ewww* converter which is part of the defaults. As options are inherited, we have to reset this option again. These steps are not necessary when using the `converters` option.
|
198 |
-
|
199 |
-
Also note that the options for modifying the converters (`converters`, `extra-converters`, `converter-options`) does not get passed down.
|
200 |
-
|
201 |
-
Also note that if you want to add two stacks with `extra-converters`, the `preferred-converters` option will not work, as there are two converters called "stack". One workaround is to add those two stacks to their own stack, so you have three levels. Or you can of course simply use the `converters` option to get complete control.
|
202 |
-
|
203 |
-
|
204 |
-
### Shuffling
|
205 |
-
|
206 |
-
The stack can be configured to shuffling, meaning that the the order will be random. This can for example be used to balance load between several wpc instances in a sub stack.
|
207 |
-
|
208 |
-
Shuffling is enabled with the `shuffle` option.
|
209 |
-
|
210 |
-
Here is an example of balancing load between several *wpc* instances:
|
211 |
-
|
212 |
-
```php
|
213 |
-
$options = [
|
214 |
-
'wpc-skip' => true, // skip the default wpc converter (we use stack of wpc converters instead)
|
215 |
-
'extra-converters' => [
|
216 |
-
[
|
217 |
-
// stack of wpc converters
|
218 |
-
'converter' => 'stack',
|
219 |
-
'options' => [
|
220 |
-
'wpc-skip' => false, // do not skip wpc from here on
|
221 |
-
'shuffle' => true,
|
222 |
-
|
223 |
-
'converters' => [
|
224 |
-
[
|
225 |
-
'converter' => 'wpc',
|
226 |
-
'options' => [
|
227 |
-
'api-key' => 'my-dog',
|
228 |
-
'api-url' => 'my-wpc.com/wpc.php',
|
229 |
-
'api-version' => 1,
|
230 |
-
'crypt-api-key-in-transfer' => true,
|
231 |
-
]
|
232 |
-
],
|
233 |
-
[
|
234 |
-
'converter' => 'wpc',
|
235 |
-
'options' => [
|
236 |
-
'api-key' => 'my-other-dog',
|
237 |
-
'api-url' => 'my-other-wpc.com/wpc.php',
|
238 |
-
'api-version' => 1,
|
239 |
-
'crypt-api-key-in-transfer' => true,
|
240 |
-
]
|
241 |
-
]
|
242 |
-
],
|
243 |
-
]
|
244 |
-
]
|
245 |
-
],
|
246 |
-
'preferred-converters' => ['cwebp', 'vips', 'stack'], // set our stack of wpc converters third in queue
|
247 |
-
];
|
248 |
-
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vendor/rosell-dk/webp-convert/docs/v2.0/converting/dice.png
DELETED
Binary file
|
vendor/rosell-dk/webp-convert/docs/v2.0/converting/introduction-for-converting.md
DELETED
@@ -1,251 +0,0 @@
|
|
1 |
-
# Introduction to converting with WebPConvert
|
2 |
-
|
3 |
-
The library is able to convert images to webp using a variety of methods (*gd*, *imagick*, *vips* etc.), which we call "converters". A converter is called like this:
|
4 |
-
|
5 |
-
```php
|
6 |
-
use WebPConvert\Convert\Converters\Gd;
|
7 |
-
|
8 |
-
Gd::convert($source, $destination, $options=[], $logger=null);
|
9 |
-
```
|
10 |
-
|
11 |
-
All converters comes with requirements. For example, the *Gd* converter requires that Gd is installed and compiled with webp support. The cloud converters requires an api key. In case the conversion fails, an exception is thrown.
|
12 |
-
|
13 |
-
## Insights to the process
|
14 |
-
If *$logger* is supplied, the converter will log the details of how the conversion process went to that logger. You can for example use the supplied *EchoLogger* to print directly to screen or the *BufferLogger* to collect the log entries. Here is a simple example which prints the process to screen:
|
15 |
-
|
16 |
-
```php
|
17 |
-
use WebPConvert\Convert\Converters\Gd;
|
18 |
-
use WebPConvert\Loggers\EchoLogger;
|
19 |
-
|
20 |
-
Gd::convert($source, $destination, $options=[], new EchoLogger());
|
21 |
-
```
|
22 |
-
|
23 |
-
It will output something like this:
|
24 |
-
|
25 |
-
```text
|
26 |
-
GD Version: 2.2.5
|
27 |
-
image is true color
|
28 |
-
Quality set to same as source: 61
|
29 |
-
|
30 |
-
Converted image in 20 ms, reducing file size with 34% (went from 12 kb to 8 kb)
|
31 |
-
```
|
32 |
-
|
33 |
-
## The stack converter
|
34 |
-
When your software is going to be installed on a variety of systems which you do not control, you can try the converters one at the time until success. The converters has been designed to exit quickly when system requirements are not met. To make this task easy, a *Stack* converter has been created.
|
35 |
-
|
36 |
-
The stack converter has two special options:
|
37 |
-
|
38 |
-
| option | description |
|
39 |
-
| ------------------------- | ----------- |
|
40 |
-
| converters (array) | Converters to try (ids or class names, in case you have your own custom converter) |
|
41 |
-
| converter-options (array) | Extra options for specific converters. |
|
42 |
-
|
43 |
-
Alternatively to the converter-options array, you can simply prefix options with the converter id.
|
44 |
-
|
45 |
-
I recommend leave the converters array at the default unless you have strong reasons not to. Otherwise you might miss out when new converters are added.
|
46 |
-
|
47 |
-
### Example:
|
48 |
-
|
49 |
-
```php
|
50 |
-
use WebPConvert\Convert\Converters\Stack;
|
51 |
-
|
52 |
-
Stack::convert($source, $destination, $options = [
|
53 |
-
|
54 |
-
// PS: only set converters if you have strong reasons to do so
|
55 |
-
'converters' => [
|
56 |
-
'cwebp', 'vips', 'imagick', 'gmagick', 'imagemagick', 'graphicsmagick', 'wpc', 'ewww', 'gd'
|
57 |
-
],
|
58 |
-
|
59 |
-
// Any available options can be set here, they dribble down to all converters.
|
60 |
-
'metadata' => 'all',
|
61 |
-
|
62 |
-
// To override for specific converter, you can prefix with converter id:
|
63 |
-
'cwebp-metadata' => 'exif',
|
64 |
-
|
65 |
-
// This can for example be used for setting ewww api key:
|
66 |
-
'ewww-api-key' => 'your-ewww-api-key-here',
|
67 |
-
|
68 |
-
// As an alternative to prefixing, you can use "converter-options" to set a whole bunch of overrides in one go:
|
69 |
-
'converter-options' => [
|
70 |
-
'wpc' => [
|
71 |
-
'crypt-api-key-in-transfer' => true
|
72 |
-
'api-key' => 'my dog is white',
|
73 |
-
'api-url' => 'https://example.com/wpc.php',
|
74 |
-
'api-version' => 1,
|
75 |
-
],
|
76 |
-
],
|
77 |
-
], $logger=null);
|
78 |
-
```
|
79 |
-
|
80 |
-
Note: As an alternative to setting the third party credentials in the options, you can set them through constants or environment variables ("WEBPCONVERT_EWWW_API_KEY", "WEBPCONVERT_WPC_API_KEY", "WEBPCONVERT_WPC_API_URL"). Paths to binaries can also be set like that (it is rarely needed to do this): "WEBPCONVERT_CWEBP_PATH", "WEBPCONVERT_GRAPHICSMAGICK_PATH" and WEBPCONVERT_IMAGEMAGICK_PATH"
|
81 |
-
|
82 |
-
To set an environment variable in Apache, you can add a line like this in your `.htaccess` or vhost configuration:
|
83 |
-
```
|
84 |
-
# Set ewww api key for WebP Convert
|
85 |
-
SetEnv WEBPCONVERT_EWWW_API_KEY yourVerySecretApiKeyGoesHere
|
86 |
-
|
87 |
-
# Set custom path to imagick for WebP Convert
|
88 |
-
SetEnv WEBPCONVERT_IMAGEMAGICK_PATH /usr/local/bin/magick
|
89 |
-
```
|
90 |
-
To set a constant:
|
91 |
-
```php
|
92 |
-
define('WEBPCONVERT_IMAGEMAGICK_PATH', '/usr/local/bin/magick');
|
93 |
-
```
|
94 |
-
|
95 |
-
|
96 |
-
## Configuring the options
|
97 |
-
|
98 |
-
### Preventing unnecessarily high quality setting for low quality jpegs
|
99 |
-
**Q:** What do you get if you convert a low quality jpeg (ie q=50) into a high quality webp (ie q=90) ?\
|
100 |
-
**A:** You maintain the low quality, but you get a large file`
|
101 |
-
|
102 |
-
What should we have done instead? We should have converted with a quality around 50. Of course, quality is still low - we cannot fix that - but it will not be less, *and the converted file will be much smaller*.
|
103 |
-
|
104 |
-
As unnecessary large conversions are rarely desirable, this library per default limits the quality setting so it does not exceed that of the source. This functionality requires that either *imagemagick*, *graphicsmagick* or *imagick* is installed (not necessarily compiled with webp support). When they are, all converters will have the "auto-limit" functionality. Otherwise, only *wpc* will support it (provided that one of these libraries is installed on the server of the cloud service).
|
105 |
-
|
106 |
-
How much can be gained? A lot!
|
107 |
-
The following low quality (q=50) jpeg weighs 54 kb. If this is converted to webp with quality=80, the size of the converted file is 52kb - almost no reduction! With auto-limit, the quality of the webp will be set to 50, and the size will be 34kb. Visually, the results are indistinguable.
|
108 |
-
|
109 |
-
![A low quality jpeg](https://raw.githubusercontent.com/rosell-dk/webp-convert/master/docs/v2.0/converting/architecture-q50-w600.jpg)
|
110 |
-
|
111 |
-
### Auto selecting between lossless/lossy encoding
|
112 |
-
WebP files can be encoded using either *lossless* or *lossy* encoding. The JPEG format is lossy and the PNG is lossless. However, this does not mean that you necessarily get the best conversion by always encoding JPEG to lossy and PNG to lossless. With JPEGs it is often the case, as they are usually pictures and pictures usually best encoded as lossy. With PNG it is however a different story, as you often can get a better compression using lossy encoding, also when using high quality level of say 85, which should be enough for the web.
|
113 |
-
|
114 |
-
As unnecessary large conversions are rarely desirable, this library per default tries to convert images using both lossy and lossless encoding and automatically selects the smallest. This is controlled using the *encoding* option, which per default is "auto", but can also be set to "lossy" or "lossless".
|
115 |
-
|
116 |
-
As an example, the following PNG (231 kb) will be compressed to 156 kb when converting to *lossless* webp. But when converting to *lossy* (quality: 85), it is compressed to merely 68 kb - less than half. (in case you are confused about the combination of lossy and transparency: Yes, you can have both at the same time with webp).
|
117 |
-
|
118 |
-
![Dice](https://raw.githubusercontent.com/rosell-dk/webp-convert/master/docs/v2.0/converting/dice.png)
|
119 |
-
|
120 |
-
Unless you changed the `near-lossless` option described below, the choice is actually between lossy and *near-lossless*.
|
121 |
-
|
122 |
-
Note that *gd* and *ewww* does not support this feature. *gd* can only produce lossy, and will simply do that. *ewww* can not be configured to use a certain encoding, but automatically chooses *lossless* encoding for PNGs and lossy for JPEGs.
|
123 |
-
|
124 |
-
### Near-lossless
|
125 |
-
*cwebp* and *vips* supports "near-lossless" mode. Near lossless produces a webp with lossless encoding but adjusts pixel values to help compressibility. The result is a smaller file. The price is described as a minimal impact on the visual quality.
|
126 |
-
|
127 |
-
As unnecessary large conversions are rarely desirable, this library per default sets *near-lossless* to 60. To disable near-lossless, set it to 100.
|
128 |
-
|
129 |
-
When compressing the image above (231 kb) to lossless, it compressed to 156 kb when near-lossless is set to 100. Setting near-lossless to 60 gets the size down to 110 kb while still looking great.
|
130 |
-
|
131 |
-
You can read more about the near-lossless mode [here](https://groups.google.com/a/webmproject.org/forum/#!topic/webp-discuss/0GmxDmlexek)
|
132 |
-
|
133 |
-
### Alpha-quality
|
134 |
-
All converters, except *gd* and *ewww* supports "alpha-quality" option. This allows lossy compressing of the alpha channel.
|
135 |
-
|
136 |
-
As unnecessary large conversions are rarely desirable, this library per default sets *alpha-quality* to 85. Set it to 100 to achieve lossless compression of alhpa.
|
137 |
-
|
138 |
-
Btw, the image above gets compressed to 68 kb with alpha quality set to 100. Surprisingly, it gets slightly larger (70 kb) with alpha quality set to 85. Setting alpha quality to 50 gets it down to merely 35 kb - about half - while still looking great.
|
139 |
-
|
140 |
-
You can read more about the alpha-quality option [here](https://developers.google.com/speed/webp/docs/cwebp) and [here](https://www.smashingmagazine.com/2018/07/converting-images-to-webp/)
|
141 |
-
|
142 |
-
### Sharp YUV
|
143 |
-
libwebp has an overlooked option which improves accuracy for RGB to YUV mapping at the price for longer conversion time. You can control it with the new 'sharp-yuv' option (introduced in webp-convert 2.6.0). Read an appraisal of the option [here](https://www.ctrl.blog/entry/webp-sharp-yuv.html).
|
144 |
-
|
145 |
-
### Tip: don't set quality too high...
|
146 |
-
**Q:** What do you get if you convert an excessively high quality jpeg into an excessively high quality webp?\
|
147 |
-
**A:** An excessively big file
|
148 |
-
|
149 |
-
The size of a webp file grows enormously with the quality setting. For the web however, a quality above 75 is rarely needed. For this reason the library has a per default sets the quality to 75 for jpegs.
|
150 |
-
|
151 |
-
So, how much can be gained? A lot!
|
152 |
-
The following excessively high quality jpeg (q=100) weighs 146 kb. Converting it to webp with quality=100 results in a 99kb image. Converting it to quality=85 results in a 40kb image.
|
153 |
-
|
154 |
-
![A (too) high quality jpeg](https://raw.githubusercontent.com/rosell-dk/webp-convert/master/docs/v2.0/converting/mouse-q100.jpg)
|
155 |
-
|
156 |
-
### PNG og JPEG-specific options.
|
157 |
-
|
158 |
-
To have options depending on the image type of the source, you can use the `png` and `jpeg` keys.
|
159 |
-
|
160 |
-
The following options mimics the default behaviour (version 2.0 - 2.5):
|
161 |
-
|
162 |
-
```php
|
163 |
-
$options = [
|
164 |
-
'png' => [
|
165 |
-
'encoding' => 'auto', /* Try both lossy and lossless and pick smallest */
|
166 |
-
'near-lossless' => 60, /* The level of near-lossless image preprocessing (when trying lossless) */
|
167 |
-
'quality' => 85, /* Quality when trying lossy. It is set high because pngs is often selected to ensure high quality */
|
168 |
-
'sharp-yuv' => true,
|
169 |
-
],
|
170 |
-
'jpeg' => [
|
171 |
-
'encoding' => 'auto', /* If you are worried about the longer conversion time, you could set it to "lossy" instead (lossy will often be smaller than lossless for jpegs) */
|
172 |
-
'quality' => 'auto', /* Set to same as jpeg (requires imagick or gmagick extension, not necessarily compiled with webp) */
|
173 |
-
'max-quality' => 80, /* Only relevant if quality is set to "auto" */
|
174 |
-
'default-quality' => 75, /* Fallback quality if quality detection isnt working */
|
175 |
-
'sharp-yuv' => true,
|
176 |
-
]
|
177 |
-
];
|
178 |
-
```
|
179 |
-
PS: From version 2.6 on, you should use the new "auto-limit" option instead of setting quality to "auto".
|
180 |
-
|
181 |
-
The following options mimics the default behaviour (version 2.6 and forth):
|
182 |
-
|
183 |
-
```php
|
184 |
-
$options = [
|
185 |
-
'png' => [
|
186 |
-
'encoding' => 'auto', /* Try both lossy and lossless and pick smallest */
|
187 |
-
'near-lossless' => 60, /* The level of near-lossless image preprocessing (when trying lossless) */
|
188 |
-
'quality' => 85, /* Quality when trying lossy. It is set high because pngs is often selected to ensure high quality */
|
189 |
-
'sharp-yuv' => true,
|
190 |
-
],
|
191 |
-
'jpeg' => [
|
192 |
-
'encoding' => 'auto', /* If you are worried about the longer conversion time, you could set it to "lossy" instead (lossy will often be smaller than lossless for jpegs) */
|
193 |
-
'quality' => 75, /* Quality when trying lossy. It is set a bit lower for jpeg than png */
|
194 |
-
'auto-limit' => true, /* Prevents using a higher quality than that of the source (requires imagick or gmagick extension, not necessarily compiled with webp) */
|
195 |
-
'sharp-yuv' => true,
|
196 |
-
]
|
197 |
-
];
|
198 |
-
```
|
199 |
-
|
200 |
-
The *png* and *jpeg* options can hold any other option - also the converter specific options.
|
201 |
-
A use case could for example be to use different converters for png and jpeg:
|
202 |
-
|
203 |
-
```php
|
204 |
-
$options = [
|
205 |
-
'png' => [
|
206 |
-
'converters' => ['ewww'],
|
207 |
-
],
|
208 |
-
'jpeg' => [
|
209 |
-
'converters' => ['gd'],
|
210 |
-
]
|
211 |
-
];
|
212 |
-
```
|
213 |
-
|
214 |
-
## Available options
|
215 |
-
|
216 |
-
**All** available options are documented [here](https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/converting/options.md).
|
217 |
-
|
218 |
-
Here is a quick overview of the few ones discussed here.
|
219 |
-
|
220 |
-
### Version 2.0 - 2.5
|
221 |
-
|
222 |
-
| Option | Default (jpeg) | Default (png) | Description |
|
223 |
-
| ----------------- | ------------------ | ------------------- | ---------------------------------------------------------------------------------- |
|
224 |
-
| quality | "auto" | 85 | See the "Auto quality" section above. |
|
225 |
-
| max-quality | 85 | 85 | Only relevant for jpegs and when quality is set to "auto". |
|
226 |
-
| default-quality | 75 | 85 | |
|
227 |
-
| metadata | "none" | "none" | Valid values: "all", "none", "exif", "icc", "xmp".<br><br>Note: Currently only *cwebp* supports all values. *gd* will always remove all metadata. *ewww*, *imagick* and *gmagick* can either strip all, or keep all (they will keep all, unless metadata is set to *none*) |
|
228 |
-
| encoding | "auto" | "auto" | See the "Auto selecting between lossless/lossy encoding" section above |
|
229 |
-
| jpeg | - | - | Array of options which will be merged into the other options when source is a JPEG |
|
230 |
-
| png | - | - | Array of options which will be merged into the other options when source is a PNG |
|
231 |
-
| skip | false | false | If true, conversion will be skipped (ie for skipping png conversion for some converters) |
|
232 |
-
|
233 |
-
### Version > 2.6
|
234 |
-
|
235 |
-
| Option | Default (jpeg) | Default (png) | Description |
|
236 |
-
| ----------------- | ------------------ | ------------------- | ---------------------------------------------------------------------------------- |
|
237 |
-
| quality | 75 | 85 | Quality for lossy encoding |
|
238 |
-
| auto-limit | true | true | Only relevant for jpegs and lossy encoding |
|
239 |
-
| metadata | "none" | "none" | Valid values: "all", "none", "exif", "icc", "xmp".<br><br>Note: Currently only *cwebp* supports all values. *gd* will always remove all metadata. *ewww*, *imagick* and *gmagick* can either strip all, or keep all (they will keep all, unless metadata is set to *none*) |
|
240 |
-
| encoding | "auto" | "auto" | See the "Auto selecting between lossless/lossy encoding" section above |
|
241 |
-
| jpeg | - | - | Array of options which will be merged into the other options when source is a JPEG |
|
242 |
-
| png | - | - | Array of options which will be merged into the other options when source is a PNG |
|
243 |
-
| skip | false | false | If true, conversion will be skipped (ie for skipping png conversion for some converters) |
|
244 |
-
|
245 |
-
|
246 |
-
## More info
|
247 |
-
|
248 |
-
- The complete api is available [here](https://www.bitwise-it.dk/webp-convert/api/2.0/html/index.xhtml)
|
249 |
-
- The converters are described in more detail here (for 1.3.9): [docs/v1.3/converting/converters.md](https://github.com/rosell-dk/webp-convert/blob/master/docs/v1.3/converting/converters.md).
|
250 |
-
- On the github wiki you can find installation instructions for imagick with webp, gd with webp, etc.
|
251 |
-
- This document is a newly written introduction to the convert api, which has been created as part of the 2.0 release. The old introduction, which was made for 1.3 is available here: [docs/converting/v1.3/convert.md](https://github.com/rosell-dk/webp-convert/blob/master/docs/v1.3/converting/convert.md).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vendor/rosell-dk/webp-convert/docs/v2.0/converting/mouse-q100.jpg
DELETED
Binary file
|
vendor/rosell-dk/webp-convert/docs/v2.0/converting/options.md
DELETED
@@ -1,403 +0,0 @@
|
|
1 |
-
# Options
|
2 |
-
|
3 |
-
This is a list of all options available for converting.
|
4 |
-
|
5 |
-
Note that as the *stack* and *wpc* converters delegates the options to their containing converters, the options that they supports depend upon the converters they have been configured to use (and which of them that are operational)<br><br>
|
6 |
-
|
7 |
-
## General options
|
8 |
-
|
9 |
-
### `alpha-quality`
|
10 |
-
```
|
11 |
-
Type: integer (0-100)
|
12 |
-
Default: 85
|
13 |
-
Supported by: cwebp, vips, imagick, gmagick, imagemagick and graphicsmagick
|
14 |
-
```
|
15 |
-
Quality of alpha channel. Often, there is no need for high quality transparency layer and in some cases you can tweak this all the way down to 10 and save a lot in file size. The option only has effect with lossy encoding, and of course only on images with transparency (so it is irrelevant when converting jpegs). Read more about tweaking the option [here](https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/converting/introduction-for-converting.md#alpha-quality)<br><br>
|
16 |
-
|
17 |
-
### `auto-filter`
|
18 |
-
```
|
19 |
-
Type: boolean
|
20 |
-
Default: false
|
21 |
-
Supported by: cwebp, vips, imagick, gmagick, imagemagick and graphicsmagick
|
22 |
-
```
|
23 |
-
Turns auto-filter on. This algorithm will spend additional time optimizing the filtering strength to reach a well-balanced quality. Unfortunately, it is extremely expensive in terms of computation. It takes about 5-10 times longer to do a conversion. A 1MB picture which perhaps typically takes about 2 seconds to convert, will takes about 15 seconds to convert with auto-filter. So in most cases, you will want to leave this at its default, which is off.<br><br>
|
24 |
-
|
25 |
-
### `auto-limit`
|
26 |
-
```
|
27 |
-
Type: boolean
|
28 |
-
Default: true
|
29 |
-
Supported by: all
|
30 |
-
```
|
31 |
-
Limits the quality to be no more than that of the jpeg. The option is only relevant when converting jpegs to lossy webp. To be functional, webp-convert needs to be able to detect the quality of the jpeg, which requires ImageMagick or GraphicsMagick. Read about the option in the [introduction](https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/converting/introduction-for-converting.md#auto-quality). In 2.7.0, it will become possible to adjust the limit with a new option. I'm currently debating with myself how this should work. Your comments and opinions would be appreciated - [here](https://github.com/rosell-dk/webp-convert/issues/289)
|
32 |
-
|
33 |
-
### `converter` (new in 2.8.0)
|
34 |
-
```
|
35 |
-
Type: string
|
36 |
-
Default: null
|
37 |
-
Supported by: WebPConvert::convert method
|
38 |
-
```
|
39 |
-
Simplifies using a specific converter. Before this option, you would either need to call the converter class (ie `Ewww::convert`) (not very flexible), or set the stack to contain just one converter (unnecessary overhead). If you do not use this option, `WebPConvert::convert` works as normal (it calls `Stack::convert`), if you do use it, it hands over the converting to the converter specified (specified by id, ie. "cwebp").
|
40 |
-
|
41 |
-
### `default-quality` (DEPRECATED)
|
42 |
-
```
|
43 |
-
Type: integer (0-100)
|
44 |
-
Default: 75 for jpegs and 85 for pngs
|
45 |
-
Supported by: all (cwebp, ewww, gd, ffmpeg, gmagick, graphicsmagick, imagick, imagemagick, vips)
|
46 |
-
```
|
47 |
-
This option has been deprecated. See why [here](https://github.com/rosell-dk/webp-convert/issues/281). It was used to determine the quality in case auto limiting was not available.<br><br>
|
48 |
-
|
49 |
-
### `encoding`
|
50 |
-
```
|
51 |
-
Type: string ("lossy" | "lossless" | "auto")
|
52 |
-
Default: "auto"
|
53 |
-
Supported by: cwebp, vips, ffmpeg, imagick, gmagick, imagemagick and graphicsmagick (gd always uses lossy encoding, ewww uses lossless for pngs and lossy for jpegs)
|
54 |
-
```
|
55 |
-
Set encoding for the webp. If you choose "auto", webp-convert will convert to both lossy and lossless and pick the smallest result. Read more about this option in the ["lossy/lossless" section in the introduction](https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/converting/introduction-for-converting.md#auto-selecting-between-losslesslossy-encoding).<br><br>
|
56 |
-
|
57 |
-
### `ewww-api-key`
|
58 |
-
```
|
59 |
-
Type: string
|
60 |
-
Default: ''
|
61 |
-
Supported by: ewww
|
62 |
-
```
|
63 |
-
Api key for the ewww converter. The option is actually called *api-key*, however, any option can be prefixed with a converter id to only apply to that converter. As this option is only for the ewww converter, it is natural to use the "ewww-" prefix.
|
64 |
-
|
65 |
-
Note: This option can alternatively be set through the *EWWW_API_KEY* environment variable.<br><br>
|
66 |
-
|
67 |
-
### `ewww-check-key-status-before-converting`
|
68 |
-
```
|
69 |
-
Type: boolean
|
70 |
-
Default: true
|
71 |
-
Supported by: ewww
|
72 |
-
```
|
73 |
-
Decides whether or not the ewww service should be invoked in order to check if the api key is valid. Doing this for every conversion is not optimal. However, it would be worse if the service was contacted repeatedly to do conversions with an invalid api key - as conversion requests carries a big upload with them. As this library cannot prevent such repeated failures (it is stateless), it per default does the additional check. However, your application can prevent it from happening by picking up invalid / exceeded api keys discovered during conversion. Such failures are stored in `Ewww::$nonFunctionalApiKeysDiscoveredDuringConversion` (this is also set even though a converter later in the stack succeeds. Do not only read this value off in a catch clauses).
|
74 |
-
|
75 |
-
You should only set this option to *false* if you handle when the converter discovers invalid api keys during conversion.
|
76 |
-
|
77 |
-
### `jpeg`
|
78 |
-
```
|
79 |
-
Type: array
|
80 |
-
Default: []
|
81 |
-
Supported by: all
|
82 |
-
```
|
83 |
-
Override selected options when the source is a jpeg. The options provided here are simply merged into the other options when the source is a jpeg.
|
84 |
-
Read about this option in the [introduction](https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/converting/introduction-for-converting.md#png-og-jpeg-specific-options).<br><br>
|
85 |
-
|
86 |
-
### `log-call-arguments`
|
87 |
-
```
|
88 |
-
Type: boolean
|
89 |
-
Default: false
|
90 |
-
Supported by: all
|
91 |
-
```
|
92 |
-
Enabling this simply puts some more in the log - namely the arguments that was supplied to the call. Sensitive information is starred out.
|
93 |
-
|
94 |
-
### `low-memory`
|
95 |
-
```
|
96 |
-
Type: boolean
|
97 |
-
Default: false
|
98 |
-
Supported by: cwebp, imagick, imagemagick and graphicsmagick
|
99 |
-
```
|
100 |
-
Reduce memory usage of lossy encoding at the cost of ~30% longer encoding time and marginally larger output size. Only effective when the *method* option is 3 or more. Read more in [the docs](https://developers.google.com/speed/webp/docs/cwebp).<br><br>
|
101 |
-
|
102 |
-
### `max-quality` (DEPRECATED)
|
103 |
-
```
|
104 |
-
Type: integer (0-100)
|
105 |
-
Default: 85
|
106 |
-
Supported by: all (cwebp, ewww, ffmpeg, gd, gmagick, graphicsmagick, imagick, imagemagick, vips)
|
107 |
-
```
|
108 |
-
This option has been deprecated. See why [here](https://github.com/rosell-dk/webp-convert/issues/281)<br><br>
|
109 |
-
|
110 |
-
### `metadata`
|
111 |
-
```
|
112 |
-
Type: string ("all" | "none" | "exif" | "icc" | "xmp" | "exif,icc" | "exif,xmp" | "icc,xmp")
|
113 |
-
Default: 'none'
|
114 |
-
Supported by: Only *cwebp* supports "exif", "icc" and "xmp". *gd* cannot copy metadata. *ffmpeg* always copies metadata. The rest supports "all" and "none" (ewww, gmagick, graphicsmagick, imagick, imagemagick, vips)
|
115 |
-
```
|
116 |
-
Determines which metadata that should be copied over to the webp. Setting it to "all" preserves all metadata, setting it to "none" strips all metadata. *cwebp* can take a comma-separated list of which kinds of metadata that should be copied (ie "exif,icc"). *gd* will always remove all metadata and *ffmpeg* will always keep all metadata. The rest can either strip all or keep all (they will keep all, unless the option is set to *none*).<br><br>
|
117 |
-
|
118 |
-
### `method`
|
119 |
-
```
|
120 |
-
Type: integer (0-6)
|
121 |
-
Default: 6
|
122 |
-
Supported by: cwebp, vips, imagick, gmagick, imagemagick, graphicsmagick and ffmpeg
|
123 |
-
```
|
124 |
-
This parameter controls the trade off between encoding speed and the compressed file size and quality. Possible values range from 0 to 6. 0 is fastest. 6 results in best quality. PS: "method" is not a very descriptive name, but this is what its called in libwebp, which is why we also choose it for webpconvert. In ffmpeg, they renamed it "compression_level", in vips, they call it "reduction_effort". Both better names, but as said, use "method" with webpconvert<br><br>
|
125 |
-
|
126 |
-
### `near-lossless`
|
127 |
-
```
|
128 |
-
Type: integer (0-100)
|
129 |
-
Default: 60
|
130 |
-
Supported by: cwebp, vips
|
131 |
-
```
|
132 |
-
This option allows you to get impressively better compression for lossless encoding, with minimal impact on visual quality. The result is still lossless (lossless encoding). What libwebp does is that it preprocesses the image before encoding it, in order to make it better suited for compression. The range is 0 (maximum preprocessing) to 100 (no preprocessing). A good compromise would be around 60. The option is ignored when encoding is set to lossy. Read more [here](https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/converting/introduction-for-converting.md#near-lossless).<br><br>
|
133 |
-
|
134 |
-
### `png`
|
135 |
-
```
|
136 |
-
Type: array
|
137 |
-
Default: []
|
138 |
-
Supported by: all
|
139 |
-
```
|
140 |
-
Override selected options when the source is a png. The options provided here are simply merged into the other options when the source is a png.
|
141 |
-
Read about this option in the [introduction](https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/converting/introduction-for-converting.md#png-og-jpeg-specific-options).<br><br>
|
142 |
-
|
143 |
-
### `preset`
|
144 |
-
```
|
145 |
-
Type: string ('none', 'default', 'photo', 'picture', 'drawing', 'icon' or 'text')
|
146 |
-
Default: "none"
|
147 |
-
Supported by: cwebp, vips, gmagick, graphicsmagick, imagick, imagemagick, ffmpeg
|
148 |
-
```
|
149 |
-
Using a preset will set many of the other options to suit a particular type of source material. It even overrides them. It does however not override the quality option. "none" means that no preset will be set. PS: The imagemagick family only partly supports this setting, as they have grouped three of the options ("drawing", "icon" and "text") into "graph". So if you for example set "preset" to "icon" with the imagemagick converter, imagemagick will be executed like this: "-define webp:image-hint='graph'".<br><br>
|
150 |
-
|
151 |
-
### `quality`
|
152 |
-
```
|
153 |
-
Type: integer (0-100) | "auto" ("auto" is now deprecated - use the "auto-limit" option instead)
|
154 |
-
Default: 75 for jpegs and 85 for pngs
|
155 |
-
Supported by: all (cwebp, ewww, gd, gmagick, graphicsmagick, imagick, imagemagick, vips, ffmpeg)
|
156 |
-
```
|
157 |
-
Quality for lossy encoding.<br><br>
|
158 |
-
|
159 |
-
### `sharp-yuv`
|
160 |
-
```
|
161 |
-
Type: boolean
|
162 |
-
Default: true
|
163 |
-
Supported by: cwebp, vips, gmagick, graphicsmagick, imagick, imagemagick
|
164 |
-
```
|
165 |
-
Better RGB->YUV color conversion (sharper and more accurate) at the expense of a little extra conversion time. Read more [here](https://www.ctrl.blog/entry/webp-sharp-yuv.html).
|
166 |
-
|
167 |
-
### `size-in-percentage`
|
168 |
-
```
|
169 |
-
Type: integer (0-100) | null
|
170 |
-
Default: null
|
171 |
-
Supported by: cwebp
|
172 |
-
```
|
173 |
-
This option sets the file size, *cwebp* should aim for, in percentage of the original. If you for example set it to *45*, and the source file is 100 kb, *cwebp* will try to create a file with size 45 kb (we use the `-size` option). This is an excellent alternative to the "quality:auto" option. If the quality detection isn't working on your system (and you do not have the rights to install imagick or gmagick), you should consider using this options instead. *Cwebp* is generally able to create webp files with the same quality at about 45% the size. So *45* would be a good choice. The option overrides the quality option. And note that it slows down the conversion - it takes about 2.5 times longer to do a conversion this way, than when quality is specified. Default is *off* (null).<br><br>
|
174 |
-
|
175 |
-
### `skip`
|
176 |
-
```
|
177 |
-
Type: boolean
|
178 |
-
Default: false
|
179 |
-
Supported by: all
|
180 |
-
```
|
181 |
-
Simply skips conversion. For example this can be used to skip png conversion for a specific converter like this:
|
182 |
-
```php
|
183 |
-
$options = [
|
184 |
-
'png' => [
|
185 |
-
'gd-skip' => true,
|
186 |
-
]
|
187 |
-
];
|
188 |
-
```
|
189 |
-
|
190 |
-
Or it can be used to skip unwanted converters from the default stack, like this:
|
191 |
-
```php
|
192 |
-
$options = [
|
193 |
-
'ewww-skip' => true,
|
194 |
-
'wpc-skip' => true,
|
195 |
-
'gd-skip' => true,
|
196 |
-
'imagick-skip' => true,
|
197 |
-
'gmagick-skip' => true,
|
198 |
-
];
|
199 |
-
```
|
200 |
-
<br>
|
201 |
-
|
202 |
-
### `use-nice`
|
203 |
-
```
|
204 |
-
Type: boolean
|
205 |
-
Default: false
|
206 |
-
Supported by: cwebp, graphicsmagick, imagemagick, ffmpeg
|
207 |
-
```
|
208 |
-
This option only applies to converters which are using exec() to execute a binary directly on the host. If *use-nice* is set, it will be examined if the [`nice`]( https://en.wikipedia.org/wiki/Nice_(Unix)) command is available on the host. If it is, the binary is executed using *nice*. This assigns low priority to the process and will save system resources - but result in slower conversion.<br><br>
|
209 |
-
|
210 |
-
|
211 |
-
# Options unique for individual converters
|
212 |
-
|
213 |
-
## cwebp options
|
214 |
-
Options unique to the "cwebp" converter
|
215 |
-
|
216 |
-
### `command-line-options`
|
217 |
-
```
|
218 |
-
Type: string
|
219 |
-
Default: ''
|
220 |
-
Supported by: cwebp
|
221 |
-
```
|
222 |
-
This allows you to set any parameter available for cwebp in the same way as you would do when executing *cwebp*. You could ie set it to "-sharpness 5 -mt -crop 10 10 40 40". Read more about all the available parameters in [the docs](https://developers.google.com/speed/webp/docs/cwebp).<br><br>
|
223 |
-
|
224 |
-
### `rel-path-to-precompiled-binaries`
|
225 |
-
```
|
226 |
-
Type: string
|
227 |
-
Default: './Binaries'
|
228 |
-
Supported by: cwebp
|
229 |
-
```
|
230 |
-
Allows you to change where to look for the precompiled binaries. While this may look as a risk, it is completely safe, as the binaries are hash-checked before being executed. The option is needed when you are using two-file version of webp-on-demand.
|
231 |
-
|
232 |
-
### `try-cwebp`
|
233 |
-
```
|
234 |
-
Type: boolean
|
235 |
-
Default: true
|
236 |
-
Supported by: cwebp
|
237 |
-
```
|
238 |
-
If set, the converter will try executing "cwebp -version". In case it succeeds, and the version is higher than those working cwebp's found using other methods, the conversion will be done by executing this cwebp.
|
239 |
-
|
240 |
-
### `try-common-system-paths`
|
241 |
-
```
|
242 |
-
Type: boolean
|
243 |
-
Default: true
|
244 |
-
Supported by: cwebp
|
245 |
-
```
|
246 |
-
If set, the converter will look for a cwebp binaries residing in common system locations such as `/usr/bin/cwebp`. If such exist, it is assumed that they are valid cwebp binaries. A version check will be run on the binaries found (they are executed with the "-version" flag. The cwebp with the highest version found using this method and the other enabled methods will be used for the actual conversion.
|
247 |
-
|
248 |
-
This method might find a cwebp binary something that isn't found using `try-discovering-cwebp` if these common paths are not within PATH or neither `which` or `whereis` are available.
|
249 |
-
|
250 |
-
Note: All methods for discovering cwebp binaries are per default enabled. You can save a few microseconds by disabling all, but the one that discovers the cwebp binary with the highest version (check the conversion log to find out). However, it is probably not worth it, as your setup will then become less resilient to system changes.
|
251 |
-
|
252 |
-
### `try-discovering-cwebp`
|
253 |
-
```
|
254 |
-
Type: boolean
|
255 |
-
Default: true
|
256 |
-
Supported by: cwebp
|
257 |
-
```
|
258 |
-
If set, the converter will try to discover installed cwebp binaries using the `which -a cwebp` command, or in case that fails, the `whereis -b cwebp` command. These commands will find cwebp binaries residing in PATH
|
259 |
-
|
260 |
-
### `try-supplied-binary-for-os`
|
261 |
-
```
|
262 |
-
Type: boolean
|
263 |
-
Default: true
|
264 |
-
Supported by: cwebp
|
265 |
-
```
|
266 |
-
If set, the converter will try use a precompiled cwebp binary that comes with webp-convert. But only if it has a higher version that those found by other methods. As the library knows the versions of its cwebps, no additional time is spent executing them with the "-version" parameter. The binaries are hash-checked before executed. The library btw. comes with several versions of precompiled cwebps because they have different dependencies - some works on some systems and others on others.
|
267 |
-
|
268 |
-
### `skip-these-precompiled-binaries`
|
269 |
-
```
|
270 |
-
Type: string
|
271 |
-
Default: ''
|
272 |
-
Supported by: cwebp
|
273 |
-
```
|
274 |
-
The precompiled binaries from google have dependencies, and they are different. This means that some of them works on some systems, others on others. For this reason, several precompiled binaries are shipped with the library - we want it to simply work on as many systems as possible. Of course, the binary with the highest version number is tried first. But if it doesn't work, time has been wasted running an executable that doesn't work, and validating the hash before running it. To avoid this, use this option to bypass precompiled binaries that you know doesn't work on your current system. You pass in the filenames (comma separated), ie "cwebp-120-linux-x86-64,cwebp-110-linux-x86-64". In order to see if time is wasted on a supplied binary, that doesn't work, check the conversion log. You can also get info about the filenames of the binaries in the conversion log. Instructions on viewing the conversion log are available [here](https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/converting/introduction-for-converting.md#insights-to-the-process).
|
275 |
-
Btw: If minimizing the overhead is a priority, there are alternatives to this option that speeds up conversion time more. It is the hash-check that is costly. Hash-checking is only done on the cwebps shipped with the library.
|
276 |
-
|
277 |
-
Alternative 1: Disabling the "cwebp-try-supplied-binary-for-os" option thus avoids the rather expensive job of hash-checking the binary each time it is run. The cost of this is that you don't get the newest cwebp available (the ones shipped with the library will only be used when you don't have a newer one available).
|
278 |
-
|
279 |
-
Alternative 2: If you set an environment variable called "WEBPCONVERT_CWEBP_PATH" (or define a "WEBPCONVERT_CWEBP_PATH" variable in PHP), cwebp will simply execute the binary found at that path and not examine other alternatives. Also, there will be no hash check either. Doing so however makes your system a little bit less secure - exactly because it bypasses the hash-checking. If some security whole allows an attacker to upload a binary, replacing the one set like this, an attacker would then have a way to have that binary executed. Here is how you define the variable in PHP: `define("WEBPCONVERT_CWEBP_PATH", "/path/to/working/cwebp/for/example/one/in/src/Convert/Converters/Binaries/dir");`. Also beware that by doing this, you will need to update your code in order to take advantage of future cwebp releases.
|
280 |
-
|
281 |
-
## stack options
|
282 |
-
Options unique to the "stack" converter
|
283 |
-
|
284 |
-
### `stack-converters`
|
285 |
-
```
|
286 |
-
Type: array
|
287 |
-
Default: ['cwebp', 'vips', 'imagick', 'gmagick', 'imagemagick', 'graphicsmagick', 'wpc', 'ewww', 'gd']
|
288 |
-
Supported by: stack
|
289 |
-
```
|
290 |
-
|
291 |
-
Specify the converters to try and their order.
|
292 |
-
|
293 |
-
Beware that if you use this option, you will miss out when more converters are added in future updates. If the purpose of setting this option is to remove converters that you do not want to use, you can use the *skip* option instead. Ie, to skip ewww, set *ewww-skip* to true. On the other hand, if what you actually want is to change the order, you can use the *stack-preferred-converters* option, ie setting *stack-preferred-converters* to `['vips', 'wpc']` will move vips and wpc in front of the others. Should they start to fail, you will still have the others as backup.
|
294 |
-
|
295 |
-
The array specifies the converters to try and their order. Each item can be:
|
296 |
-
|
297 |
-
- An id (ie "cwebp")
|
298 |
-
- A fully qualified class name (in case you have programmed your own custom converter)
|
299 |
-
- An array with two keys: "converter" and "options".
|
300 |
-
|
301 |
-
`
|
302 |
-
Alternatively, converter options can be set using the *converter-options* option.
|
303 |
-
|
304 |
-
Read more about the stack converter in the [introduction](https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/converting/introduction-for-converting.md#the-stack-converter).<br><br>
|
305 |
-
|
306 |
-
### `stack-converter-options`
|
307 |
-
```
|
308 |
-
Type: array
|
309 |
-
Default: []
|
310 |
-
Supported by: stack
|
311 |
-
```
|
312 |
-
Extra options for specific converters. Example:
|
313 |
-
|
314 |
-
```php
|
315 |
-
$options = [
|
316 |
-
'converter-options' => [
|
317 |
-
'vips' => [
|
318 |
-
'quality' => 72
|
319 |
-
],
|
320 |
-
]
|
321 |
-
]
|
322 |
-
```
|
323 |
-
<br>
|
324 |
-
|
325 |
-
### `stack-extra-converters`
|
326 |
-
```
|
327 |
-
Type: array
|
328 |
-
Default: []
|
329 |
-
Supported by: stack
|
330 |
-
```
|
331 |
-
Add extra converters to the bottom of the stack. The items are similar to those in the `stack-converters` option.<br><br>
|
332 |
-
|
333 |
-
### `stack-preferred-converters`
|
334 |
-
```
|
335 |
-
Type: array
|
336 |
-
Default: []
|
337 |
-
Supported by: stack
|
338 |
-
```
|
339 |
-
With this option you can move specified converters to the top of the stack. The converters are specified by id. For example, setting this option to ['vips', 'wpc'] ensures that *vips* will be tried first and - in case that fails - *wpc* will be tried. The rest of the converters keeps their relative order.<br><br>
|
340 |
-
|
341 |
-
### `stack-shuffle`
|
342 |
-
```
|
343 |
-
Type: boolean
|
344 |
-
Default: false
|
345 |
-
Supported by: stack
|
346 |
-
```
|
347 |
-
Shuffle the converters in the stack. This can for example be used to balance load between several wpc instances in a substack, as illustrated [here](https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/converting/converters/stack.md)<br><br>
|
348 |
-
|
349 |
-
## vips options
|
350 |
-
|
351 |
-
### `vips-smart-subsample` (DEPRECATED)
|
352 |
-
```
|
353 |
-
Type: boolean
|
354 |
-
Default: false
|
355 |
-
Supported by: vips
|
356 |
-
```
|
357 |
-
This feature seemed not to be part of *libwebp* but intrinsic to vips. However, we were wrong - the feature is the same as 'sharp-yuv'. Use that instead.<br><br>
|
358 |
-
|
359 |
-
|
360 |
-
## wcp options
|
361 |
-
|
362 |
-
### `wpc-api-key`
|
363 |
-
```
|
364 |
-
Type: string
|
365 |
-
Default: ''
|
366 |
-
Supported by: wpc
|
367 |
-
```
|
368 |
-
Api key for the wpc converter. The option is actually called *api-key*, however, any option can be prefixed with a converter id to only apply to that converter. As this option is only for the wpc converter, it is natural to use the "wpc-" prefix. Same goes for the other "wpc-" options.
|
369 |
-
|
370 |
-
Note: You can alternatively set the api key through the *WPC_API_KEY* environment variable.<br><br>
|
371 |
-
|
372 |
-
### `wpc-api-url`
|
373 |
-
```
|
374 |
-
Type: string
|
375 |
-
Default: ''
|
376 |
-
Supported by: wpc
|
377 |
-
```
|
378 |
-
Note: You can alternatively set the api url through the *WPC_API_URL* environment variable.<br><br>
|
379 |
-
|
380 |
-
### `wpc-api-version`
|
381 |
-
```
|
382 |
-
Type: integer (0 - 1 - 2)
|
383 |
-
Default: 2
|
384 |
-
Supported by: wpc
|
385 |
-
```
|
386 |
-
PS: In many releases, you had to set this to 1 even though you were running on 2. This will be fixed in 2.9.0
|
387 |
-
<br>
|
388 |
-
|
389 |
-
### `wpc-crypt-api-key-in-transfer`
|
390 |
-
```
|
391 |
-
Type: boolean
|
392 |
-
Default: false
|
393 |
-
Supported by: wpc
|
394 |
-
```
|
395 |
-
<br>
|
396 |
-
|
397 |
-
### `wpc-secret`
|
398 |
-
```
|
399 |
-
Type: string
|
400 |
-
Default: ''
|
401 |
-
Supported by: wpc
|
402 |
-
```
|
403 |
-
Note: This option is only relevant for api version 0.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vendor/rosell-dk/webp-convert/docs/v2.0/installing-converters/cwebp.md
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
# Installing cwebp using official precompilations
|
2 |
-
|
3 |
-
Official precompilations are available [here](https://developers.google.com/speed/webp/docs/precompiled). Since `WebPConvert` compares each binary's checksum first, you will have to change the checksums hardcoded in `Converters/Cwebp.php` if you want to replace any of them. If you feel the need of using another binary, please let us know - chances are that it should be added to the project!
|
|
|
|
|
|
vendor/rosell-dk/webp-convert/docs/v2.0/installing-converters/ffmpeg.md
DELETED
@@ -1,15 +0,0 @@
|
|
1 |
-
# Installing FFMpeg
|
2 |
-
Its very easy.
|
3 |
-
|
4 |
-
|
5 |
-
# Ubuntu
|
6 |
-
Here is a tutorial for ubuntu: https://linuxize.com/post/how-to-install-ffmpeg-on-ubuntu-18-04/
|
7 |
-
|
8 |
-
## GitHub actions workflow
|
9 |
-
As easy as adding this step to your workflow yaml:
|
10 |
-
|
11 |
-
```yaml
|
12 |
-
- name: Setup ffmpeg
|
13 |
-
uses: FedericoCarboni/setup-ffmpeg@v1
|
14 |
-
```
|
15 |
-
docs: https://github.com/marketplace/actions/setup-ffmpeg
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vendor/rosell-dk/webp-convert/docs/v2.0/installing-converters/gd.md
DELETED
@@ -1,19 +0,0 @@
|
|
1 |
-
# Installing Gd extension with WebP support
|
2 |
-
|
3 |
-
## Ubuntu 18.04
|
4 |
-
|
5 |
-
On Ubuntu 18.04, I did not have to do anything special to configure Gd for WebP support. The following worked right away:
|
6 |
-
```
|
7 |
-
sudo apt-get install php7.2-gd
|
8 |
-
```
|
9 |
-
|
10 |
-
## Ubuntu 16.04
|
11 |
-
The official page with installation instructions is [available here](http://il1.php.net/manual/en/image.installation.php)
|
12 |
-
|
13 |
-
In summary:
|
14 |
-
|
15 |
-
PHP 5.5.0:
|
16 |
-
To get WebP support for `gd` in PHP 5.5.0, PHP must be configured with the `--with-vpx-dir` flag.
|
17 |
-
|
18 |
-
PHP >7.0.0:
|
19 |
-
PHP has to be configured with the `--with-webp-dir` flag
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vendor/rosell-dk/webp-convert/docs/v2.0/installing-converters/gmagick-extension.md
DELETED
@@ -1,40 +0,0 @@
|
|
1 |
-
# Installing GMagick PHP extension with WebP support
|
2 |
-
|
3 |
-
See:
|
4 |
-
https://github.com/rosell-dk/webp-convert/issues/37
|
5 |
-
|
6 |
-
## MX-19.4
|
7 |
-
I succeeded by simply doing the following after installing graphicsmagick, libwebp and libwebp-dev:
|
8 |
-
```
|
9 |
-
sudo apt install php-gmagick
|
10 |
-
sudo service apache2 restart
|
11 |
-
```
|
12 |
-
Note: For some reason this disables the imagick extension. It seems they cannot both be installed at the same time.
|
13 |
-
|
14 |
-
|
15 |
-
## Ubuntu 18.04, using *PECL*
|
16 |
-
In Ubuntu 18.04, you will not have to do any special steps in order to compile with webp :)
|
17 |
-
|
18 |
-
1. Find out which version of PHP you are using and the location of the relevant php.ini file. Both of these can be obtained with `phpinfo();`
|
19 |
-
2. Find out which is the latest version of *gmagick* on pecl. https://pecl.php.net/package/gmagick
|
20 |
-
3. Do the following - but alter to use the info you just collected
|
21 |
-
|
22 |
-
```
|
23 |
-
sudo apt-get update
|
24 |
-
sudo apt-get install graphicsmagick gcc libgraphicsmagick1-dev php-pear php7.2-dev
|
25 |
-
sudo pecl install gmagick-2.0.5RC1
|
26 |
-
sudo echo "extension=gmagick.so" >> /etc/php/7.2/apache2/php.ini
|
27 |
-
sudo service apache2 restart
|
28 |
-
```
|
29 |
-
|
30 |
-
Notes:
|
31 |
-
- The php-pear contains *pecl*.
|
32 |
-
- *php7.2-dev* provides *phpize*, which is needed by pecl. Use *php7.1-dev*, if you are on PHP 7.1
|
33 |
-
- We do not simply do a `pecl install gmagick` because the latest package is in beta, and pecl would not allow. You should however be able to do *pecl install gmagick-beta*, which should install the latest beta.
|
34 |
-
- If you are on *fpm*, remember to restart that as well (ie `sudo service php7.2-fpm restart`)
|
35 |
-
|
36 |
-
## Plesk
|
37 |
-
https://support.plesk.com/hc/en-us/articles/115003511013-How-to-install-Gmagick-PHP-extension-on-Ubuntu-Debian-
|
38 |
-
|
39 |
-
## From source
|
40 |
-
https://duntuk.com/how-install-graphicsmagick-gmagick-php-extension
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vendor/rosell-dk/webp-convert/docs/v2.0/installing-converters/imagick-extension.md
DELETED
@@ -1,80 +0,0 @@
|
|
1 |
-
# Installing Imagick extension with WebP support
|
2 |
-
|
3 |
-
## MX-19.4
|
4 |
-
I succeeded by simply doing the following after installing imagemagick, libwebp and libwebp-dev:
|
5 |
-
```
|
6 |
-
sudo apt install php-imagick
|
7 |
-
sudo service apache2 restart
|
8 |
-
```
|
9 |
-
|
10 |
-
## Ubuntu 16.04
|
11 |
-
In order to get imagick with WebP on Ubuntu 16.04, you (currently) need to:
|
12 |
-
1. [Compile libwebp from source](https://developers.google.com/speed/webp/docs/compiling)
|
13 |
-
2. [Compile imagemagick from source](https://www.imagemagick.org/script/install-source.php) (```./configure --with-webp=yes```)
|
14 |
-
3. Compile php-imagick from source, phpize it and add ```extension=/path/to/imagick.so``` to php.ini
|
15 |
-
|
16 |
-
## Ubuntu 18.04 (from source)
|
17 |
-
A simple `sudo apt-get install php-imagick` unfortunately does not give you webp support.
|
18 |
-
Again, you must:
|
19 |
-
|
20 |
-
### 1. Compile libwebp from source
|
21 |
-
Instructions are [here](https://developers.google.com/speed/webp/docs/compiling).
|
22 |
-
In short, you need to:
|
23 |
-
```
|
24 |
-
sudo apt-get install libjpeg-dev libpng-dev
|
25 |
-
wget https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-1.1.0.tar.gz
|
26 |
-
tar xvzf libwebp-1.1.0.tar.gz
|
27 |
-
cd into the dir
|
28 |
-
./configure
|
29 |
-
make
|
30 |
-
sudo make install
|
31 |
-
```
|
32 |
-
|
33 |
-
### 2. Compile *imagemagick* from source, configured with *webp*
|
34 |
-
See tutorial [here](https://linuxconfig.org/how-to-install-imagemagick-7-on-ubuntu-18-04-linux), but configure with *webp* (`./configure --with-webp=yes`)
|
35 |
-
|
36 |
-
```
|
37 |
-
sudo apt-get update
|
38 |
-
sudo apt build-dep imagemagick
|
39 |
-
wget https://imagemagick.org/download/ImageMagick.tar.gz
|
40 |
-
tar xvzf ImageMagick.tar.gz
|
41 |
-
cd into the dir
|
42 |
-
./configure --with-webp=yes
|
43 |
-
sudo make
|
44 |
-
sudo make install
|
45 |
-
sudo ldconfig /usr/local/lib
|
46 |
-
sudo identify -version # to check if installed ok
|
47 |
-
make check # optional run in-depth check
|
48 |
-
```
|
49 |
-
Check it this way: `identify -list format | grep WEBP`
|
50 |
-
- It should print a line
|
51 |
-
|
52 |
-
### 3a. Install extension with pecl
|
53 |
-
First find out which version of PHP you are using and the location of the relevant *php.ini* file. Both of these can be obtained with `phpinfo();`. Next do the following (but alter to use the info you just collected):
|
54 |
-
|
55 |
-
```
|
56 |
-
sudo apt-get update
|
57 |
-
sudo apt-get install imagemagick gcc libmagickwand-dev php-pear php7.2-dev
|
58 |
-
sudo pecl install imagick
|
59 |
-
sudo echo "extension=imagick.so" >> /etc/php/7.2/apache2/php.ini
|
60 |
-
sudo service apache2 restart
|
61 |
-
```
|
62 |
-
Related:
|
63 |
-
https://askubuntu.com/questions/769396/how-to-install-imagemagick-for-php7-on-ubuntu-16-04
|
64 |
-
|
65 |
-
|
66 |
-
### 3b. Alternively to using pecl, compile php-imagick from source
|
67 |
-
https://github.com/mkoppanen/imagick
|
68 |
-
First find out which version of PHP you are using and the location of the relevant *php.ini* file. Both of these can be obtained with `phpinfo();`. Next do the following (but alter to use the info you just collected):
|
69 |
-
|
70 |
-
```
|
71 |
-
wget https://pecl.php.net/get/imagick-3.4.3.tgz
|
72 |
-
tar xvzf imagick-3.4.3.tgz
|
73 |
-
cd into the dir
|
74 |
-
sudo /usr/bin/phpize7.2 # note: find you version of phpize with locate phpize
|
75 |
-
./configure
|
76 |
-
make
|
77 |
-
make install
|
78 |
-
sudo echo "extension=imagick.so" >> /etc/php/7.2/apache2/php.ini
|
79 |
-
sudo service apache2 restart
|
80 |
-
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vendor/rosell-dk/webp-convert/docs/v2.0/installing-converters/vips.md
DELETED
@@ -1,35 +0,0 @@
|
|
1 |
-
# Installing vips extension
|
2 |
-
|
3 |
-
### Step 1: Install the vips library
|
4 |
-
Follow the instructions on the [vips library github page](https://github.com/libvips/libvips/)
|
5 |
-
|
6 |
-
Don't forget to install required packages before running `./configure`:
|
7 |
-
```
|
8 |
-
sudo apt-get install libglib2.0-dev pkg-config build-essential libexpat1-dev libjpeg-dev libpng-dev libwebp-dev gobject-introspection libgs-dev
|
9 |
-
```
|
10 |
-
|
11 |
-
### Step 2: Install the vips extension
|
12 |
-
|
13 |
-
```
|
14 |
-
sudo pecl install vips
|
15 |
-
```
|
16 |
-
– And add the following to the relevant php.ini:
|
17 |
-
```
|
18 |
-
extension=vips
|
19 |
-
```
|
20 |
-
|
21 |
-
(or `extension=vips.so` if you are in older PHP)
|
22 |
-
|
23 |
-
The vips extension is btw [also on github](https://github.com/libvips/php-vips-ext):
|
24 |
-
|
25 |
-
|
26 |
-
## GitHub actions workflow
|
27 |
-
As easy as adding "vips" to the extensions for `setup-php@v2`:
|
28 |
-
|
29 |
-
```yaml
|
30 |
-
- name: Setup PHP
|
31 |
-
uses: shivammathur/setup-php@v2
|
32 |
-
with:
|
33 |
-
php-version: '8.0'
|
34 |
-
extensions: vips
|
35 |
-
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vendor/rosell-dk/webp-convert/docs/v2.0/migrating-to-2.0.md
DELETED
@@ -1,73 +0,0 @@
|
|
1 |
-
convert# Migrating to 2.0
|
2 |
-
|
3 |
-
## Converting
|
4 |
-
|
5 |
-
### Changes in conversion api
|
6 |
-
While the code have been refactored quite extensively, if you have stuck to `WebPConvert::convert()` and/or `WebPConvert::convertAndServe()`, there is only a few things you need to know.
|
7 |
-
|
8 |
-
First and foremost: *`WebPConvert::convert` no longer returns a boolean indicating the result*. So, if conversion fails, an exception is thrown, no matter what the reason is. When migrating, you will probably need to remove some lines of code where you test the result.
|
9 |
-
|
10 |
-
Also, a few options has been renamed and a few option defaults has been changed.
|
11 |
-
|
12 |
-
#### The options that has been renamed are the following:
|
13 |
-
|
14 |
-
- Two converters have changed IDs and class names: The ids that are changed are: *imagickbinary* => *imagemagick* and *gmagickbinary* => *graphicsmagick*
|
15 |
-
- In *ewww*, the `key` option has been renamed to `api-key` (or [`ewww-api-key`](https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/converting/options.md#ewww-api-key))
|
16 |
-
- In *wpc*, the `url` option has been renamed to `api-url` (or [`wpc-api-url`](https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/converting/options.md#wpc-api-url))
|
17 |
-
* In *cwebp*, the [`lossless`] option is now replaced with the new `encoding` option (which is not boolean, but "lossy", "lossless" or ["auto"](https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/converting/introduction-for-converting.md#auto-selecting-between-losslesslossy-encoding))
|
18 |
-
* In *cwebp*, the [`autofilter`] option has been renamed to "auto-filter"
|
19 |
-
- In *gd*, the `skip-pngs` option has been removed and replaced with the general `skip` option and prefixing. So `gd-skip` amounts to the same thing, but notice that Gd no longer skips per default.
|
20 |
-
|
21 |
-
#### The option defaults that has been changed are the following:
|
22 |
-
- the `converters` default now includes the cloud converters (*ewww* and *wpc*) and also two new converters, *vips* and *graphicsmagick*. So it is not necessary to add *ewww* or *wpc* explicitly. Also, when you set options with `converter-options` and point to a converter that isn't in the stack, in 1.3.9, this resulted in the converter automatically being added. This behavior has been removed.
|
23 |
-
- *gd* no longer skips pngs per default. To make it skip pngs, set `gd-skip` to *true*
|
24 |
-
- Default quality is now 75 for jpegs and 85 for pngs (it was 75 for both)
|
25 |
-
- For *cwebp*, the `lossless` has been removed. Use the new `encoding` option instead.
|
26 |
-
- For *wpc*, default `secret` and `api-key` are now "" (they were "my dog is white")
|
27 |
-
|
28 |
-
### New convert options
|
29 |
-
You might also be interested in the new options available in 2.0:
|
30 |
-
|
31 |
-
- Added a syntax for conveniently targeting specific converters. If you for example prefix the "quality" option with "gd-", it will override the "quality" option, but only for gd.
|
32 |
-
- Certain options can now be set with environment variables too ("EWWW_API_KEY", "WPC_API_KEY" and "WPC_API_URL")
|
33 |
-
- Added new *vips* converter.
|
34 |
-
- Added new *graphicsmagick* converter.
|
35 |
-
- Added new *stack* converter (the stack functionality has been moved into a converter)
|
36 |
-
- Added [`jpeg`](https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/converting/options.md#jpeg) and [`png`](https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/converting/options.md#png) options
|
37 |
-
- Added [`alpha-quality`](https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/converting/options.md#alpha-quality) option for *cwebp*, *vips*, *imagick*, *imagemagick* and *graphicsmagick*.
|
38 |
-
- Added [`auto-filter`](https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/converting/options.md#autofilter) option for *cwebp*, *imagick*, *imagemagick* and the new *vips* converter.
|
39 |
-
- Added [`encoding`](https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/converting/options.md#encoding) option (lossy | lossless | auto). lossless and auto is supported for *cwebp*, *imagick*, *imagemagick*, *graphicsmagick* and the new *vips* converter.
|
40 |
-
- Added [`near-lossless`](https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/converting/options.md#near-lossless) option for *cwebp* and *imagemagick*.
|
41 |
-
- Added [`preset`](https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/converting/options.md#preset) option for *cwebp* and the new *vips* converter.
|
42 |
-
- Added [`skip`](https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/converting/options.md#skip) option (its general and works for all converters)
|
43 |
-
- Besides the ones mentioned above, *imagemagick* now also supports [`low-memory`](https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/converting/options.md#low-memory), [`metadata`](https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/converting/options.md#metadata) ("all" or "none") and [`method`](https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/converting/options.md#method). *imagemagick* has become very potent!
|
44 |
-
|
45 |
-
## Serving
|
46 |
-
The classes for serving has also been refactored quite extensively, but again, if you have stuck to `WebPConvert::convertAndServe`, there is only a few things you need to know.
|
47 |
-
|
48 |
-
First and foremost, *`WebPConvert::convertAndServe` has been renamed to `WebPConvert::serveConverted()`*. The reason for this change is that it more accurately describes what is happening: A converted file is served. The old name implied that a conversion was always going on, which is not the case (if the file at destination already exists, which is not bigger or older than the source, that file is served directly).
|
49 |
-
|
50 |
-
Besides this, there is the following changes in options:
|
51 |
-
|
52 |
-
- A new option `convert` has been created for supplying the conversion options. So the conversion options are no longer "mingled" with the serving options, but has its own option.
|
53 |
-
- Options regarding serving the image are now organized into its own `serve-image` setting, which again has been reorganized.
|
54 |
-
- A new option `serve-image > headers > cache-control` controls whether to set cache control header (default: false).
|
55 |
-
- The `fail` option no longer support the "report-as-image" value. It however supports a new value: "throw".
|
56 |
-
- The `fail-when-original-unavailable` option has been renamed to `fail-when-fail-fails`. In 2.0, the original not being available is no longer the only thing that can cause the fail action to fail – the library now checks the mime type of the source file and only serves it if it is either png or jpeg.
|
57 |
-
- The `error-reporting` option has been removed. The reason for it being removed is that it is considered bad practice for a library to mess with error handling. However, *this pushes the responsibility to you*. You should make sure that no warnings ends up in the output, as this will corrupt the image being served. You can for example ensure that by calling `ini_set('display_errors', '0');` or `error_reporting(0);` (or both), or by creating your own error handler.
|
58 |
-
- The `aboutToServeImageCallBack` option has been removed. You can instead extend the `ServeConvertedWebP` class and override `serveOriginal` and `serveDestination`. You can call the serve method of your extended class, but then you will not have the error handling (the `fail` and `fail-if-fail-fails` options). Too add this, you can call `ServeConvertedWebPWithErrorHandling::serve` and make sure to override the default of the last argument.
|
59 |
-
- The `aboutToPerformFailAction` option has been removed. You can instead set `fail` to `throw` and handle the exception in a *catch* clause. Or you can extend the `ServeConvertedWebPWithErrorHandling` class and override the `performFailAction` method.
|
60 |
-
- The `add-x-header-status` and `add-x-header-options` options have been removed.
|
61 |
-
- The `require-for-conversion` option has been removed. You must either use with composer or create a simple autoloader (see next section)
|
62 |
-
|
63 |
-
## WebP On demand
|
64 |
-
If you are using the "non-composer" version of webp demand (the one where you only upload two files - `webp-on-demand-1.inc` and `webp-on-demand-2.inc`), you were probably using the `require-for-conversion` option. This option is no longer supported. But you never really needed it in the first place, because the you create and register an autoloader instead:
|
65 |
-
|
66 |
-
```php
|
67 |
-
function autoloader($class) {
|
68 |
-
if (strpos($class, 'WebPConvert\\') === 0) {
|
69 |
-
require_once __DIR__ . '/webp-on-demand-2.inc';
|
70 |
-
}
|
71 |
-
}
|
72 |
-
spl_autoload_register('autoloader', true, true);
|
73 |
-
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vendor/rosell-dk/webp-convert/docs/v2.0/serving/introduction-for-serving.md
DELETED
@@ -1,157 +0,0 @@
|
|
1 |
-
# Introduction to serving converted WebP files with WebPConvert
|
2 |
-
|
3 |
-
**NOTE: This document only applies to the upcoming 2.0 version**
|
4 |
-
|
5 |
-
The classes for serving first and foremost helps you handle the cached files intelligently (not serving them if they are larger or older than the original). It also provides a convenient way to deal with conversion failures and setting headers.
|
6 |
-
|
7 |
-
|
8 |
-
In the following example, all available *serve* options are explicitly set to their default values.
|
9 |
-
|
10 |
-
```php
|
11 |
-
use WebPConvert\WebPConvert;
|
12 |
-
|
13 |
-
WebPConvert::serveConverted($source, $destination, [
|
14 |
-
|
15 |
-
// failure handling
|
16 |
-
'fail' => 'original', // ('original' | 404' | 'throw' | 'report')
|
17 |
-
'fail-when-fail-fails' => 'throw', // ('original' | 404' | 'throw' | 'report')
|
18 |
-
|
19 |
-
// options influencing the decision process of what to be served
|
20 |
-
'reconvert' => false, // if true, existing (cached) image will be discarded
|
21 |
-
'serve-original' => false, // if true, the original image will be served rather than the converted
|
22 |
-
'show-report' => false, // if true, a report will be output rather than the raw image
|
23 |
-
|
24 |
-
// warning handling
|
25 |
-
'suppress-warnings' => true, // if you set to false, make sure that warnings are not echoed out!
|
26 |
-
|
27 |
-
// options when serving an image (be it the webp or the original, if the original is smaller than the webp)
|
28 |
-
'serve-image' => [
|
29 |
-
'headers' => [
|
30 |
-
'cache-control' => true,
|
31 |
-
'content-length' => true,
|
32 |
-
'content-type' => true,
|
33 |
-
'expires' => false,
|
34 |
-
'last-modified' => true,
|
35 |
-
'vary-accept' => false
|
36 |
-
],
|
37 |
-
'cache-control-header' => 'public, max-age=31536000',
|
38 |
-
],
|
39 |
-
|
40 |
-
// redirect tweak
|
41 |
-
'redirect-to-self-instead-of-serving' => false, // if true, a redirect will be issues rather than serving
|
42 |
-
|
43 |
-
'convert' => [
|
44 |
-
// options for converting goes here
|
45 |
-
'quality' => 'auto',
|
46 |
-
]
|
47 |
-
]);
|
48 |
-
```
|
49 |
-
|
50 |
-
## Failure handling
|
51 |
-
The `fail` option gives you an easy way to handle errors. Setting it to 'original' tells it to handle errors by serving the original file instead (*$source*). This could be a good choice on production servers. On development servers, 'throw' might be a good option. It simply rethrows the exception that was thrown by *WebPConvert::convert()*. '404' could also be an option, but it has the weakness that it will probably only be discovered by real persons seeing a missing image.
|
52 |
-
|
53 |
-
The fail action might fail too. For example, if it is set to 'original' and the failure is that the original file doesn't exist. Or, more delicately, it may have a wrong mime type - our serve method will not let itself be tricked into serving *exe* files as the 'original'. Anyway, you can control what to do when fail fails using the *fail-when-fail-fails* option. If that fails too, the original exception is thrown. The fun stops there, there is no "fail-when-fail-when-fail-fails" option to customize this.
|
54 |
-
|
55 |
-
The failure handling is implemented as an extra layer. You can bypass it by calling `WebPConvert\Serve\ServeConvertedWebP::serve()` directly. Doing that will give the same result as if you set `fail` to 'throw'.
|
56 |
-
|
57 |
-
## Options influencing the decision process
|
58 |
-
The default process is like this:
|
59 |
-
|
60 |
-
1. Is there a file at the destination? If not, trigger conversion
|
61 |
-
2. Is the destination older than the source? If yes, delete destination and trigger conversion
|
62 |
-
3. Serve the smallest file (destination or source)
|
63 |
-
|
64 |
-
You can influence the process with the following options:
|
65 |
-
|
66 |
-
*reconvert*
|
67 |
-
If you set *reconvert* to true, the destination and conversion is triggered (between step 1 and 2)
|
68 |
-
|
69 |
-
*serve-original*
|
70 |
-
If you set *serve-original* to true, process will take its cause from (1) to (2) and then end with source being served.
|
71 |
-
|
72 |
-
*show-report*
|
73 |
-
If you set `show-report`, the process is skipped entirely, and instead a report is generated of how a fresh conversion using the supplied options goes.
|
74 |
-
|
75 |
-
## Headers
|
76 |
-
Leaving errors and reports out of account for a moment, the *WebPConvert::serveConverted()* ultimately has two possible outcomes: Either a converted image is served or - if smaller - the source image. If the source is to be served, its mime type will be detected in order to make sure it is an image and to be able to set the content type header. Either way, the actual serving is passed to `Serve\ServeFile::serve`. The main purpose of this class is to add/set headers.
|
77 |
-
|
78 |
-
#### *Cache-Control* and *Expires* headers
|
79 |
-
Default behavior is to neither set the *Cache-Control* nor the *Expires* header. Once you are on production, you will probably want to turn these on. The default is btw one year (31536000 seconds). I recommend the following for production:
|
80 |
-
|
81 |
-
```
|
82 |
-
'serve-image' => [
|
83 |
-
'headers' => [
|
84 |
-
'cache-control' => true,
|
85 |
-
'expires' => false,
|
86 |
-
],
|
87 |
-
'cache-control-header' => 'public, max-age=31536000',
|
88 |
-
],
|
89 |
-
```
|
90 |
-
|
91 |
-
The value for the *Expires* header is calculated from "max-age" found in the *cache-control-header* option and the time of the request. The result is an absolute time, ie "Expires: Thu, 07 May 2020 07:02:37 GMT". As most browsers now supports the *Cache-Control* header, *from a performance perspective*, there is no need to also add the expires header. However, some tools complains if you don't (gtmetrix allegedly), and there is no harm in adding both headers. More on this discussion [[here]](https://github.com/rosell-dk/webp-convert/issues/126).
|
92 |
-
|
93 |
-
#### *Vary: Accept* header
|
94 |
-
This library can be used as part of a solution that serves webp files to browsers that supports it, while serving the original file to browsers that does not *on the same URL*. Such a solution typically inspects the *Accept* request header in order to determine if the client supports webp or not. Thus, the response will *vary* along with the "Accept" header and the world (and proxies) should be informed about this, so they don't end up serving cached webps to browsers that does not support it. To add the "Vary: Accept" header, simply set the *serve-image > headers > vary-accept* option to true.
|
95 |
-
|
96 |
-
#### *Last-Modified* header
|
97 |
-
The Last-Modified header is also used for caching purposes. You should leave that setting on, unless you set it by other means. You control it with the *serve-image > headers > last-modified* option.
|
98 |
-
|
99 |
-
#### *Content-Type* header
|
100 |
-
The *Content-Type* header tells browsers what they are receiving. This is important information and you should leave the *serve-image > headers > content-type* option at its default (true), unless you set it by other means.
|
101 |
-
|
102 |
-
When the outcome is to serve a webp, the header will be set to: "Content-Type: image/webp". When the original is to be served, the library will try to detect the mime type of the file and set the content type accordingly. The [image-mime-type-guesser](https://github.com/rosell-dk/image-mime-type-guesser) library is used for that.
|
103 |
-
|
104 |
-
#### *Content-Length* header
|
105 |
-
The *Content-Length* header tells browsers the length of the content. According to [the specs](https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.13), it should be set unless it is prohibited by rules in [section 4.4](https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.4). In that section we learn that it should not be set when the *Transfer-Encoding* header is set (which it often is, to "chunked"). However, no harm done, because it also says that clients should ignore the header in case *Transfer-Encoding* is set. From this I concluded that it makes sense to default the *serve-image > headers > content-length* to true. I might however change this in case I should learn that the header could be problematic in some way. So if you decided you want it, do not rely on the default, but set it to *true*. See discussion on this subject [here](https://stackoverflow.com/questions/3854842/content-length-header-with-head-requests/3854983#3854983).
|
106 |
-
|
107 |
-
#### *X-WebP-Convert-Log* headers
|
108 |
-
The serve method adds *X-WebP-Convert-Log* headers in order to let you know what went on.
|
109 |
-
For example, if there is no converted image and conversion was successful, the following headers will be sent:
|
110 |
-
|
111 |
-
```
|
112 |
-
X-WebP-Convert-Log: Converting (there were no file at destination)
|
113 |
-
X-WebP-Convert-Log: Serving converted file
|
114 |
-
```
|
115 |
-
|
116 |
-
On the next call (presuming the webp has not been deleted), no conversion is needed and you should simply see:
|
117 |
-
```
|
118 |
-
X-WebP-Convert-Log: Serving converted file
|
119 |
-
```
|
120 |
-
|
121 |
-
But say that the first conversion actually failed. In case you have permission problems, the output could be:
|
122 |
-
```
|
123 |
-
X-WebP-Convert-Log: Converting (there were no file at destination)
|
124 |
-
X-WebP-Convert-Log: Failed creating folder. Check the permissions!
|
125 |
-
X-WebP-Convert-Log: Performing fail action: original
|
126 |
-
```
|
127 |
-
|
128 |
-
In case the problem is that the conversion failed, you could see the following:
|
129 |
-
```
|
130 |
-
X-WebP-Convert-Log: Converting (there were no file at destination)
|
131 |
-
X-WebP-Convert-Log: None of the converters in the stack are operational
|
132 |
-
X-WebP-Convert-Log: Performing fail action: original
|
133 |
-
```
|
134 |
-
|
135 |
-
If you need more info about the conversion process in order to learn why the converters aren't working, enable the *show-report* option.
|
136 |
-
|
137 |
-
As a last example, say you have supplied a non-existing file as source and `fail` is set to "original" (which will also fail). Result:
|
138 |
-
```
|
139 |
-
X-WebP-Convert-Log: Source file was not found
|
140 |
-
X-WebP-Convert-Log: Performing fail action: original
|
141 |
-
X-WebP-Convert-Log: Performing fail action: throw
|
142 |
-
```
|
143 |
-
|
144 |
-
## The redirect tweak (will be available in 2.3.0)
|
145 |
-
There are cases where serving the image directly with PHP isn't optimal.
|
146 |
-
|
147 |
-
One case is WP Engine. Even though webp-convert adds a Vary:Accept header, the header is not present in the response on WP Engine. It is somehow overwritten by the caching machinery and set to Vary:Accept-Encoding, Cookie.
|
148 |
-
|
149 |
-
If however rules have been set up to redirect images directly to existing webps, one can overcome the problem by redirecting the image request back to itself rather than serving the webp directly.
|
150 |
-
|
151 |
-
You can achieve this by setting the *redirect-to-self-instead-of-serving* option to true.
|
152 |
-
|
153 |
-
Beware of risk of an endless redirect loop. Such loop will happen if the redirection to existing webp rules aren't set up correctly. To prevent this, it is recommended that you only set the option to true after checking that the destination file does not exist. But note that this check does not completely prevent such loops occurring when redirection to existing rules are missing - as the 302 redirect could get cached (it does that on WP Engine). So bottom line: Only use this feature when you have server rules set up for redirecting images to their corresponding webp images (for client that supports webp) - *and you are certain that these rules works*.
|
154 |
-
|
155 |
-
## More info
|
156 |
-
|
157 |
-
- The complete api is available [here](https://www.bitwise-it.dk/webp-convert/api/2.0/html/index.xhtml)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vendor/rosell-dk/webp-convert/docs/v2.0/serving/laravel-nginx-serving.md
DELETED
@@ -1,116 +0,0 @@
|
|
1 |
-
# Serving WebP from a Laravel Nginx site
|
2 |
-
|
3 |
-
**NOTE: This document only applies to the upcoming 2.0 version**
|
4 |
-
|
5 |
-
This should work with most php sites although I'm basing the Nginx configuration around what's commonly seen with Laravel installations.
|
6 |
-
|
7 |
-
Create webp converter script in ```project_root/public/webp-on-demand.php```
|
8 |
-
|
9 |
-
```
|
10 |
-
<?php
|
11 |
-
|
12 |
-
require '../vendor/autoload.php';
|
13 |
-
|
14 |
-
use WebPConvert\WebPConvert;
|
15 |
-
|
16 |
-
$source = __DIR__ . $_GET['source'];
|
17 |
-
$destination = $source . '.webp';
|
18 |
-
|
19 |
-
WebPConvert::serveConverted($source, $destination, [
|
20 |
-
'fail' => 'original', // If failure, serve the original image (source). Other options include 'throw', '404' and 'report'
|
21 |
-
// 'show-report' => true, // Generates a report instead of serving an image
|
22 |
-
|
23 |
-
'serve-image' => [
|
24 |
-
'headers' => [
|
25 |
-
'cache-control' => true,
|
26 |
-
'vary-accept' => true,
|
27 |
-
// other headers can be toggled...
|
28 |
-
],
|
29 |
-
'cache-control-header' => 'max-age=2',
|
30 |
-
],
|
31 |
-
|
32 |
-
'convert' => [
|
33 |
-
// all convert option can be entered here (ie "quality")
|
34 |
-
],
|
35 |
-
]);
|
36 |
-
|
37 |
-
```
|
38 |
-
|
39 |
-
|
40 |
-
### Configure Nginx
|
41 |
-
|
42 |
-
We just need to add the following block to our site in ```/etc/sites-enabled/```
|
43 |
-
|
44 |
-
```
|
45 |
-
location ~* ^/.*\.(png|jpe?g)$ {
|
46 |
-
add_header Vary Accept;
|
47 |
-
expires 365d;
|
48 |
-
if ($http_accept !~* "webp"){
|
49 |
-
break;
|
50 |
-
}
|
51 |
-
try_files
|
52 |
-
$uri.webp
|
53 |
-
/webp-on-demand.php?source=$uri
|
54 |
-
;
|
55 |
-
}
|
56 |
-
```
|
57 |
-
|
58 |
-
Then reload Nginx ```sudo systemctl restart nginx```
|
59 |
-
|
60 |
-
The full Nginx block should look like
|
61 |
-
|
62 |
-
```
|
63 |
-
server {
|
64 |
-
server_name webp-testing.com;
|
65 |
-
root /home/forge/webp-testing.com/public;
|
66 |
-
|
67 |
-
index index.html index.htm index.php;
|
68 |
-
|
69 |
-
charset utf-8;
|
70 |
-
|
71 |
-
location / {
|
72 |
-
try_files $uri $uri/ /index.php?$query_string;
|
73 |
-
}
|
74 |
-
|
75 |
-
location ~* ^/.*\.(png|jpe?g)$ {
|
76 |
-
add_header Vary Accept;
|
77 |
-
expires 365d;
|
78 |
-
if ($http_accept !~* "webp"){
|
79 |
-
break;
|
80 |
-
}
|
81 |
-
try_files
|
82 |
-
$uri.webp
|
83 |
-
/webp-on-demand.php?source=$uri
|
84 |
-
;
|
85 |
-
}
|
86 |
-
|
87 |
-
location = /favicon.ico { access_log off; log_not_found off; }
|
88 |
-
location = /robots.txt { access_log off; log_not_found off; }
|
89 |
-
|
90 |
-
access_log off;
|
91 |
-
error_log /var/log/nginx/webp-testing.com-error.log error;
|
92 |
-
|
93 |
-
error_page 404 /index.php;
|
94 |
-
|
95 |
-
location ~ \.php$ {
|
96 |
-
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
97 |
-
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
|
98 |
-
fastcgi_index index.php;
|
99 |
-
include fastcgi_params;
|
100 |
-
}
|
101 |
-
|
102 |
-
location ~ /\.(?!well-known).* {
|
103 |
-
deny all;
|
104 |
-
}
|
105 |
-
|
106 |
-
# cache static assets
|
107 |
-
location ~* \.(gif|ico|css|pdf|svg)$ {
|
108 |
-
expires 365d;
|
109 |
-
}
|
110 |
-
|
111 |
-
location ~* \.(js)$ {
|
112 |
-
add_header Cache-Control no-cache;
|
113 |
-
}
|
114 |
-
|
115 |
-
}
|
116 |
-
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vendor/rosell-dk/webp-convert/docs/v2.0/webp-on-demand/tweaks.md
DELETED
@@ -1,181 +0,0 @@
|
|
1 |
-
# Tweaks
|
2 |
-
|
3 |
-
## Store converted images in separate folder
|
4 |
-
|
5 |
-
In most cases, you probably want the cache of converted images to be stored in their own folder rather than have them mingled with the source files.
|
6 |
-
|
7 |
-
To have have the cache folder contain a file structure mirroring the structure of the original files, you can do this:
|
8 |
-
|
9 |
-
```php
|
10 |
-
$applicationRoot = $_SERVER["DOCUMENT_ROOT"]; // If your application is not in document root, you can change accordingly.
|
11 |
-
$imageRoot = $applicationRoot . '/webp-images'; // Change to where you want the webp images to be saved
|
12 |
-
$sourceRel = substr($source, strlen($applicationRoot));
|
13 |
-
$destination = $imageRoot . $sourceRel . '.webp';
|
14 |
-
```
|
15 |
-
|
16 |
-
If your images are stored outside document root (a rare case), you can simply use the complete absolute path:
|
17 |
-
```php
|
18 |
-
$destination = $imageRoot . $source . '.webp'; // pst: $source is an absolute path, and starts with '/'
|
19 |
-
```
|
20 |
-
This will ie store a converted image in */var/www/example.com/public_html/app/webp-images/var/www/example.com/images/logo.jpg.webp*
|
21 |
-
|
22 |
-
If your application can be configured to store outside document root, but rarely is, you can go for this structure:
|
23 |
-
|
24 |
-
```php
|
25 |
-
$docRoot = $_SERVER["DOCUMENT_ROOT"];
|
26 |
-
$imageRoot = $contentDirAbs . '/webp-images';
|
27 |
-
|
28 |
-
if (substr($source, 0, strlen($docRoot)) === $docRoot) {
|
29 |
-
// Source file is residing inside document root.
|
30 |
-
// We can store relative to that.
|
31 |
-
$sourceRel = substr($source, strlen($docRoot));
|
32 |
-
$destination = $imageRoot . '/doc-root' . $sourceRel . '.webp';
|
33 |
-
} else {
|
34 |
-
// Source file is residing outside document root.
|
35 |
-
// we must add complete path to structure
|
36 |
-
$destination = $imageRoot . '/abs' . $source . '.webp';
|
37 |
-
}
|
38 |
-
```
|
39 |
-
|
40 |
-
If you do not know the application root beforehand, and thus do not know the appropriate root for the converted images, see next tweak.
|
41 |
-
|
42 |
-
|
43 |
-
## Get the application root automatically
|
44 |
-
When you want destination files to be put in their own folder, you need to know the root of the application (the folder in which the .htaccess rules resides). In most applications, you know the root. In many cases, it is simply the document root. However, if you are writing an extension, plugin or module to a framework that can be installed in a subfolder, you may have trouble finding it. Many applications have a *index.php* in the root, which can get it with `__DIR__`. However, you do not want to run an entire bootstrap each time you serve an image. Obviously, to get around this, you can place *webp-on-demand.php* in the webroot. However, some frameworks, such as Wordpress, will not allow a plugin to put a file in the root. Now, how could we determine the application root from a file inside some subdir? Here are three suggestions:
|
45 |
-
|
46 |
-
1. You could traverse parent folders until you find a file you expect to be in application root (ie a .htaccess containing the string "webp-on-demand.php"). This should work.
|
47 |
-
2. If the rules in the *.htaccess* file are generated by your application, you probably have access to the path at generation time. You can then simply put the path in the *.htaccess*, as an extra parameter to the script (or better: the relative path from document root to the application).
|
48 |
-
3. You can use the following hack:
|
49 |
-
|
50 |
-
### The hack
|
51 |
-
The idea is to grab the URL path of the image in the *.htaccess* and pass it to the script. Assuming that the URL paths always matches the file paths, we can get the application root by subtracting that relative path to source from the absolute path to source.
|
52 |
-
|
53 |
-
In *.htaccess*, we grab the url-path by appending "&url-path=$1.$2" to the rewrite rule:
|
54 |
-
```
|
55 |
-
RewriteRule ^(.*)\.(jpe?g|png)$ webp-on-demand.php?source=%{SCRIPT_FILENAME}&url-path=$1.$2 [NC,L]
|
56 |
-
```
|
57 |
-
|
58 |
-
In the script, we can then calculate the application root like this:
|
59 |
-
|
60 |
-
```php
|
61 |
-
$applicationRoot = substr($_GET['source'], 0, -strlen($_GET['url-path']));
|
62 |
-
```
|
63 |
-
|
64 |
-
## CDN
|
65 |
-
To work properly with a CDN, a "Vary Accept" header should be added when serving images. This is a declaration that the response varies with the *Accept* header (recall that we inspect *Accept* header in the .htaccess to determine if the browsers supports webp images). If this header is missing, the CDN will see no reason to cache separate images depending on the Accept header.
|
66 |
-
|
67 |
-
Add this snippet to the *.htaccess* to make webp-on-demand work with CDN's:
|
68 |
-
|
69 |
-
```
|
70 |
-
<IfModule mod_headers.c>
|
71 |
-
SetEnvIf Request_URI "\.(jpe?g|png)" ADDVARY
|
72 |
-
|
73 |
-
# Declare that the response varies depending on the accept header.
|
74 |
-
# The purpose is to make CDN cache both original images and converted images.
|
75 |
-
Header append "Vary" "Accept" env=ADDVARY
|
76 |
-
</IfModule>
|
77 |
-
```
|
78 |
-
|
79 |
-
***Note:*** When configuring the CDN, you must make sure to set it up to forward the the "Accept" header to your origin server.
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
## Make .htaccess route directly to existing images
|
84 |
-
|
85 |
-
There may be a performance benefit of using the *.htaccess* file to route to already converted images, instead of letting the PHP script serve it. Note however:
|
86 |
-
- If you do the routing in .htaccess, the solution will not be able to discard converted images when original images are updated.
|
87 |
-
- Performance benefit may be insignificant (*WebPConvertAndServe* class is not autoloaded when serving existing images)
|
88 |
-
|
89 |
-
Add the following to the *.htaccess* to make it route to existing converted images. Place it above the # Redirect images to webp-on-demand.php" comment. Take care of replacing [[your-base-path]] with the directory your *.htaccess* lives in (relative to document root, and [[your-destination-root]] with the directory the converted images resides.
|
90 |
-
```
|
91 |
-
# Redirect to existing converted image (under appropriate circumstances)
|
92 |
-
RewriteCond %{HTTP_ACCEPT} image/webp
|
93 |
-
RewriteCond %{DOCUMENT_ROOT}/[[your-base-path]]/[[your-destination-root]]/$1.$2.webp -f
|
94 |
-
RewriteRule ^\/?(.*)\.(jpe?g|png)$ /[[your-base-path]]/[[your-destination-root]]/$1.$2.webp [NC,T=image/webp,L]
|
95 |
-
```
|
96 |
-
*edit:* Removed the QSD flag from the RewriteRule because it is not supported in Apache < 2.4 (and it [triggers error](https://github.com/rosell-dk/webp-express/issues/155))
|
97 |
-
|
98 |
-
Note however that DOCUMENT_ROOT can be unreliable.
|
99 |
-
|
100 |
-
If you store the webp images in the same folder as the originals and append ".webp" (rather than replace the file extension), you can do this instead:
|
101 |
-
|
102 |
-
```
|
103 |
-
# Redirect to existing converted image (under appropriate circumstances)
|
104 |
-
RewriteCond %{HTTP_ACCEPT} image/webp
|
105 |
-
RewriteCond %{REQUEST_FILENAME}.webp -f
|
106 |
-
RewriteRule ^/?(.+)\.(jpe?g|png)$ $1.$2.webp [T=image/webp,L]
|
107 |
-
```
|
108 |
-
|
109 |
-
|
110 |
-
RewriteCond %{REQUEST_FILENAME}.webp -f
|
111 |
-
|
112 |
-
### Redirect with CDN support
|
113 |
-
If you are using a CDN, and want to redirect to existing images with the .htaccess, it is a good idea to add a "Vary Accept" header. This instructs the CDN that the response varies with the *Accept* header (we do not need to do that when routing to webp-on-demand.php, because the script takes care of adding this header, when appropriate.)
|
114 |
-
|
115 |
-
You can achieve redirect with CDN support with the following rules:
|
116 |
-
```
|
117 |
-
<IfModule mod_rewrite.c>
|
118 |
-
|
119 |
-
RewriteEngine On
|
120 |
-
|
121 |
-
# Redirect to existing converted image (under appropriate circumstances)
|
122 |
-
RewriteCond %{HTTP_ACCEPT} image/webp
|
123 |
-
RewriteCond %{DOCUMENT_ROOT}/[[your-base-path]]/[[your-destination-root]]/$1.$2.webp -f
|
124 |
-
RewriteRule ^\/?(.*)\.(jpe?g|png)$ /[[your-base-path]]/[[your-destination-root]]/$1.$2.webp [NC,T=image/webp,QSD,E=WEBPACCEPT:1,L]
|
125 |
-
|
126 |
-
# Redirect images to webp-on-demand.php (if browser supports webp)
|
127 |
-
RewriteCond %{HTTP_ACCEPT} image/webp
|
128 |
-
RewriteRule ^(.*)\.(jpe?g|png)$ webp-on-demand.php?source=%{SCRIPT_FILENAME}&url-path=$1.$2 [NC,L]
|
129 |
-
|
130 |
-
</IfModule>
|
131 |
-
|
132 |
-
<IfModule mod_headers.c>
|
133 |
-
# Apache appends "REDIRECT_" in front of the environment variables, but LiteSpeed does not.
|
134 |
-
# These next line is for Apache, in order to set environment variables without "REDIRECT_"
|
135 |
-
SetEnvIf REDIRECT_WEBPACCEPT 1 WEBPACCEPT=1
|
136 |
-
|
137 |
-
# Make CDN caching possible.
|
138 |
-
# The effect is that the CDN will cache both the webp image and the jpeg/png image and return the proper
|
139 |
-
# image to the proper clients (for this to work, make sure to set up CDN to forward the "Accept" header)
|
140 |
-
Header append Vary Accept env=WEBPACCEPT
|
141 |
-
</IfModule>
|
142 |
-
|
143 |
-
AddType image/webp .webp
|
144 |
-
```
|
145 |
-
|
146 |
-
## Forward the querystring
|
147 |
-
By forwarding the query string, you can allow control directly from the URL. You could for example make it possible to add "?debug" to an image URL, and thereby getting a conversion report. Or make "?reconvert" force reconversion.
|
148 |
-
|
149 |
-
In order to forward the query string, you need to add this condition before the RewriteRule that redirects to *webp-on-demand.php*:
|
150 |
-
```
|
151 |
-
RewriteCond %{QUERY_STRING} (.*)
|
152 |
-
```
|
153 |
-
That condition will always be met. The side effect is that it stores the match (the complete querystring). That match will be available as %1 in the RewriteRule. So, in the RewriteRule, we will have to add "&%1" after the last argument. Here is a complete solution:
|
154 |
-
```
|
155 |
-
<IfModule mod_rewrite.c>
|
156 |
-
RewriteEngine On
|
157 |
-
|
158 |
-
# Redirect images to webp-on-demand.php (if browser supports webp)
|
159 |
-
RewriteCond %{HTTP_ACCEPT} image/webp
|
160 |
-
RewriteCond %{QUERY_STRING} (.*)
|
161 |
-
RewriteRule ^(.*)\.(jpe?g|png)$ webp-on-demand.php?source=%{SCRIPT_FILENAME}&%1 [NC,L]
|
162 |
-
</IfModule>
|
163 |
-
|
164 |
-
AddType image/webp .webp
|
165 |
-
```
|
166 |
-
|
167 |
-
Of course, in order to *do* something with that querystring, you must use them in your *webp-on-demand.php* script. You could for example use them directly in the options array sent to the *convertAndServe()* method. To achieve the mentioned "debug" and "reconvert" features, do this:
|
168 |
-
```php
|
169 |
-
$options = [
|
170 |
-
'show-report' => isset($_GET['debug']),
|
171 |
-
'reconvert' => isset($_GET['reconvert']),
|
172 |
-
'serve-original' => isset($_GET['original']),
|
173 |
-
];
|
174 |
-
```
|
175 |
-
|
176 |
-
*EDIT:*
|
177 |
-
I have just discovered a simpler way to achieve the querystring forward: The [QSA flag](https://httpd.apache.org/docs/trunk/rewrite/flags.html).
|
178 |
-
So, simply set the QSA flag in the RewriteRule, and nothing more:
|
179 |
-
```
|
180 |
-
RewriteRule ^(.*)\.(jpe?g|png)$ webp-on-demand.php?source=%{SCRIPT_FILENAME} [NC,QSA,L]
|
181 |
-
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vendor/rosell-dk/webp-convert/docs/v2.0/webp-on-demand/webp-on-demand.md
DELETED
@@ -1,145 +0,0 @@
|
|
1 |
-
# WebP on demand
|
2 |
-
|
3 |
-
This is a solution for automatically serving WebP images instead of jpeg/pngs [for browsers that supports WebP](https://caniuse.com/#feat=webp) (At the time of writing, 78% of all mobile users and 72% of all desktop users uses browsers supporting webp)
|
4 |
-
|
5 |
-
Once set up, it will automatically convert images, no matter how they are referenced. It for example also works on images referenced in CSS. As the solution does not require any change in the HTML, it can easily be integrated into any website / framework
|
6 |
-
|
7 |
-
## Overview
|
8 |
-
|
9 |
-
A setup consists of a PHP script that serves converted images and some *redirect rules* that redirects JPG/PNG images to the script.
|
10 |
-
|
11 |
-
|
12 |
-
## Requirements
|
13 |
-
|
14 |
-
* *Apache* or *LiteSpeed* web server. Can be made to work with *NGINX* as well. Documentation is on the roadmap.
|
15 |
-
* *mod_rewrite* module for Apache
|
16 |
-
* PHP >= 5.6 (we are only testing down to 5.6. It should however work in 5.5 as well)
|
17 |
-
* That one of the *webp-convert* converters are working (these have different requirements)
|
18 |
-
|
19 |
-
## Installation
|
20 |
-
|
21 |
-
Here we assume you are using Composer. [Not using composer? - Follow me!](https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/webp-on-demand/without-composer.md)
|
22 |
-
|
23 |
-
### 1. Require the webp-convert library with composer
|
24 |
-
```
|
25 |
-
composer require rosell-dk/webp-convert
|
26 |
-
```
|
27 |
-
|
28 |
-
### 2. Create the script
|
29 |
-
|
30 |
-
Create a file *webp-on-demand.php*, and place it in webroot, or where-ever you like in you web-application.
|
31 |
-
|
32 |
-
Here is a minimal example to get started with:
|
33 |
-
|
34 |
-
```php
|
35 |
-
<?php
|
36 |
-
// To start with, lets display any errors.
|
37 |
-
// - this will reveal if you entered wrong paths
|
38 |
-
error_reporting(E_ALL);
|
39 |
-
ini_set("display_errors", 1);
|
40 |
-
|
41 |
-
// Once you got it working, make sure that PHP warnings are not send to the output
|
42 |
-
// - this will corrupt the image
|
43 |
-
// For example, you can do it by commenting out the lines below:
|
44 |
-
// error_reporting(0);
|
45 |
-
// ini_set("display_errors", 0);
|
46 |
-
|
47 |
-
require 'vendor/autoload.php'; // Make sure to point this correctly
|
48 |
-
|
49 |
-
use WebPConvert\WebPConvert;
|
50 |
-
|
51 |
-
$source = $_GET['source']; // Absolute file path to source file. Comes from the .htaccess
|
52 |
-
$destination = $source . '.webp'; // Store the converted images besides the original images (other options are available!)
|
53 |
-
|
54 |
-
$options = [
|
55 |
-
|
56 |
-
// UNCOMMENT NEXT LINE, WHEN YOU ARE UP AND RUNNING!
|
57 |
-
'show-report' => true // Show a conversion report instead of serving the converted image.
|
58 |
-
|
59 |
-
// More options available!
|
60 |
-
// https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/converting/introduction-for-converting.md
|
61 |
-
// https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/serving/introduction-for-serving.md
|
62 |
-
];
|
63 |
-
WebPConvert::serveConverted($source, $destination, $options);
|
64 |
-
```
|
65 |
-
|
66 |
-
### 3. Add redirect rules
|
67 |
-
Place the following rewrite rules in a *.htaccess* file in the directory where you want the solution to take effect:
|
68 |
-
|
69 |
-
```
|
70 |
-
<IfModule mod_rewrite.c>
|
71 |
-
RewriteEngine On
|
72 |
-
|
73 |
-
# Redirect images to webp-on-demand.php (if browser supports webp)
|
74 |
-
RewriteCond %{HTTP_ACCEPT} image/webp
|
75 |
-
RewriteCond %{REQUEST_FILENAME} -f
|
76 |
-
RewriteRule ^(.*)\.(jpe?g|png)$ webp-on-demand.php?source=%{SCRIPT_FILENAME} [NC,L]
|
77 |
-
</IfModule>
|
78 |
-
|
79 |
-
AddType image/webp .webp
|
80 |
-
```
|
81 |
-
If you have placed *webp-on-demand.php* in a subfolder, you will need to change the rewrite rule accordingly.
|
82 |
-
|
83 |
-
The `RewriteCond %{REQUEST_FILENAME} -f` is not strictly necessary, but there to be sure that we got an existing file, and it could perhaps also prevent some undiscovered way of misuse.
|
84 |
-
|
85 |
-
### 4. Validate that it works
|
86 |
-
|
87 |
-
Browse to a JPEG image. Instead of an image, you should see a conversion report. Hopefully, you get a success. Otherwise, you need to hook up to a cloud converter or try to meet the requirements for cwebp, gd or imagick.
|
88 |
-
|
89 |
-
Once you get a successful conversion, you can uncomment the "show-report" option in the script.
|
90 |
-
|
91 |
-
It should work now, but to be absolute sure:
|
92 |
-
|
93 |
-
- Visit a page on your site with an image on it, using *Google Chrome*.
|
94 |
-
- Right-click the page and choose "Inspect"
|
95 |
-
- Click the "Network" tab
|
96 |
-
- Reload the page
|
97 |
-
- Find a jpeg or png image in the list. In the "type" column, it should say "webp". There should also be a *X-WebP-Convert-Status* header on the image that provides some insights on how things went.
|
98 |
-
|
99 |
-
|
100 |
-
### 5. Try this improvement and see if it works
|
101 |
-
|
102 |
-
It seems that it is not necessary to pass the filename in the query string.
|
103 |
-
|
104 |
-
Try replacing `$source = $_GET['source'];` in the script with the following:
|
105 |
-
|
106 |
-
```php
|
107 |
-
$docRoot = rtrim($_SERVER["DOCUMENT_ROOT"], '/');
|
108 |
-
$requestUriNoQS = explode('?', $_SERVER['REQUEST_URI'])[0];
|
109 |
-
$source = $docRoot . urldecode($requestUriNoQS);
|
110 |
-
```
|
111 |
-
|
112 |
-
And you can then remove `?source=%{SCRIPT_FILENAME}` from the `.htaccess` file.
|
113 |
-
|
114 |
-
There are some benefits of not passing in query string:
|
115 |
-
1. Passing a path in the query string may be blocked by a firewall, as it looks suspicious.
|
116 |
-
2. The script called to convert arbitrary files
|
117 |
-
3. One person experienced problems with spaces in filenames passed in the query string. See [this issue](https://github.com/rosell-dk/webp-convert/issues/95)
|
118 |
-
|
119 |
-
|
120 |
-
### 6. Customizing and tweaking
|
121 |
-
|
122 |
-
Basic customizing is done by setting options in the `$options` array. Check out the [docs on convert()](https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/converting/convert.md) and the [docs on convertAndServe()](https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/serving/convert-and-serve.md)
|
123 |
-
|
124 |
-
Other tweaking is described in *docs/webp-on-demand/tweaks.md*:
|
125 |
-
- [Store converted images in separate folder](https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/webp-on-demand/tweaks.md#store-converted-images-in-separate-folder)
|
126 |
-
- [CDN](https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/webp-on-demand/tweaks.md#cdn)
|
127 |
-
- [Make .htaccess route directly to existing images](https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/webp-on-demand/tweaks.md#make-htaccess-route-directly-to-existing-images)
|
128 |
-
- [Forward the query string](https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/webp-on-demand/tweaks.md#forward-the-querystring)
|
129 |
-
|
130 |
-
|
131 |
-
## Troubleshooting
|
132 |
-
|
133 |
-
### The redirect rule doesn't seem to be working
|
134 |
-
If images are neither routed to the converter or a 404, it means that the redirect rule isn't taking effect. Common reasons for this includes:
|
135 |
-
|
136 |
-
- Perhaps there are other rules in your *.htaccess* that interfere with the rules?
|
137 |
-
- Perhaps your site is on *Apache*, but it has been configured to use *Nginx* to serve image files. To find out which server that is handling the images, browse to an image and eximine the "Server" response header. In case *NGINX* are serving images, see if you can reconfigure your server setup. Alternatively, you can create *NGINX* rewrite rules. There are some [here](https://github.com/S1SYPHOS/kirby-webp#nginx) and [there](https://github.com/uhop/grunt-tight-sprite/wiki/Recipe:-serve-WebP-with-nginx-conditionally).
|
138 |
-
- Perhaps the server isn't configured to allow *.htaccess* files? Try inserting rubbish in the top of the *.htaccess* file and refresh. You should now see an *Internal Server Error* error page. If you don't, your *.htaccess* file is ignored. Probably you will need to set *AllowOverride All* in your Virtual Host. [Look here for more help](
|
139 |
-
https://docs.bolt.cm/3.4/howto/making-sure-htaccess-works#test-if-htaccess-is-working)
|
140 |
-
- Perhaps the Apache *mod_rewrite* extension isn't enabled? Try removing both `<IfModule mod_rewrite.c>` and `</IfModule>` lines: if you get an *Internal Server Error* error page after this change, it's probably that it's indeed not enabled.
|
141 |
-
|
142 |
-
|
143 |
-
## Related
|
144 |
-
* https://www.maxcdn.com/blog/how-to-reduce-image-size-with-webp-automagically/
|
145 |
-
* https://www.digitalocean.com/community/tutorials/how-to-create-and-serve-webp-images-to-speed-up-your-website
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vendor/rosell-dk/webp-convert/docs/v2.0/webp-on-demand/without-composer.md
DELETED
@@ -1,58 +0,0 @@
|
|
1 |
-
# WebP On Demand without composer
|
2 |
-
|
3 |
-
For your convenience, the library has been cooked down to two files: *webp-on-demand-1.inc* and *webp-on-demand-2.inc*. The second one is loaded when the first one decides it needs to do a conversion (and not simply serve existing image).
|
4 |
-
|
5 |
-
## Installing
|
6 |
-
|
7 |
-
### 1. Copy the latest build files into your website
|
8 |
-
The build files are distributed [here](https://github.com/rosell-dk/webp-convert-concat/tree/master/build). Open the "latest" folder and copy *webp-on-demand-1.inc* and *webp-on-demand-2.inc* into your website. They can be located wherever you like.
|
9 |
-
|
10 |
-
### 2. Create a *webp-on-demand.php*
|
11 |
-
|
12 |
-
Create a file *webp-on-demand.php*, and place it in webroot, or where-ever you like in you web-application.
|
13 |
-
|
14 |
-
Here is a minimal example to get started with:
|
15 |
-
|
16 |
-
```php
|
17 |
-
<?php
|
18 |
-
// To start with, lets display any errors.
|
19 |
-
// - this will reveal if you entered wrong paths
|
20 |
-
error_reporting(E_ALL);
|
21 |
-
ini_set("display_errors", 1);
|
22 |
-
|
23 |
-
// Once you got it working, make sure that PHP warnings are not send to the output
|
24 |
-
// - this will corrupt the image
|
25 |
-
// For example, you can do it by commenting out the lines below:
|
26 |
-
// error_reporting(0);
|
27 |
-
// ini_set("display_errors", 0);
|
28 |
-
|
29 |
-
use WebPConvert\WebPConvert;
|
30 |
-
|
31 |
-
require 'webp-on-demand-1.inc';
|
32 |
-
|
33 |
-
function webpconvert_autoloader($class) {
|
34 |
-
if (strpos($class, 'WebPConvert\\') === 0) {
|
35 |
-
require_once __DIR__ . '/webp-on-demand-2.inc';
|
36 |
-
}
|
37 |
-
}
|
38 |
-
spl_autoload_register('webpconvert_autoloader', true, true);
|
39 |
-
|
40 |
-
$source = $_GET['source']; // Absolute file path to source file. Comes from the .htaccess
|
41 |
-
$destination = $source . '.webp'; // Store the converted images besides the original images (other options are available!)
|
42 |
-
|
43 |
-
$options = [
|
44 |
-
|
45 |
-
// UNCOMMENT NEXT LINE, WHEN YOU ARE UP AND RUNNING!
|
46 |
-
'show-report' => true // Show a conversion report instead of serving the converted image.
|
47 |
-
|
48 |
-
// More options available!
|
49 |
-
// https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/converting/introduction-for-converting.md
|
50 |
-
// https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/serving/introduction-for-serving.md
|
51 |
-
];
|
52 |
-
WebPConvert::serveConverted($source, $destination, $options);
|
53 |
-
```
|
54 |
-
|
55 |
-
Note that the procedure has changed in 2.0. In 1.x, the library supported a `require-for-conversion` option, but this option has been removed in 2.0. It was not really needed, as the example above illustrates.
|
56 |
-
|
57 |
-
### 3. Continue the regular install instructions from step 3
|
58 |
-
[Click here to continue...](https://github.com/rosell-dk/webp-on-demand#3-add-redirect-rules)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vendor/rosell-dk/webp-convert/src/Convert/Converters/Cwebp.php
CHANGED
@@ -713,13 +713,13 @@ class Cwebp extends AbstractConverter
|
|
713 |
|
714 |
if (defined('WEBPCONVERT_CWEBP_PATH')) {
|
715 |
$this->logLn('WEBPCONVERT_CWEBP_PATH was defined, so using that path and ignoring any other');
|
716 |
-
return [constant('WEBPCONVERT_CWEBP_PATH')];
|
717 |
}
|
718 |
if (!empty(getenv('WEBPCONVERT_CWEBP_PATH'))) {
|
719 |
$this->logLn(
|
720 |
'WEBPCONVERT_CWEBP_PATH environment variable was set, so using that path and ignoring any other'
|
721 |
);
|
722 |
-
return [getenv('WEBPCONVERT_CWEBP_PATH')];
|
723 |
}
|
724 |
|
725 |
if ($this->options['try-cwebp']) {
|
713 |
|
714 |
if (defined('WEBPCONVERT_CWEBP_PATH')) {
|
715 |
$this->logLn('WEBPCONVERT_CWEBP_PATH was defined, so using that path and ignoring any other');
|
716 |
+
return [[constant('WEBPCONVERT_CWEBP_PATH')],[[], []]];
|
717 |
}
|
718 |
if (!empty(getenv('WEBPCONVERT_CWEBP_PATH'))) {
|
719 |
$this->logLn(
|
720 |
'WEBPCONVERT_CWEBP_PATH environment variable was set, so using that path and ignoring any other'
|
721 |
);
|
722 |
+
return [[getenv('WEBPCONVERT_CWEBP_PATH')],[[], []]];
|
723 |
}
|
724 |
|
725 |
if ($this->options['try-cwebp']) {
|
vendor/rosell-dk/webp-convert/src/Helpers/SanityCheck.txt
DELETED
@@ -1,255 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace WebPConvert\Helpers;
|
4 |
-
|
5 |
-
use WebPConvert\Helpers\Sanitize;
|
6 |
-
use WebPConvert\Exceptions\SanityException;
|
7 |
-
|
8 |
-
class SanityCheck
|
9 |
-
{
|
10 |
-
|
11 |
-
/**
|
12 |
-
*
|
13 |
-
* @param string $input string to test for NUL char
|
14 |
-
*/
|
15 |
-
public static function mustBeString($input, $errorMsg = 'String expected')
|
16 |
-
{
|
17 |
-
if (gettype($input) !== 'string') {
|
18 |
-
throw new SanityException($errorMsg);
|
19 |
-
}
|
20 |
-
return $input;
|
21 |
-
}
|
22 |
-
|
23 |
-
/**
|
24 |
-
* The NUL character is a demon, because it can be used to bypass other tests
|
25 |
-
* See https://st-g.de/2011/04/doing-filename-checks-securely-in-PHP.
|
26 |
-
*
|
27 |
-
* @param string $input string to test for NUL char
|
28 |
-
*/
|
29 |
-
public static function noNUL($input, $errorMsg = 'NUL character is not allowed')
|
30 |
-
{
|
31 |
-
self::mustBeString($input);
|
32 |
-
if (strpos($input, chr(0)) !== false) {
|
33 |
-
throw new SanityException($errorMsg);
|
34 |
-
}
|
35 |
-
return $input;
|
36 |
-
}
|
37 |
-
|
38 |
-
/**
|
39 |
-
* Prevent control chararters (#00 - #20).
|
40 |
-
*
|
41 |
-
* This prevents line feed, new line, tab, charater return, tab, ets.
|
42 |
-
* https://www.rapidtables.com/code/text/ascii-table.html
|
43 |
-
*
|
44 |
-
* @param string $input string to test for control characters
|
45 |
-
*/
|
46 |
-
public static function noControlChars($input)
|
47 |
-
{
|
48 |
-
self::mustBeString($input);
|
49 |
-
self::noNUL($input);
|
50 |
-
if (preg_match('#[\x{0}-\x{1f}]#', $input)) {
|
51 |
-
throw new SanityException('Control characters are not allowed');
|
52 |
-
}
|
53 |
-
return $input;
|
54 |
-
}
|
55 |
-
|
56 |
-
|
57 |
-
/**
|
58 |
-
*
|
59 |
-
* @param mixed $input something that may not be empty
|
60 |
-
*/
|
61 |
-
public static function notEmpty($input, $errorMsg = 'Must be non-empty')
|
62 |
-
{
|
63 |
-
if (empty($input)) {
|
64 |
-
throw new SanityException($input);
|
65 |
-
}
|
66 |
-
return $input;
|
67 |
-
}
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
public static function noDirectoryTraversal($input, $errorMsg = 'Directory traversal is not allowed')
|
72 |
-
{
|
73 |
-
self::mustBeString($input);
|
74 |
-
self::noControlChars($input);
|
75 |
-
if (preg_match('#\.\.\/#', $input)) {
|
76 |
-
throw new SanityException($errorMsg);
|
77 |
-
}
|
78 |
-
return $input;
|
79 |
-
}
|
80 |
-
|
81 |
-
public static function noStreamWrappers($input, $errorMsg = 'Stream wrappers are not allowed')
|
82 |
-
{
|
83 |
-
self::mustBeString($input);
|
84 |
-
self::noControlChars($input);
|
85 |
-
|
86 |
-
// Prevent stream wrappers ("phar://", "php://" and the like)
|
87 |
-
// https://www.php.net/manual/en/wrappers.phar.php
|
88 |
-
if (preg_match('#^\\w+://#', Sanitize::removeNUL($input))) {
|
89 |
-
throw new SanityException($errorMsg);
|
90 |
-
}
|
91 |
-
return $input;
|
92 |
-
}
|
93 |
-
|
94 |
-
public static function path($input)
|
95 |
-
{
|
96 |
-
self::notEmpty($input);
|
97 |
-
self::mustBeString($input);
|
98 |
-
self::noControlChars($input);
|
99 |
-
self::noDirectoryTraversal($input);
|
100 |
-
self::noStreamWrappers($input);
|
101 |
-
return $input;
|
102 |
-
}
|
103 |
-
|
104 |
-
public static function pathWithoutDirectoryTraversal($input)
|
105 |
-
{
|
106 |
-
return self::path($input);
|
107 |
-
}
|
108 |
-
|
109 |
-
public static function absPathMicrosoftStyle($input, $errorMsg = 'Not an fully qualified Windows path')
|
110 |
-
{
|
111 |
-
// On microsoft we allow [drive letter]:\
|
112 |
-
if (!preg_match("#^[A-Z]:\\\\|/#", $input)) {
|
113 |
-
throw new SanityException($errorMsg . ':' . $input);
|
114 |
-
}
|
115 |
-
return $input;
|
116 |
-
}
|
117 |
-
|
118 |
-
public static function absPath($input, $errorMsg = 'Not an absolute path')
|
119 |
-
{
|
120 |
-
if ((strpos($input, '/') !== 0)) {
|
121 |
-
|
122 |
-
// Check if we are on Microsoft
|
123 |
-
$onMicrosoft = false;
|
124 |
-
if (isset($_SERVER['SERVER_SOFTWARE'])) {
|
125 |
-
if (strpos(strtolower($_SERVER['SERVER_SOFTWARE']), 'microsoft') !== false) {
|
126 |
-
$onMicrosoft = true;
|
127 |
-
}
|
128 |
-
}
|
129 |
-
switch (PHP_OS) {
|
130 |
-
case "WINNT":
|
131 |
-
case "WIN32":
|
132 |
-
case "INTERIX":
|
133 |
-
case "UWIN":
|
134 |
-
case "UWIN-W7":
|
135 |
-
$onMicrosoft = true;
|
136 |
-
break;
|
137 |
-
}
|
138 |
-
|
139 |
-
if (!$onMicrosoft) {
|
140 |
-
throw new SanityException($errorMsg . ':' . $input);
|
141 |
-
}
|
142 |
-
self::absPathMicrosoftStyle($input);
|
143 |
-
|
144 |
-
}
|
145 |
-
return self::path($input);
|
146 |
-
}
|
147 |
-
|
148 |
-
public static function pathBeginsWith($input, $beginsWith, $errorMsg = 'Path is outside allowed path')
|
149 |
-
{
|
150 |
-
self::path($input);
|
151 |
-
if (!(strpos($input, $beginsWith) === 0)) {
|
152 |
-
throw new SanityException($errorMsg);
|
153 |
-
}
|
154 |
-
return $input;
|
155 |
-
}
|
156 |
-
|
157 |
-
public static function findClosestExistingFolderSymLinksExpanded($input) {
|
158 |
-
$levelsUp = 1;
|
159 |
-
//echo 'input:' . $input;
|
160 |
-
while (true) {
|
161 |
-
$dir = dirname($input, $levelsUp);
|
162 |
-
//echo 'dir:' . $dir . '<br>';
|
163 |
-
$realPathResult = realpath($dir);
|
164 |
-
if ($realPathResult !== false) {
|
165 |
-
return $realPathResult;
|
166 |
-
}
|
167 |
-
if (($dir == '/') || (strlen($dir) < 4)) {
|
168 |
-
return $dir;
|
169 |
-
}
|
170 |
-
$levelsUp++;
|
171 |
-
}
|
172 |
-
return '/';
|
173 |
-
}
|
174 |
-
|
175 |
-
public static function pathBeginsWithSymLinksExpanded($input, $beginsWith, $errorMsg = 'Path is outside allowed path') {
|
176 |
-
$closestExistingFolder = self::findClosestExistingFolderSymLinksExpanded($input);
|
177 |
-
//throw new SanityException('hm.' . $input . ' : <br>' . $closestExistingFolder);
|
178 |
-
self::pathBeginsWith($closestExistingFolder, $beginsWith, $errorMsg);
|
179 |
-
}
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
public static function absPathExists($input, $errorMsg = 'Path does not exist')
|
184 |
-
{
|
185 |
-
self::absPath($input);
|
186 |
-
if (@!file_exists($input)) {
|
187 |
-
throw new SanityException($errorMsg);
|
188 |
-
}
|
189 |
-
return $input;
|
190 |
-
}
|
191 |
-
|
192 |
-
public static function absPathExistsAndIsDir(
|
193 |
-
$input,
|
194 |
-
$errorMsg = 'Path points to a file (it should point to a directory)'
|
195 |
-
) {
|
196 |
-
self::absPathExists($input);
|
197 |
-
if (!is_dir($input)) {
|
198 |
-
throw new SanityException($errorMsg);
|
199 |
-
}
|
200 |
-
return $input;
|
201 |
-
}
|
202 |
-
|
203 |
-
public static function absPathExistsAndIsFile(
|
204 |
-
$input,
|
205 |
-
$errorMsg = 'Path points to a directory (it should not do that)'
|
206 |
-
) {
|
207 |
-
self::absPathExists($input, 'File does not exist');
|
208 |
-
if (@is_dir($input)) {
|
209 |
-
throw new SanityException($errorMsg);
|
210 |
-
}
|
211 |
-
return $input;
|
212 |
-
}
|
213 |
-
|
214 |
-
public static function absPathExistsAndIsNotDir(
|
215 |
-
$input,
|
216 |
-
$errorMsg = 'Path points to a directory (it should point to a file)'
|
217 |
-
) {
|
218 |
-
self::absPathExistsAndIsFile($input, $errorMsg);
|
219 |
-
return $input;
|
220 |
-
}
|
221 |
-
|
222 |
-
|
223 |
-
public static function pregMatch($pattern, $input, $errorMsg = 'Does not match expected pattern')
|
224 |
-
{
|
225 |
-
self::noNUL($input);
|
226 |
-
self::mustBeString($input);
|
227 |
-
if (!preg_match($pattern, $input)) {
|
228 |
-
throw new SanityException($errorMsg);
|
229 |
-
}
|
230 |
-
return $input;
|
231 |
-
}
|
232 |
-
|
233 |
-
public static function isJSONArray($input, $errorMsg = 'Not a JSON array')
|
234 |
-
{
|
235 |
-
self::noNUL($input);
|
236 |
-
self::mustBeString($input);
|
237 |
-
self::notEmpty($input);
|
238 |
-
if ((strpos($input, '[') !== 0) || (!is_array(json_decode($input)))) {
|
239 |
-
throw new SanityException($errorMsg);
|
240 |
-
}
|
241 |
-
return $input;
|
242 |
-
}
|
243 |
-
|
244 |
-
public static function isJSONObject($input, $errorMsg = 'Not a JSON object')
|
245 |
-
{
|
246 |
-
self::noNUL($input);
|
247 |
-
self::mustBeString($input);
|
248 |
-
self::notEmpty($input);
|
249 |
-
if ((strpos($input, '{') !== 0) || (!is_object(json_decode($input)))) {
|
250 |
-
throw new SanityException($errorMsg);
|
251 |
-
}
|
252 |
-
return $input;
|
253 |
-
}
|
254 |
-
|
255 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
webp-express.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* Plugin Name: WebP Express
|
4 |
* Plugin URI: https://github.com/rosell-dk/webp-express
|
5 |
* Description: Serve autogenerated WebP images instead of jpeg/png to browsers that supports WebP. Works on anything (media library images, galleries, theme images etc).
|
6 |
-
* Version: 0.25.
|
7 |
* Author: Bjørn Rosell
|
8 |
* Author URI: https://www.bitwise-it.dk
|
9 |
* License: GPL2
|
3 |
* Plugin Name: WebP Express
|
4 |
* Plugin URI: https://github.com/rosell-dk/webp-express
|
5 |
* Description: Serve autogenerated WebP images instead of jpeg/png to browsers that supports WebP. Works on anything (media library images, galleries, theme images etc).
|
6 |
+
* Version: 0.25.2
|
7 |
* Author: Bjørn Rosell
|
8 |
* Author URI: https://www.bitwise-it.dk
|
9 |
* License: GPL2
|