WebP Express - Version 0.14.20

Version Description

(released: 29 jun 2019)

  • Fixed bug: Ewww api-key was forgot upon saving options (fixed by pcfreak30, USA, reported by viajandocomamalarosa. Thanks!)
  • Cleaned away unneeded files in vendor folders (primarily docs and tests)
Download this release

Release Info

Developer rosell.dk
Plugin Icon 128x128 WebP Express
Version 0.14.20
Comparing to
See all releases

Code changes from version 0.14.19 to 0.14.20

Files changed (32) hide show
  1. README.md +3 -2
  2. README.txt +10 -1
  3. lib/options/submit.php +4 -0
  4. tests/BananaTest.php +0 -24
  5. vendor/autoload.php +1 -1
  6. vendor/composer/autoload_classmap.php +83 -0
  7. vendor/composer/autoload_real.php +4 -4
  8. vendor/composer/autoload_static.php +90 -3
  9. vendor/composer/installed.json +2 -2
  10. vendor/rosell-dk/webp-convert-cloud-service/docs/api.md +0 -103
  11. vendor/rosell-dk/webp-convert-cloud-service/docs/development.md +0 -51
  12. vendor/rosell-dk/webp-convert-cloud-service/tests/WebPConvertCloudServiceTest.php +0 -21
  13. vendor/rosell-dk/webp-convert/docs/development.md +0 -78
  14. vendor/rosell-dk/webp-convert/docs/v1.3/converting/convert-options.md +0 -322
  15. vendor/rosell-dk/webp-convert/docs/v1.3/converting/convert.md +0 -96
  16. vendor/rosell-dk/webp-convert/docs/v1.3/converting/converters.md +0 -322
  17. vendor/rosell-dk/webp-convert/docs/v1.3/serving/convert-and-serve.md +0 -167
  18. vendor/rosell-dk/webp-convert/docs/v1.3/webp-on-demand/tweaks.md +0 -167
  19. vendor/rosell-dk/webp-convert/docs/v1.3/webp-on-demand/webp-on-demand.md +0 -133
  20. vendor/rosell-dk/webp-convert/docs/v1.3/webp-on-demand/without-composer.md +0 -45
  21. vendor/rosell-dk/webp-convert/docs/v2.0/converting/architecture-q50-w600.jpg +0 -0
  22. vendor/rosell-dk/webp-convert/docs/v2.0/converting/converters/stack.md +0 -248
  23. vendor/rosell-dk/webp-convert/docs/v2.0/converting/dice.png +0 -0
  24. vendor/rosell-dk/webp-convert/docs/v2.0/converting/introduction-for-converting.md +0 -218
  25. vendor/rosell-dk/webp-convert/docs/v2.0/converting/mouse-q100.jpg +0 -0
  26. vendor/rosell-dk/webp-convert/docs/v2.0/converting/options.md +0 -319
  27. vendor/rosell-dk/webp-convert/docs/v2.0/migrating-to-2.0.md +0 -73
  28. vendor/rosell-dk/webp-convert/docs/v2.0/serving/introduction-for-serving.md +0 -143
  29. vendor/rosell-dk/webp-convert/docs/v2.0/webp-on-demand/tweaks.md +0 -167
  30. vendor/rosell-dk/webp-convert/docs/v2.0/webp-on-demand/webp-on-demand.md +0 -145
  31. vendor/rosell-dk/webp-convert/docs/v2.0/webp-on-demand/without-composer.md +0 -58
  32. webp-express.php +1 -1
README.md CHANGED
@@ -2,9 +2,10 @@
2
 
3
  Serve autogenerated WebP images instead of jpeg/png to browsers that supports WebP.
4
 
5
- The plugin is available on the Wordpress codex ([here](https://wordpress.org/plugins/webp-express/)), and developed on github ([here](https://github.com/rosell-dk/webp-express/)).
 
6
 
7
- Note that to use the version on github, you need to *cd* into the plugin folder and run `composer update`.
8
 
9
  ## Description
10
  Almost 4 out of 5 mobile users use a browser that is able to display webp images. Yet, on most websites, they are served jpeg images, which are typically double the size of webp images for a given quality. What a waste of bandwidth! This plugin was created to help remedy that situation. With little effort, Wordpress admins can have their site serving autogenerated webp images to browsers that supports it, while still serving jpeg and png files to browsers that does not support webp.
2
 
3
  Serve autogenerated WebP images instead of jpeg/png to browsers that supports WebP.
4
 
5
+ The plugin is available on the Wordpress codex ([here](https://wordpress.org/plugins/webp-express/)).
6
+ But well, it is developed ([here on github](https://github.com/rosell-dk/webp-express/)).
7
 
8
+ **News: I have added the vendor folder to the repo. To install the plugin here from github, you can simply download the zip and unzip it in your plugin folder**
9
 
10
  ## Description
11
  Almost 4 out of 5 mobile users use a browser that is able to display webp images. Yet, on most websites, they are served jpeg images, which are typically double the size of webp images for a given quality. What a waste of bandwidth! This plugin was created to help remedy that situation. With little effort, Wordpress admins can have their site serving autogenerated webp images to browsers that supports it, while still serving jpeg and png files to browsers that does not support webp.
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.2
7
- Stable tag: 0.14.19
8
  Requires PHP: 5.6
9
  License: GPLv3
10
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
@@ -612,6 +612,12 @@ Easy enough! - [Go here!](https://ko-fi.com/rosell). Or [here](https://buymeacof
612
 
613
  == Changelog ==
614
 
 
 
 
 
 
 
615
  = 0.14.19 =
616
  *(released: 28 jun 2019)*
617
 
@@ -914,6 +920,9 @@ For older releases, check out changelog.txt
914
 
915
  == Upgrade Notice ==
916
 
 
 
 
917
  = 0.14.19 =
918
  * Bug fix
919
 
4
  Tags: webp, images, performance
5
  Requires at least: 4.0
6
  Tested up to: 5.2
7
+ Stable tag: 0.14.20
8
  Requires PHP: 5.6
9
  License: GPLv3
10
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
612
 
613
  == Changelog ==
614
 
615
+ = 0.14.20 =
616
+ *(released: 29 jun 2019)*
617
+
618
+ * Fixed bug: Ewww api-key was forgot upon saving options (fixed by pcfreak30, USA, reported by viajandocomamalarosa. Thanks!)
619
+ * Cleaned away unneeded files in vendor folders (primarily docs and tests)
620
+
621
  = 0.14.19 =
622
  *(released: 28 jun 2019)*
623
 
920
 
921
  == Upgrade Notice ==
922
 
923
+ = 0.14.20 =
924
+ * Ewww api-key was forgotten upon saving options
925
+
926
  = 0.14.19 =
927
  * Bug fix
928
 
lib/options/submit.php CHANGED
@@ -219,6 +219,10 @@ function webpexpress_getSanitizedConverters() {
219
  "api-version" => 'integer',
220
  "crypt-api-key-in-transfer" => 'boolean',
221
  "new-api-key" => 'string',
 
 
 
 
222
  ];
223
 
224
  // check that it is an accepted option name
219
  "api-version" => 'integer',
220
  "crypt-api-key-in-transfer" => 'boolean',
221
  "new-api-key" => 'string',
222
+
223
+ //ewww
224
+ "api-key" => 'string',
225
+ "api-key-2" => 'string',
226
  ];
227
 
228
  // check that it is an accepted option name
tests/BananaTest.php DELETED
@@ -1,24 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * WebPConvert - Convert JPEG & PNG to WebP with PHP
5
- *
6
- * @link https://github.com/rosell-dk/webp-convert
7
- * @license MIT
8
- */
9
-
10
- namespace WebPExpressTests;
11
-
12
- //use WebPConvert\WebPConvert;
13
- use PHPUnit\Framework\TestCase;
14
- use Sunra\PhpSimple\HtmlDomParser;
15
-
16
- class BananaTest extends TestCase
17
- {
18
-
19
- public function testPotatoPotato()
20
- {
21
- $this->assertEquals('potato', 'potato');
22
- }
23
-
24
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/autoload.php CHANGED
@@ -4,4 +4,4 @@
4
 
5
  require_once __DIR__ . '/composer/autoload_real.php';
6
 
7
- return ComposerAutoloaderInit9a5d1d521aac5c1f4f08f3a90858f030::getLoader();
4
 
5
  require_once __DIR__ . '/composer/autoload_real.php';
6
 
7
+ return ComposerAutoloaderInit8fd167583ae3bd095a84a87a56a51e7c::getLoader();
vendor/composer/autoload_classmap.php CHANGED
@@ -6,4 +6,87 @@ $vendorDir = dirname(dirname(__FILE__));
6
  $baseDir = dirname($vendorDir);
7
 
8
  return array(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  );
6
  $baseDir = dirname($vendorDir);
7
 
8
  return array(
9
+ 'DOMUtilForWebP\\ImageUrlReplacer' => $vendorDir . '/rosell-dk/dom-util-for-webp/src/ImageUrlReplacer.php',
10
+ 'DOMUtilForWebP\\PictureTags' => $vendorDir . '/rosell-dk/dom-util-for-webp/src/PictureTags.php',
11
+ 'ImageMimeTypeGuesser\\Detectors\\AbstractDetector' => $vendorDir . '/rosell-dk/image-mime-type-guesser/src/Detectors/AbstractDetector.php',
12
+ 'ImageMimeTypeGuesser\\Detectors\\ExifImageType' => $vendorDir . '/rosell-dk/image-mime-type-guesser/src/Detectors/ExifImageType.php',
13
+ 'ImageMimeTypeGuesser\\Detectors\\FInfo' => $vendorDir . '/rosell-dk/image-mime-type-guesser/src/Detectors/FInfo.php',
14
+ 'ImageMimeTypeGuesser\\Detectors\\GetImageSize' => $vendorDir . '/rosell-dk/image-mime-type-guesser/src/Detectors/GetImageSize.php',
15
+ 'ImageMimeTypeGuesser\\Detectors\\MimeContentType' => $vendorDir . '/rosell-dk/image-mime-type-guesser/src/Detectors/MimeContentType.php',
16
+ 'ImageMimeTypeGuesser\\Detectors\\SniffFirstFourBytes' => $vendorDir . '/rosell-dk/image-mime-type-guesser/src/Detectors/SniffFirstFourBytes.php',
17
+ 'ImageMimeTypeGuesser\\Detectors\\Stack' => $vendorDir . '/rosell-dk/image-mime-type-guesser/src/Detectors/Stack.php',
18
+ 'ImageMimeTypeGuesser\\GuessFromExtension' => $vendorDir . '/rosell-dk/image-mime-type-guesser/src/GuessFromExtension.php',
19
+ 'ImageMimeTypeGuesser\\ImageMimeTypeGuesser' => $vendorDir . '/rosell-dk/image-mime-type-guesser/src/ImageMimeTypeGuesser.php',
20
+ 'WebPConvertCloudService\\AccessCheck' => $vendorDir . '/rosell-dk/webp-convert-cloud-service/src/AccessCheck.php',
21
+ 'WebPConvertCloudService\\Serve' => $vendorDir . '/rosell-dk/webp-convert-cloud-service/src/Serve.php',
22
+ 'WebPConvertCloudService\\WebPConvertCloudService' => $vendorDir . '/rosell-dk/webp-convert-cloud-service/src/WebPConvertCloudService.php',
23
+ 'WebPConvert\\Convert\\ConverterFactory' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/ConverterFactory.php',
24
+ 'WebPConvert\\Convert\\Converters\\AbstractConverter' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Converters/AbstractConverter.php',
25
+ 'WebPConvert\\Convert\\Converters\\BaseTraits\\AutoQualityTrait' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Converters/BaseTraits/AutoQualityTrait.php',
26
+ 'WebPConvert\\Convert\\Converters\\BaseTraits\\DestinationPreparationTrait' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Converters/BaseTraits/DestinationPreparationTrait.php',
27
+ 'WebPConvert\\Convert\\Converters\\BaseTraits\\LoggerTrait' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Converters/BaseTraits/LoggerTrait.php',
28
+ 'WebPConvert\\Convert\\Converters\\BaseTraits\\OptionsTrait' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Converters/BaseTraits/OptionsTrait.php',
29
+ 'WebPConvert\\Convert\\Converters\\BaseTraits\\WarningLoggerTrait' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Converters/BaseTraits/WarningLoggerTrait.php',
30
+ 'WebPConvert\\Convert\\Converters\\ConverterTraits\\CloudConverterTrait' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Converters/ConverterTraits/CloudConverterTrait.php',
31
+ 'WebPConvert\\Convert\\Converters\\ConverterTraits\\CurlTrait' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Converters/ConverterTraits/CurlTrait.php',
32
+ 'WebPConvert\\Convert\\Converters\\ConverterTraits\\EncodingAutoTrait' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Converters/ConverterTraits/EncodingAutoTrait.php',
33
+ 'WebPConvert\\Convert\\Converters\\ConverterTraits\\ExecTrait' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Converters/ConverterTraits/ExecTrait.php',
34
+ 'WebPConvert\\Convert\\Converters\\Cwebp' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Converters/Cwebp.php',
35
+ 'WebPConvert\\Convert\\Converters\\Ewww' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Converters/Ewww.php',
36
+ 'WebPConvert\\Convert\\Converters\\Gd' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Converters/Gd.php',
37
+ 'WebPConvert\\Convert\\Converters\\Gmagick' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Converters/Gmagick.php',
38
+ 'WebPConvert\\Convert\\Converters\\GmagickBinary' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Converters/GmagickBinary.php',
39
+ 'WebPConvert\\Convert\\Converters\\GraphicsMagick' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Converters/GraphicsMagick.php',
40
+ 'WebPConvert\\Convert\\Converters\\ImageMagick' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Converters/ImageMagick.php',
41
+ 'WebPConvert\\Convert\\Converters\\Imagick' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Converters/Imagick.php',
42
+ 'WebPConvert\\Convert\\Converters\\ImagickBinary' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Converters/ImagickBinary.php',
43
+ 'WebPConvert\\Convert\\Converters\\Stack' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Converters/Stack.php',
44
+ 'WebPConvert\\Convert\\Converters\\Vips' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Converters/Vips.php',
45
+ 'WebPConvert\\Convert\\Converters\\Wpc' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Converters/Wpc.php',
46
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailedException' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailedException.php',
47
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\ConversionSkippedException' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/ConversionSkippedException.php',
48
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\ConverterNotOperationalException' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/ConverterNotOperationalException.php',
49
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\ConverterNotOperational\\InvalidApiKeyException' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/ConverterNotOperational/InvalidApiKeyException.php',
50
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\ConverterNotOperational\\SystemRequirementsNotMetException' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/ConverterNotOperational/SystemRequirementsNotMetException.php',
51
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\FileSystemProblemsException' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/FileSystemProblemsException.php',
52
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\FileSystemProblems\\CreateDestinationFileException' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/FileSystemProblems/CreateDestinationFileException.php',
53
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\FileSystemProblems\\CreateDestinationFolderException' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/FileSystemProblems/CreateDestinationFolderException.php',
54
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\InvalidInputException' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/InvalidInputException.php',
55
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\InvalidInput\\ConverterNotFoundException' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/InvalidInput/ConverterNotFoundException.php',
56
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\InvalidInput\\InvalidImageTypeException' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/InvalidInput/InvalidImageTypeException.php',
57
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\InvalidInput\\TargetNotFoundException' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/InvalidInput/TargetNotFoundException.php',
58
+ 'WebPConvert\\Convert\\Helpers\\JpegQualityDetector' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Helpers/JpegQualityDetector.php',
59
+ 'WebPConvert\\Convert\\Helpers\\PhpIniSizes' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Helpers/PhpIniSizes.php',
60
+ 'WebPConvert\\Exceptions\\InvalidInputException' => $vendorDir . '/rosell-dk/webp-convert/src/Exceptions/InvalidInputException.php',
61
+ 'WebPConvert\\Exceptions\\InvalidInput\\InvalidImageTypeException' => $vendorDir . '/rosell-dk/webp-convert/src/Exceptions/InvalidInput/InvalidImageTypeException.php',
62
+ 'WebPConvert\\Exceptions\\InvalidInput\\TargetNotFoundException' => $vendorDir . '/rosell-dk/webp-convert/src/Exceptions/InvalidInput/TargetNotFoundException.php',
63
+ 'WebPConvert\\Exceptions\\WebPConvertException' => $vendorDir . '/rosell-dk/webp-convert/src/Exceptions/WebPConvertException.php',
64
+ 'WebPConvert\\Helpers\\InputValidator' => $vendorDir . '/rosell-dk/webp-convert/src/Helpers/InputValidator.php',
65
+ 'WebPConvert\\Helpers\\MimeType' => $vendorDir . '/rosell-dk/webp-convert/src/Helpers/MimeType.php',
66
+ 'WebPConvert\\Helpers\\PathChecker' => $vendorDir . '/rosell-dk/webp-convert/src/Helpers/PathChecker.php',
67
+ 'WebPConvert\\Loggers\\BaseLogger' => $vendorDir . '/rosell-dk/webp-convert/src/Loggers/BaseLogger.php',
68
+ 'WebPConvert\\Loggers\\BufferLogger' => $vendorDir . '/rosell-dk/webp-convert/src/Loggers/BufferLogger.php',
69
+ 'WebPConvert\\Loggers\\EchoLogger' => $vendorDir . '/rosell-dk/webp-convert/src/Loggers/EchoLogger.php',
70
+ 'WebPConvert\\Options\\ArrayOption' => $vendorDir . '/rosell-dk/webp-convert/src/Options/ArrayOption.php',
71
+ 'WebPConvert\\Options\\BooleanOption' => $vendorDir . '/rosell-dk/webp-convert/src/Options/BooleanOption.php',
72
+ 'WebPConvert\\Options\\Exceptions\\InvalidOptionTypeException' => $vendorDir . '/rosell-dk/webp-convert/src/Options/Exceptions/InvalidOptionTypeException.php',
73
+ 'WebPConvert\\Options\\Exceptions\\InvalidOptionValueException' => $vendorDir . '/rosell-dk/webp-convert/src/Options/Exceptions/InvalidOptionValueException.php',
74
+ 'WebPConvert\\Options\\Exceptions\\OptionNotFoundException' => $vendorDir . '/rosell-dk/webp-convert/src/Options/Exceptions/OptionNotFoundException.php',
75
+ 'WebPConvert\\Options\\GhostOption' => $vendorDir . '/rosell-dk/webp-convert/src/Options/GhostOption.php',
76
+ 'WebPConvert\\Options\\IntegerOption' => $vendorDir . '/rosell-dk/webp-convert/src/Options/IntegerOption.php',
77
+ 'WebPConvert\\Options\\IntegerOrNullOption' => $vendorDir . '/rosell-dk/webp-convert/src/Options/IntegerOrNullOption.php',
78
+ 'WebPConvert\\Options\\MetadataOption' => $vendorDir . '/rosell-dk/webp-convert/src/Options/MetadataOption.php',
79
+ 'WebPConvert\\Options\\Option' => $vendorDir . '/rosell-dk/webp-convert/src/Options/Option.php',
80
+ 'WebPConvert\\Options\\Options' => $vendorDir . '/rosell-dk/webp-convert/src/Options/Options.php',
81
+ 'WebPConvert\\Options\\QualityOption' => $vendorDir . '/rosell-dk/webp-convert/src/Options/QualityOption.php',
82
+ 'WebPConvert\\Options\\SensitiveArrayOption' => $vendorDir . '/rosell-dk/webp-convert/src/Options/SensitiveArrayOption.php',
83
+ 'WebPConvert\\Options\\SensitiveStringOption' => $vendorDir . '/rosell-dk/webp-convert/src/Options/SensitiveStringOption.php',
84
+ 'WebPConvert\\Options\\StringOption' => $vendorDir . '/rosell-dk/webp-convert/src/Options/StringOption.php',
85
+ 'WebPConvert\\Serve\\Exceptions\\ServeFailedException' => $vendorDir . '/rosell-dk/webp-convert/src/Serve/Exceptions/ServeFailedException.php',
86
+ 'WebPConvert\\Serve\\Header' => $vendorDir . '/rosell-dk/webp-convert/src/Serve/Header.php',
87
+ 'WebPConvert\\Serve\\Report' => $vendorDir . '/rosell-dk/webp-convert/src/Serve/Report.php',
88
+ 'WebPConvert\\Serve\\ServeConvertedWebP' => $vendorDir . '/rosell-dk/webp-convert/src/Serve/ServeConvertedWebP.php',
89
+ 'WebPConvert\\Serve\\ServeConvertedWebPWithErrorHandling' => $vendorDir . '/rosell-dk/webp-convert/src/Serve/ServeConvertedWebPWithErrorHandling.php',
90
+ 'WebPConvert\\Serve\\ServeFile' => $vendorDir . '/rosell-dk/webp-convert/src/Serve/ServeFile.php',
91
+ 'WebPConvert\\WebPConvert' => $vendorDir . '/rosell-dk/webp-convert/src/WebPConvert.php',
92
  );
vendor/composer/autoload_real.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  // autoload_real.php @generated by Composer
4
 
5
- class ComposerAutoloaderInit9a5d1d521aac5c1f4f08f3a90858f030
6
  {
7
  private static $loader;
8
 
@@ -19,15 +19,15 @@ class ComposerAutoloaderInit9a5d1d521aac5c1f4f08f3a90858f030
19
  return self::$loader;
20
  }
21
 
22
- spl_autoload_register(array('ComposerAutoloaderInit9a5d1d521aac5c1f4f08f3a90858f030', 'loadClassLoader'), true, true);
23
  self::$loader = $loader = new \Composer\Autoload\ClassLoader();
24
- spl_autoload_unregister(array('ComposerAutoloaderInit9a5d1d521aac5c1f4f08f3a90858f030', 'loadClassLoader'));
25
 
26
  $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
27
  if ($useStaticLoader) {
28
  require_once __DIR__ . '/autoload_static.php';
29
 
30
- call_user_func(\Composer\Autoload\ComposerStaticInit9a5d1d521aac5c1f4f08f3a90858f030::getInitializer($loader));
31
  } else {
32
  $map = require __DIR__ . '/autoload_namespaces.php';
33
  foreach ($map as $namespace => $path) {
2
 
3
  // autoload_real.php @generated by Composer
4
 
5
+ class ComposerAutoloaderInit8fd167583ae3bd095a84a87a56a51e7c
6
  {
7
  private static $loader;
8
 
19
  return self::$loader;
20
  }
21
 
22
+ spl_autoload_register(array('ComposerAutoloaderInit8fd167583ae3bd095a84a87a56a51e7c', 'loadClassLoader'), true, true);
23
  self::$loader = $loader = new \Composer\Autoload\ClassLoader();
24
+ spl_autoload_unregister(array('ComposerAutoloaderInit8fd167583ae3bd095a84a87a56a51e7c', 'loadClassLoader'));
25
 
26
  $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
27
  if ($useStaticLoader) {
28
  require_once __DIR__ . '/autoload_static.php';
29
 
30
+ call_user_func(\Composer\Autoload\ComposerStaticInit8fd167583ae3bd095a84a87a56a51e7c::getInitializer($loader));
31
  } else {
32
  $map = require __DIR__ . '/autoload_namespaces.php';
33
  foreach ($map as $namespace => $path) {
vendor/composer/autoload_static.php CHANGED
@@ -4,7 +4,7 @@
4
 
5
  namespace Composer\Autoload;
6
 
7
- class ComposerStaticInit9a5d1d521aac5c1f4f08f3a90858f030
8
  {
9
  public static $prefixLengthsPsr4 = array (
10
  'W' =>
@@ -41,11 +41,98 @@ class ComposerStaticInit9a5d1d521aac5c1f4f08f3a90858f030
41
  ),
42
  );
43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  public static function getInitializer(ClassLoader $loader)
45
  {
46
  return \Closure::bind(function () use ($loader) {
47
- $loader->prefixLengthsPsr4 = ComposerStaticInit9a5d1d521aac5c1f4f08f3a90858f030::$prefixLengthsPsr4;
48
- $loader->prefixDirsPsr4 = ComposerStaticInit9a5d1d521aac5c1f4f08f3a90858f030::$prefixDirsPsr4;
 
49
 
50
  }, null, ClassLoader::class);
51
  }
4
 
5
  namespace Composer\Autoload;
6
 
7
+ class ComposerStaticInit8fd167583ae3bd095a84a87a56a51e7c
8
  {
9
  public static $prefixLengthsPsr4 = array (
10
  'W' =>
41
  ),
42
  );
43
 
44
+ public static $classMap = array (
45
+ 'DOMUtilForWebP\\ImageUrlReplacer' => __DIR__ . '/..' . '/rosell-dk/dom-util-for-webp/src/ImageUrlReplacer.php',
46
+ 'DOMUtilForWebP\\PictureTags' => __DIR__ . '/..' . '/rosell-dk/dom-util-for-webp/src/PictureTags.php',
47
+ 'ImageMimeTypeGuesser\\Detectors\\AbstractDetector' => __DIR__ . '/..' . '/rosell-dk/image-mime-type-guesser/src/Detectors/AbstractDetector.php',
48
+ 'ImageMimeTypeGuesser\\Detectors\\ExifImageType' => __DIR__ . '/..' . '/rosell-dk/image-mime-type-guesser/src/Detectors/ExifImageType.php',
49
+ 'ImageMimeTypeGuesser\\Detectors\\FInfo' => __DIR__ . '/..' . '/rosell-dk/image-mime-type-guesser/src/Detectors/FInfo.php',
50
+ 'ImageMimeTypeGuesser\\Detectors\\GetImageSize' => __DIR__ . '/..' . '/rosell-dk/image-mime-type-guesser/src/Detectors/GetImageSize.php',
51
+ 'ImageMimeTypeGuesser\\Detectors\\MimeContentType' => __DIR__ . '/..' . '/rosell-dk/image-mime-type-guesser/src/Detectors/MimeContentType.php',
52
+ 'ImageMimeTypeGuesser\\Detectors\\SniffFirstFourBytes' => __DIR__ . '/..' . '/rosell-dk/image-mime-type-guesser/src/Detectors/SniffFirstFourBytes.php',
53
+ 'ImageMimeTypeGuesser\\Detectors\\Stack' => __DIR__ . '/..' . '/rosell-dk/image-mime-type-guesser/src/Detectors/Stack.php',
54
+ 'ImageMimeTypeGuesser\\GuessFromExtension' => __DIR__ . '/..' . '/rosell-dk/image-mime-type-guesser/src/GuessFromExtension.php',
55
+ 'ImageMimeTypeGuesser\\ImageMimeTypeGuesser' => __DIR__ . '/..' . '/rosell-dk/image-mime-type-guesser/src/ImageMimeTypeGuesser.php',
56
+ 'WebPConvertCloudService\\AccessCheck' => __DIR__ . '/..' . '/rosell-dk/webp-convert-cloud-service/src/AccessCheck.php',
57
+ 'WebPConvertCloudService\\Serve' => __DIR__ . '/..' . '/rosell-dk/webp-convert-cloud-service/src/Serve.php',
58
+ 'WebPConvertCloudService\\WebPConvertCloudService' => __DIR__ . '/..' . '/rosell-dk/webp-convert-cloud-service/src/WebPConvertCloudService.php',
59
+ 'WebPConvert\\Convert\\ConverterFactory' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/ConverterFactory.php',
60
+ 'WebPConvert\\Convert\\Converters\\AbstractConverter' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Converters/AbstractConverter.php',
61
+ 'WebPConvert\\Convert\\Converters\\BaseTraits\\AutoQualityTrait' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Converters/BaseTraits/AutoQualityTrait.php',
62
+ 'WebPConvert\\Convert\\Converters\\BaseTraits\\DestinationPreparationTrait' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Converters/BaseTraits/DestinationPreparationTrait.php',
63
+ 'WebPConvert\\Convert\\Converters\\BaseTraits\\LoggerTrait' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Converters/BaseTraits/LoggerTrait.php',
64
+ 'WebPConvert\\Convert\\Converters\\BaseTraits\\OptionsTrait' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Converters/BaseTraits/OptionsTrait.php',
65
+ 'WebPConvert\\Convert\\Converters\\BaseTraits\\WarningLoggerTrait' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Converters/BaseTraits/WarningLoggerTrait.php',
66
+ 'WebPConvert\\Convert\\Converters\\ConverterTraits\\CloudConverterTrait' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Converters/ConverterTraits/CloudConverterTrait.php',
67
+ 'WebPConvert\\Convert\\Converters\\ConverterTraits\\CurlTrait' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Converters/ConverterTraits/CurlTrait.php',
68
+ 'WebPConvert\\Convert\\Converters\\ConverterTraits\\EncodingAutoTrait' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Converters/ConverterTraits/EncodingAutoTrait.php',
69
+ 'WebPConvert\\Convert\\Converters\\ConverterTraits\\ExecTrait' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Converters/ConverterTraits/ExecTrait.php',
70
+ 'WebPConvert\\Convert\\Converters\\Cwebp' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Converters/Cwebp.php',
71
+ 'WebPConvert\\Convert\\Converters\\Ewww' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Converters/Ewww.php',
72
+ 'WebPConvert\\Convert\\Converters\\Gd' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Converters/Gd.php',
73
+ 'WebPConvert\\Convert\\Converters\\Gmagick' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Converters/Gmagick.php',
74
+ 'WebPConvert\\Convert\\Converters\\GmagickBinary' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Converters/GmagickBinary.php',
75
+ 'WebPConvert\\Convert\\Converters\\GraphicsMagick' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Converters/GraphicsMagick.php',
76
+ 'WebPConvert\\Convert\\Converters\\ImageMagick' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Converters/ImageMagick.php',
77
+ 'WebPConvert\\Convert\\Converters\\Imagick' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Converters/Imagick.php',
78
+ 'WebPConvert\\Convert\\Converters\\ImagickBinary' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Converters/ImagickBinary.php',
79
+ 'WebPConvert\\Convert\\Converters\\Stack' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Converters/Stack.php',
80
+ 'WebPConvert\\Convert\\Converters\\Vips' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Converters/Vips.php',
81
+ 'WebPConvert\\Convert\\Converters\\Wpc' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Converters/Wpc.php',
82
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailedException' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailedException.php',
83
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\ConversionSkippedException' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/ConversionSkippedException.php',
84
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\ConverterNotOperationalException' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/ConverterNotOperationalException.php',
85
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\ConverterNotOperational\\InvalidApiKeyException' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/ConverterNotOperational/InvalidApiKeyException.php',
86
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\ConverterNotOperational\\SystemRequirementsNotMetException' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/ConverterNotOperational/SystemRequirementsNotMetException.php',
87
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\FileSystemProblemsException' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/FileSystemProblemsException.php',
88
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\FileSystemProblems\\CreateDestinationFileException' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/FileSystemProblems/CreateDestinationFileException.php',
89
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\FileSystemProblems\\CreateDestinationFolderException' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/FileSystemProblems/CreateDestinationFolderException.php',
90
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\InvalidInputException' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/InvalidInputException.php',
91
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\InvalidInput\\ConverterNotFoundException' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/InvalidInput/ConverterNotFoundException.php',
92
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\InvalidInput\\InvalidImageTypeException' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/InvalidInput/InvalidImageTypeException.php',
93
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\InvalidInput\\TargetNotFoundException' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/InvalidInput/TargetNotFoundException.php',
94
+ 'WebPConvert\\Convert\\Helpers\\JpegQualityDetector' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Helpers/JpegQualityDetector.php',
95
+ 'WebPConvert\\Convert\\Helpers\\PhpIniSizes' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Helpers/PhpIniSizes.php',
96
+ 'WebPConvert\\Exceptions\\InvalidInputException' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Exceptions/InvalidInputException.php',
97
+ 'WebPConvert\\Exceptions\\InvalidInput\\InvalidImageTypeException' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Exceptions/InvalidInput/InvalidImageTypeException.php',
98
+ 'WebPConvert\\Exceptions\\InvalidInput\\TargetNotFoundException' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Exceptions/InvalidInput/TargetNotFoundException.php',
99
+ 'WebPConvert\\Exceptions\\WebPConvertException' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Exceptions/WebPConvertException.php',
100
+ 'WebPConvert\\Helpers\\InputValidator' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Helpers/InputValidator.php',
101
+ 'WebPConvert\\Helpers\\MimeType' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Helpers/MimeType.php',
102
+ 'WebPConvert\\Helpers\\PathChecker' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Helpers/PathChecker.php',
103
+ 'WebPConvert\\Loggers\\BaseLogger' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Loggers/BaseLogger.php',
104
+ 'WebPConvert\\Loggers\\BufferLogger' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Loggers/BufferLogger.php',
105
+ 'WebPConvert\\Loggers\\EchoLogger' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Loggers/EchoLogger.php',
106
+ 'WebPConvert\\Options\\ArrayOption' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Options/ArrayOption.php',
107
+ 'WebPConvert\\Options\\BooleanOption' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Options/BooleanOption.php',
108
+ 'WebPConvert\\Options\\Exceptions\\InvalidOptionTypeException' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Options/Exceptions/InvalidOptionTypeException.php',
109
+ 'WebPConvert\\Options\\Exceptions\\InvalidOptionValueException' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Options/Exceptions/InvalidOptionValueException.php',
110
+ 'WebPConvert\\Options\\Exceptions\\OptionNotFoundException' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Options/Exceptions/OptionNotFoundException.php',
111
+ 'WebPConvert\\Options\\GhostOption' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Options/GhostOption.php',
112
+ 'WebPConvert\\Options\\IntegerOption' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Options/IntegerOption.php',
113
+ 'WebPConvert\\Options\\IntegerOrNullOption' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Options/IntegerOrNullOption.php',
114
+ 'WebPConvert\\Options\\MetadataOption' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Options/MetadataOption.php',
115
+ 'WebPConvert\\Options\\Option' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Options/Option.php',
116
+ 'WebPConvert\\Options\\Options' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Options/Options.php',
117
+ 'WebPConvert\\Options\\QualityOption' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Options/QualityOption.php',
118
+ 'WebPConvert\\Options\\SensitiveArrayOption' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Options/SensitiveArrayOption.php',
119
+ 'WebPConvert\\Options\\SensitiveStringOption' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Options/SensitiveStringOption.php',
120
+ 'WebPConvert\\Options\\StringOption' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Options/StringOption.php',
121
+ 'WebPConvert\\Serve\\Exceptions\\ServeFailedException' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Serve/Exceptions/ServeFailedException.php',
122
+ 'WebPConvert\\Serve\\Header' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Serve/Header.php',
123
+ 'WebPConvert\\Serve\\Report' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Serve/Report.php',
124
+ 'WebPConvert\\Serve\\ServeConvertedWebP' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Serve/ServeConvertedWebP.php',
125
+ 'WebPConvert\\Serve\\ServeConvertedWebPWithErrorHandling' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Serve/ServeConvertedWebPWithErrorHandling.php',
126
+ 'WebPConvert\\Serve\\ServeFile' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Serve/ServeFile.php',
127
+ 'WebPConvert\\WebPConvert' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/WebPConvert.php',
128
+ );
129
+
130
  public static function getInitializer(ClassLoader $loader)
131
  {
132
  return \Closure::bind(function () use ($loader) {
133
+ $loader->prefixLengthsPsr4 = ComposerStaticInit8fd167583ae3bd095a84a87a56a51e7c::$prefixLengthsPsr4;
134
+ $loader->prefixDirsPsr4 = ComposerStaticInit8fd167583ae3bd095a84a87a56a51e7c::$prefixDirsPsr4;
135
+ $loader->classMap = ComposerStaticInit8fd167583ae3bd095a84a87a56a51e7c::$classMap;
136
 
137
  }, null, ClassLoader::class);
138
  }
vendor/composer/installed.json CHANGED
@@ -155,7 +155,7 @@
155
  "test": "Launches the preconfigured PHPUnit"
156
  }
157
  },
158
- "installation-source": "source",
159
  "autoload": {
160
  "psr-4": {
161
  "WebPConvert\\": "src/"
@@ -226,7 +226,7 @@
226
  "test": "Launches the preconfigured PHPUnit"
227
  }
228
  },
229
- "installation-source": "source",
230
  "autoload": {
231
  "psr-4": {
232
  "WebPConvertCloudService\\": "src/"
155
  "test": "Launches the preconfigured PHPUnit"
156
  }
157
  },
158
+ "installation-source": "dist",
159
  "autoload": {
160
  "psr-4": {
161
  "WebPConvert\\": "src/"
226
  "test": "Launches the preconfigured PHPUnit"
227
  }
228
  },
229
+ "installation-source": "dist",
230
  "autoload": {
231
  "psr-4": {
232
  "WebPConvertCloudService\\": "src/"
vendor/rosell-dk/webp-convert-cloud-service/docs/api.md DELETED
@@ -1,103 +0,0 @@
1
- Conversion is done by requesting the script file you created over http(s) (ie `https://wpc.example.com/wpc.php`).
2
- The following is expected in the POST:
3
-
4
-
5
- ## Get the api version
6
- Getting api version bypasses the access-checks.
7
- ```
8
- curl --form action="api-version" http://wpc.example.com/wpc.php
9
- ```
10
-
11
- It returns the major version of the current release. For release 1.1, it will return '1'.
12
- The method was not available in v0.1.
13
-
14
-
15
- ## Check access
16
- If you have set *require-api-key-to-be-crypted-in-transfer* to `false`, you can test access like this:
17
-
18
- ```
19
- curl --form action="check-access" --form api-key="my dog is white" http://wpc.example.com/wpc.php
20
- ```
21
-
22
- Otherwise, it gets more complicated. You will then have to provide "api-key-crypted" and "salt". "api-key-crypted" must be crypted with blowfish, and with salt stripped off. In php, it is calculated like this:
23
-
24
- ```php
25
- $apiKey = 'my dog is white';
26
- $salt = "whatever-but-make-it-unique-for-each-request";
27
- $cryptedKey = substr(crypt($apiKey, '$2y$10$' . $salt . '$'), 28);
28
- ```
29
-
30
- ## Converting an image
31
- To convert an image, you must set action to "convert", and supply a file.
32
- The method also accepts an "options" argument (json format), which overrides *webp-convert* options set in the configuration.
33
-
34
- Example:
35
- ```
36
- curl --form action="convert" --form api-key="my dog is white" --form file=@test.jpg http://wpc.example.com/wpc.php > test.webp
37
- ```
38
-
39
- If you get a corrupt file, then it is probably because the output contains an error message. To see it, run the above command again, but remove the piping of the output to a file.
40
-
41
-
42
- ### Usage example (PHP)
43
-
44
- ```php
45
-
46
- function createRandomSaltForBlowfish() {
47
- $salt = '';
48
- $validCharsForSalt = array_merge(
49
- range('A', 'Z'),
50
- range('a', 'z'),
51
- range('0', '9'),
52
- ['.', '/']
53
- );
54
-
55
- for ($i=0; $i<22; $i++) {createRandomSaltForBlowfish
56
- $salt .= $validCharsForSalt[array_rand($validCharsForSalt)];
57
- }
58
- return $salt;
59
- }
60
-
61
- $source = __DIR__ . 'test.jpg';
62
- $destination = __DIR__ . 'test.jpg.webp';
63
- $url = 'http://example.com/wpc.php';
64
- $apiKey = 'my dog is white';
65
-
66
- $salt = createRandomSaltForBlowfish();
67
- // Strip off the first 28 characters (the first 6 are always "$2y$10$". The next 22 is the salt)
68
- $apiKeyCrypted = substr(crypt($apiKey, '$2y$10$' . $salt . '$'), 28);
69
-
70
-
71
- $ch = curl_init();
72
- curl_setopt_array($ch, [
73
- CURLOPT_URL => 'http://example.com/wpc.php',
74
- CURLOPT_POST => 1,
75
- CURLOPT_POSTFIELDS => [
76
- 'action' => 'convert',
77
- 'file' => curl_file_create($source),
78
- 'salt' => $salt,
79
- 'api-key-crypted' => $apiKeyCrypted,
80
- 'options' => json_encode(array(
81
- 'quality' => 'auto',
82
- ))
83
- ],
84
- CURLOPT_BINARYTRANSFER => true,
85
- CURLOPT_RETURNTRANSFER => true,
86
- CURLOPT_HEADER => false,
87
- CURLOPT_SSL_VERIFYPEER => false
88
- ]);
89
-
90
- $response = curl_exec($ch);
91
-
92
- // The WPC cloud service either returns an image or an error message
93
- // Verify that we got an image back.
94
- if (curl_getinfo($ch, CURLINFO_CONTENT_TYPE) == 'application/octet-stream') {
95
- $success = file_put_contents($destination, $response);
96
- }
97
- else {
98
- // show error response
99
- echo $response;
100
- }
101
-
102
- curl_close($ch);
103
- ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/rosell-dk/webp-convert-cloud-service/docs/development.md DELETED
@@ -1,51 +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
- ## Unit Testing
18
- To run all the unit tests do this:
19
- ```
20
- composer test
21
- ```
22
-
23
- Individual test files can be executed like this:
24
- ```
25
- composer test tests/Converters/WPCTest
26
- composer test tests/Serve/ServeConvertedTest
27
- ```
28
-
29
- ## Coding styles
30
- WebPConvert complies with the [PSR-2](https://www.php-fig.org/psr/psr-2/) coding standard.
31
-
32
- To validate coding style of all files, do this:
33
- ```
34
- composer phpcs src
35
- ```
36
-
37
- To automatically fix the coding style of all files, using [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer), do this:
38
- ```
39
- composer phpcbf src
40
- ```
41
-
42
- Or, alternatively, you can fix with the use the [PHP-CS-FIXER](https://github.com/FriendsOfPHP/PHP-CS-Fixer) library instead:
43
- ```
44
- composer cs-fix
45
- ```
46
-
47
- ## Running all tests in one command
48
- The following script runs the unit tests, checks the coding styles and validates composer.json. Run this before pushing to github
49
- ```
50
- composer ci
51
- ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/rosell-dk/webp-convert-cloud-service/tests/WebPConvertCloudServiceTest.php DELETED
@@ -1,21 +0,0 @@
1
- <?php
2
-
3
- /**
4
- *
5
- * @link https://github.com/rosell-dk/webp-convert-cloud-service
6
- * @license MIT
7
- */
8
-
9
- namespace WebPConvertCloudService\Tests;
10
-
11
- use WebPConvertCloudService\WebPConvertCloudService;
12
- use PHPUnit\Framework\TestCase;
13
-
14
- class WebPConvertCloudServiceTest extends TestCase
15
- {
16
- public function testLogic()
17
- {
18
- $this->assertFalse(false);
19
- }
20
-
21
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/rosell-dk/webp-convert/docs/development.md DELETED
@@ -1,78 +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
- ## The builds
18
- For those old-schoolers that prefers one packaged file containing all the code - easily uploaded via ftp - we are maintaining `build/webp-convert.inc`.
19
-
20
- It is an aggregation of all the php files needed, with base classes on top. It also includes the files in vendor/rosell-dk/image-mime-type-guesser.
21
-
22
- We also maintain `build/webp-on-demand-1.inc` (which only consists of a few classes) and `build/webp-on-demand-2.inc` (which is loaded by webp-on-demand-2, when a conversion is needed, and contains the rest of the library).
23
-
24
- Whenever code is changed in `src` - or at least, whenever a new release is released, we must rebuild these files. This can be done like this:
25
-
26
- ```
27
- composer build
28
- ```
29
-
30
- This runs `build-scripts/build-webp-on-demand.php`.
31
- That file needs maintaining when new base classes arrives, new folders, or new dependencies.
32
-
33
-
34
- ## Unit Testing
35
- To run all the unit tests do this:
36
- ```
37
- composer test
38
- ```
39
- This also runs tests on the builds.
40
-
41
-
42
- Individual test files can be executed like this:
43
- ```
44
- composer phpunit tests/Convert/Converters/WPCTest
45
- composer phpunit tests/Serve/ServeConvertedTest
46
- ```
47
-
48
-
49
- ## Coding styles
50
- WebPConvert complies with the [PSR-2](https://www.php-fig.org/psr/psr-2/) coding standard.
51
-
52
- To validate coding style of all files, do this:
53
- ```
54
- composer phpcs src
55
- ```
56
-
57
- To automatically fix the coding style of all files, using [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer), do this:
58
- ```
59
- composer phpcbf src
60
- ```
61
-
62
- Or, alternatively, you can fix with the use the [PHP-CS-FIXER](https://github.com/FriendsOfPHP/PHP-CS-Fixer) library instead:
63
- ```
64
- composer cs-fix
65
- ```
66
-
67
- ## Running all tests in one command
68
- The following script runs the unit tests, checks the coding styles, validates `composer.json` and runs the builds.
69
- Run this before pushing anything to github. "ci" btw stands for *continuous integration*.
70
- ```
71
- composer ci
72
- ```
73
-
74
- ## Generating api docs
75
- Install phpdox and run it in the project root:
76
- ```
77
- phpdox
78
- ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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* &ndash; 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,218 +0,0 @@
1
- # Introduction to converting with WebPConvert
2
-
3
- **NOTE: This document only applies to the upcoming 2.0 version**
4
-
5
- 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:
6
-
7
- ```php
8
- use WebPConvert\Convert\Converters\Gd;
9
-
10
- Gd::convert($source, $destination, $options=[], $logger=null);
11
- ```
12
-
13
- 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.
14
-
15
- ## Insights to the process
16
- 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:
17
-
18
- ```php
19
- use WebPConvert\Convert\Converters\Gd;
20
- use WebPConvert\Loggers\EchoLogger;
21
-
22
- Gd::convert($source, $destination, $options=[], new EchoLogger());
23
- ```
24
-
25
- It will output something like this:
26
-
27
- ```text
28
- GD Version: 2.2.5
29
- image is true color
30
- Quality set to same as source: 61
31
-
32
- Converted image in 20 ms, reducing file size with 34% (went from 12 kb to 8 kb)
33
- ```
34
-
35
- ## The stack converter
36
- 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.
37
-
38
- The stack converter has two special options:
39
-
40
- | option | description |
41
- | ------------------------- | ----------- |
42
- | converters (array) | Converters to try (ids or class names, in case you have your own custom converter) |
43
- | converter-options (array) | Extra options for specific converters. |
44
-
45
- Alternatively to the converter-options array, you can simply prefix options with the converter id.
46
-
47
- 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.
48
-
49
- ### Example:
50
-
51
- ```php
52
- <?php
53
- use WebPConvert\Convert\Converters\Stack;
54
-
55
- Stack::convert($source, $destination, $options = [
56
-
57
- // PS: only set converters if you have strong reasons to do so
58
- 'converters' => [
59
- 'cwebp', 'vips', 'imagick', 'gmagick', 'imagemagick', 'graphicsmagick', 'wpc', 'ewww', 'gd'
60
- ],
61
-
62
- // Any available options can be set here, they dribble down to all converters.
63
- 'metadata' => 'all',
64
-
65
- // To override for specific converter, you can prefix with converter id:
66
- 'cwebp-metadata' => 'exif',
67
-
68
- // This can for example be used for setting ewww api key:
69
- 'ewww-api-key' => 'your-ewww-api-key-here',
70
-
71
- // As an alternative to prefixing, you can use "converter-options" to set a whole bunch of overrides in one go:
72
- 'converter-options' => [
73
- 'wpc' => [
74
- 'crypt-api-key-in-transfer' => true
75
- 'api-key' => 'my dog is white',
76
- 'api-url' => 'https://example.com/wpc.php',
77
- 'api-version' => 1,
78
- ],
79
- ],
80
- ], $logger=null);
81
- ```
82
-
83
- 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"
84
-
85
- To set an environment variable in Apache, you can add a line like this in your `.htaccess` or vhost configuration:
86
- ```
87
- # Set ewww api key for WebP Convert
88
- SetEnv WEBPCONVERT_EWWW_API_KEY yourVerySecretApiKeyGoesHere
89
-
90
- # Set custom path to imagick for WebP Convert
91
- SetEnv WEBPCONVERT_IMAGEMAGICK_PATH /usr/local/bin/magick
92
- ```
93
- To set a constant:
94
- ```php
95
- define('WEBPCONVERT_IMAGEMAGICK_PATH', '/usr/local/bin/magick');
96
- ```
97
-
98
-
99
- ## Configuring the options
100
-
101
- ### Auto quality
102
- **Q:** What do you get if you convert a low quality jpeg (ie q=50) into a high quality webp (ie q=90) ?\
103
- **A:** You maintain the low quality, but you get a large file`
104
-
105
- 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*.
106
-
107
- As unnecessary large conversions are rarely desirable, this library per default converts jpeg files with the same quality level as 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" quality functionality. The *wpc* cloud converter supports auto quality if these are installed on the server that *wpc* is installed on.
108
-
109
- How much can be gained? A lot!
110
- 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, the quality of the webp will be set to 50, and the size will be 34kb. Visually, the results are indistinguable.
111
-
112
- ![A low quality jpeg](https://raw.githubusercontent.com/rosell-dk/webp-convert/master/docs/v2.0/converting/architecture-q50-w600.jpg)
113
-
114
- **Q:** What do you get if you convert an excessively high quality jpeg into an excessively high quality webp?\
115
- **A:** An excessively big file
116
-
117
- The size of a webp file grows enormously with the quality setting. For the web however, a quality above 80 is rarely needed. For this reason the library has a per default limits the quality to the value of the *max-quality* option (default: 85).
118
-
119
- In case quality detection is unavailable, the quality gets the value of the *default-quality* option (default is 70 for JPEGs and 85 for PNGs).
120
-
121
- So, how much can be gained? A lot!
122
- The following excessively high quality jpeg (q=100) weighs 146 kb. Converting it to webp with q=100 results in a 99kb image (this would happen if we had the auto feature, but not the max-quality feature). Converting it to q=85 results in a 40kb image.
123
-
124
- ![A (too) high quality jpeg](https://raw.githubusercontent.com/rosell-dk/webp-convert/master/docs/v2.0/converting/mouse-q100.jpg)
125
-
126
-
127
- ### Auto selecting between lossless/lossy encoding
128
- 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.
129
-
130
- 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".
131
-
132
- 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).
133
-
134
- ![Dice](https://raw.githubusercontent.com/rosell-dk/webp-convert/master/docs/v2.0/converting/dice.png)
135
-
136
- Unless you changed the `near-lossless` option described below, the choice is actually between lossy and *near-lossless*.
137
-
138
- Note that *gd* and *ewww* doesn't 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.
139
-
140
- ### Near-lossless
141
- *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.
142
-
143
- As unnecessary large conversions are rarely desirable, this library per default sets *near-lossless* to 60. To disable near-lossless, set it to 100.
144
-
145
- 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.
146
-
147
- You can read more about the near-lossless mode [here](https://groups.google.com/a/webmproject.org/forum/#!topic/webp-discuss/0GmxDmlexek)
148
-
149
- ### Alpha-quality
150
- All converters, except *gd* and *ewww* supports "alpha-quality" option. This allows lossy compressing of the alpha channel.
151
-
152
- 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.
153
-
154
- 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.
155
-
156
- You can read more about the alpha-quality option [here](https://developers.google.com/speed/webp/docs/cwebp)
157
-
158
-
159
- ### PNG og JPEG-specific options.
160
-
161
- To have options depending on the image type of the source, you can use the `png` and `jpeg` keys.
162
-
163
- The following options mimics the default behaviour:
164
-
165
- ```php
166
- $options = [
167
- 'png' => [
168
- 'encoding' => 'auto', /* Try both lossy and lossless and pick smallest */
169
- 'near-lossless' => 60, /* The level of near-lossless image preprocessing (when trying lossless) */
170
- 'quality' => 85, /* Quality when trying lossy. It is set high because pngs is often selected to ensure high quality */
171
- ],
172
- 'jpeg' => [
173
- '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) */
174
- 'quality' => 'auto', /* Set to same as jpeg (requires imagick or gmagick extension, not necessarily compiled with webp) */
175
- 'max-quality' => 80, /* Only relevant if quality is set to "auto" */
176
- 'default-quality' => 75, /* Fallback quality if quality detection isnt working */
177
- ]
178
- ];
179
- ```
180
-
181
- You can use it for any option, also the converter specific options.
182
- A use case could for example be to use different converters for png and jpeg:
183
-
184
- ```php
185
- $options = [
186
- 'png' => [
187
- 'converters' => ['ewww'],
188
- ],
189
- 'jpeg' => [
190
- 'converters' => ['gd'],
191
- ]
192
- ];
193
- ```
194
-
195
- ## Available options
196
-
197
- **All** available options are documented [here](https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/converting/options.md).
198
-
199
- Here is a quick overview of the few ones discussed here.
200
-
201
- | Option | Default (jpeg) | Default (png) | Description |
202
- | ----------------- | ------------------ | ------------------- | ---------------------------------------------------------------------------------- |
203
- | quality | "auto" | 85 | See the "Auto quality" section above. |
204
- | max-quality | 85 | 85 | Only relevant for jpegs and when quality is set to "auto". |
205
- | default-quality | 75 | 85 | |
206
- | 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*) |
207
- | encoding | "auto" | "auto" | See the "Auto selecting between lossless/lossy encoding" section above |
208
- | jpeg | - | - | Array of options which will be merged into the other options when source is a JPEG |
209
- | png | - | - | Array of options which will be merged into the other options when source is a PNG |
210
- | skip | false | false | If true, conversion will be skipped (ie for skipping png conversion for some converters) |
211
-
212
-
213
- ## More info
214
-
215
- - The complete api is available [here](https://www.bitwise-it.dk/webp-convert/api/2.0/html/index.xhtml)
216
- - 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).
217
- - On the github wiki you can find installation instructions for imagick with webp, gd with webp, etc.
218
- - 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,319 +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
- ### `alpha-quality`
8
- ```
9
- Type: integer (0-100)
10
- Default: 85
11
- Supported by: cwebp, vips, imagick, gmagick, imagemagick and graphicsmagick
12
- ```
13
- Quality of alpha channel. Only relevant for lossy encoding and only relevant for images with alpha channel.<br><br>
14
-
15
- ### `auto-filter`
16
- ```
17
- Type: boolean
18
- Default: false
19
- Supported by: cwebp, vips, imagick, gmagick and imagemagick
20
- ```
21
- 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>
22
-
23
- ### `cwebp-command-line-options`
24
- ```
25
- Type: string
26
- Default: ''
27
- Supported by: cwebp
28
- ```
29
- 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>
30
-
31
- ### `cwebp-rel-path-to-precompiled-binaries`
32
- ```
33
- Type: string
34
- Default: './Binaries'
35
- Supported by: cwebp
36
- ```
37
- 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.
38
-
39
- ### `cwebp-try-common-system-paths`
40
- ```
41
- Type: boolean
42
- Default: true
43
- Supported by: cwebp
44
- ```
45
- If set, the converter will try to look for cwebp in locations such as `/usr/bin/cwebp`.
46
-
47
- ### `cwebp-try-supplied-binary-for-os`
48
- ```
49
- Type: boolean
50
- Default: true
51
- Supported by: cwebp
52
- ```
53
- If set, the converter will try the precompiled cwebp binary that are located in `src/Convert/Converters/Binaries`, for the current OS. The binaries are hash-checked before executed.
54
-
55
- ### `default-quality`
56
- ```
57
- Type: integer (0-100)
58
- Default: 75 for jpegs and 85 for pngs
59
- Supported by: all (cwebp, ewww, gd, gmagick, graphicsmagick, imagick, imagemagick, vips)
60
- ```
61
- Read about this option in the ["auto quality" section in the introduction](https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/converting/introduction-for-converting.md#auto-quality).<br><br>
62
-
63
- ### `encoding`
64
- ```
65
- Type: string ("lossy" | "lossless" | "auto")
66
- Default: "auto"
67
- Supported by: cwebp, vips, imagick, gmagick, imagemagick and graphicsmagick (gd always uses lossy encoding, ewww uses lossless for pngs and lossy for jpegs)
68
- ```
69
- Read 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>
70
-
71
- ### `ewww-api-key`
72
- ```
73
- Type: string
74
- Default: ''
75
- Supported by: ewww
76
- ```
77
- 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.
78
-
79
- Note: This option can alternatively be set through the *EWWW_API_KEY* environment variable.<br><br>
80
-
81
- ### `jpeg`
82
- ```
83
- Type: array
84
- Default: []
85
- Supported by: all
86
- ```
87
- 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.
88
- 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>
89
-
90
- ### `log-call-arguments`
91
- ```
92
- Type: boolean
93
- Default: false
94
- Supported by: all
95
- ```
96
- Enabling this simply puts some more in the log - namely the arguments that was supplied to the call. Sensitive information is starred out.
97
-
98
- ### `low-memory`
99
- ```
100
- Type: boolean
101
- Default: false
102
- Supported by: cwebp, imagick, imagemagick and graphicsmagick
103
- ```
104
- Reduce memory usage of lossy encoding at the cost of ~30% longer encoding time and marginally larger output size. Read more in [the docs](https://developers.google.com/speed/webp/docs/cwebp).<br><br>
105
-
106
- ### `max-quality`
107
- ```
108
- Type: integer (0-100)
109
- Default: 85
110
- Supported by: all (cwebp, ewww, gd, gmagick, graphicsmagick, imagick, imagemagick, vips)
111
- ```
112
- Read about this option in the ["auto quality" section in the introduction](https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/converting/introduction-for-converting.md#auto-quality).<br><br>
113
-
114
- ### `metadata`
115
- ```
116
- Type: string ("all" | "none" | "exif" | "icc" | "xmp")
117
- Default: 'none'
118
- Supported by: 'none' is supported by all. 'all' is supported by all, except *gd*. The rest is only supported by *cwebp*
119
- ```
120
- Only *cwebp* supports all values. *gd* will always remove all metadata. The rest can either strip all or keep all (they will keep all, unless the option is set to *none*).<br><br>
121
-
122
- ### `method`
123
- ```
124
- Type: integer (0-6)
125
- Default: 6
126
- Supported by: cwebp, imagick, gmagick, imagemagick and graphicsmagick
127
- ```
128
- 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.<br><br>
129
-
130
- ### `near-lossless`
131
- ```
132
- Type: integer (0-100)
133
- Default: 60
134
- Supported by: cwebp, vips
135
- ```
136
- 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).<br><br>
137
-
138
- ### `png`
139
- ```
140
- Type: array
141
- Default: []
142
- Supported by: all
143
- ```
144
- 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.
145
- 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>
146
-
147
- ### `preset`
148
- ```
149
- Type: string ('none', 'default', 'photo', 'picture', 'drawing', 'icon' or 'text')
150
- Default: "none"
151
- Supported by: cwebp, vips
152
- ```
153
- 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<br><br>
154
-
155
- ### `quality`
156
- ```
157
- Type: integer (0-100) | "auto"
158
- Default: "auto" for jpegs and 85 for pngs
159
- Supported by: all (cwebp, ewww, gd, gmagick, graphicsmagick, imagick, imagemagick, vips)
160
- ```
161
- Quality for lossy encoding. Read about the "auto" option in the [introduction](https://github.com/rosell-dk/webp-convert/blob/master/docs/v2.0/converting/introduction-for-converting.md#auto-quality).<br><br>
162
-
163
- ### `size-in-percentage`
164
- ```
165
- Type: integer (0-100) | null
166
- Default: null
167
- Supported by: cwebp
168
- ```
169
- 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>
170
-
171
- ### `skip`
172
- ```
173
- Type: boolean
174
- Default: false
175
- Supported by: all
176
- ```
177
- Simply skips conversion. For example this can be used to skip png conversion for a specific converter like this:
178
- ```php
179
- $options = [
180
- 'png' => [
181
- 'gd-skip' => true,
182
- ]
183
- ];
184
- ```
185
-
186
- Or it can be used to skip unwanted converters from the default stack, like this:
187
- ```php
188
- $options = [
189
- 'ewww-skip' => true,
190
- 'wpc-skip' => true,
191
- 'gd-skip' => true,
192
- 'imagick-skip' => true,
193
- 'gmagick-skip' => true,
194
- ];
195
- ```
196
- <br>
197
-
198
- ### `stack-converters`
199
- ```
200
- Type: array
201
- Default: ['cwebp', 'vips', 'imagick', 'gmagick', 'imagemagick', 'graphicsmagick', 'wpc', 'ewww', 'gd']
202
- Supported by: stack
203
- ```
204
-
205
- Specify the converters to try and their order.
206
-
207
- 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.
208
-
209
- The array specifies the converters to try and their order. Each item can be:
210
-
211
- - An id (ie "cwebp")
212
- - A fully qualified class name (in case you have programmed your own custom converter)
213
- - An array with two keys: "converter" and "options".
214
-
215
- `
216
- Alternatively, converter options can be set using the *converter-options* option.
217
-
218
- 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>
219
-
220
- ### `stack-converter-options`
221
- ```
222
- Type: array
223
- Default: []
224
- Supported by: stack
225
- ```
226
- Extra options for specific converters. Example:
227
-
228
- ```php
229
- $options = [
230
- 'converter-options' => [
231
- 'vips' => [
232
- 'quality' => 72
233
- ],
234
- ]
235
- ]
236
- ```
237
- <br>
238
-
239
- ### `stack-extra-converters`
240
- ```
241
- Type: array
242
- Default: []
243
- Supported by: stack
244
- ```
245
- Add extra converters to the bottom of the stack. The items are similar to those in the `stack-converters` option.<br><br>
246
-
247
- ### `stack-preferred-converters`
248
- ```
249
- Type: array
250
- Default: []
251
- Supported by: stack
252
- ```
253
- 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>
254
-
255
- ### `stack-shuffle`
256
- ```
257
- Type: boolean
258
- Default: false
259
- Supported by: stack
260
- ```
261
- 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>
262
-
263
- ### `use-nice`
264
- ```
265
- Type: boolean
266
- Default: false
267
- Supported by: cwebp, graphicsmagick, imagemagick
268
- ```
269
- 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>
270
-
271
- ### `vips-smart-subsample`
272
- ```
273
- Type: boolean
274
- Default: false
275
- Supported by: vips
276
- ```
277
- This feature seems not to be part of *libwebp* but intrinsic to vips. According to the [vips docs](https://jcupitt.github.io/libvips/API/current/VipsForeignSave.html#vips-webpsave), it enables high quality chroma subsampling.<br><br>
278
-
279
- ### `wpc-api-key`
280
- ```
281
- Type: string
282
- Default: ''
283
- Supported by: wpc
284
- ```
285
- 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.
286
-
287
- Note: You can alternatively set the api key through the *WPC_API_KEY* environment variable.<br><br>
288
-
289
- ### `wpc-api-url`
290
- ```
291
- Type: string
292
- Default: ''
293
- Supported by: wpc
294
- ```
295
- Note: You can alternatively set the api url through the *WPC_API_URL* environment variable.<br><br>
296
-
297
- ### `wpc-api-version`
298
- ```
299
- Type: integer (0 - 1)
300
- Default: 0
301
- Supported by: wpc
302
- ```
303
- <br>
304
-
305
- ### `wpc-crypt-api-key-in-transfer`
306
- ```
307
- Type: boolean
308
- Default: false
309
- Supported by: wpc
310
- ```
311
- <br>
312
-
313
- ### `wpc-secret`
314
- ```
315
- Type: string
316
- Default: ''
317
- Supported by: wpc
318
- ```
319
- Note: This option is only relevant for api version 0.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 &ndash; 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,143 +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
- 'convert' => [
41
- // options for converting goes here
42
- 'quality' => 'auto',
43
- ]
44
- ]);
45
- ```
46
-
47
- ## Failure handling
48
- 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.
49
-
50
- 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.
51
-
52
- 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'.
53
-
54
- ## Options influencing the decision process
55
- The default process is like this:
56
-
57
- 1. Is there a file at the destination? If not, trigger conversion
58
- 2. Is the destination older than the source? If yes, delete destination and trigger conversion
59
- 3. Serve the smallest file (destination or source)
60
-
61
- You can influence the process with the following options:
62
-
63
- *reconvert*
64
- If you set *reconvert* to true, the destination and conversion is triggered (between step 1 and 2)
65
-
66
- *serve-original*
67
- If you set *serve-original* to true, process will take its cause from (1) to (2) and then end with source being served.
68
-
69
- *show-report*
70
- 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.
71
-
72
- ## Headers
73
- 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.
74
-
75
- #### *Cache-Control* and *Expires* headers
76
- 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:
77
-
78
- ```
79
- 'serve-image' => [
80
- 'headers' => [
81
- 'cache-control' => true,
82
- 'expires' => false,
83
- ],
84
- 'cache-control-header' => 'public, max-age=31536000',
85
- ],
86
- ```
87
-
88
- 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).
89
-
90
- #### *Vary: Accept* header
91
- 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.
92
-
93
- #### *Last-Modified* header
94
- 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.
95
-
96
- #### *Content-Type* header
97
- 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.
98
-
99
- 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.
100
-
101
- #### *Content-Length* header
102
- 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).
103
-
104
- #### *X-WebP-Convert-Log* headers
105
- The serve method adds *X-WebP-Convert-Log* headers in order to let you know what went on.
106
- For example, if there is no converted image and conversion was successful, the following headers will be sent:
107
-
108
- ```
109
- X-WebP-Convert-Log: Converting (there were no file at destination)
110
- X-WebP-Convert-Log: Serving converted file
111
- ```
112
-
113
- On the next call (presuming the webp has not been deleted), no conversion is needed and you should simply see:
114
- ```
115
- X-WebP-Convert-Log: Serving converted file
116
- ```
117
-
118
- But say that the first conversion actually failed. In case you have permission problems, the output could be:
119
- ```
120
- X-WebP-Convert-Log: Converting (there were no file at destination)
121
- X-WebP-Convert-Log: Failed creating folder. Check the permissions!
122
- X-WebP-Convert-Log: Performing fail action: original
123
- ```
124
-
125
- In case the problem is that the conversion failed, you could see the following:
126
- ```
127
- X-WebP-Convert-Log: Converting (there were no file at destination)
128
- X-WebP-Convert-Log: None of the converters in the stack are operational
129
- X-WebP-Convert-Log: Performing fail action: original
130
- ```
131
-
132
- If you need more info about the conversion process in order to learn why the converters aren't working, enable the *show-report* option.
133
-
134
- 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:
135
- ```
136
- X-WebP-Convert-Log: Source file was not found
137
- X-WebP-Convert-Log: Performing fail action: original
138
- X-WebP-Convert-Log: Performing fail action: throw
139
- ```
140
-
141
- ## More info
142
-
143
- - 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/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/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
- 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:
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 autoloader($class) {
34
- if (strpos($class, 'WebPConvert\\') === 0) {
35
- require_once __DIR__ . '/webp-on-demand-2.inc';
36
- }
37
- }
38
- spl_autoload_register('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 main install instructions from step 3
58
- [Click here to continue...](https://github.com/rosell-dk/webp-on-demand#3-add-redirect-rules)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.14.19
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.14.20
7
  * Author: Bjørn Rosell
8
  * Author URI: https://www.bitwise-it.dk
9
  * License: GPL2