WebP Express - Version 0.14.2

Version Description

(released: 17 jun 2019)

  • Fixed problem with older versions of cwebp
  • Fixed that images was not deleted
  • Fixed cache problem on options page on systems that disables cache busting (it resulted in "SyntaxError: JSON.parse")
Download this release

Release Info

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

Code changes from version 0.14.1 to 0.14.2

Files changed (46) hide show
  1. README.md +9 -0
  2. README.txt +13 -3
  3. composer.json +1 -1
  4. composer.lock +6 -6
  5. lib/alter-html.php +2 -0
  6. lib/classes/AdminInit.php +29 -19
  7. lib/classes/HandleDeleteFileHook.php +2 -2
  8. lib/debug.php +1 -0
  9. lib/options/enqueue_scripts.php +17 -15
  10. lib/options/js/{authorized_sites_bak.js → 0.14.2/authorized_sites_bak.js} +0 -0
  11. lib/options/js/{bulk-convert.js → 0.14.2/bulk-convert.js} +0 -0
  12. lib/options/js/{converters.js → 0.14.2/converters.js} +0 -0
  13. lib/options/js/{das-popup.js → 0.14.2/das-popup.js} +0 -0
  14. lib/options/js/{image-comparison-slider.js → 0.14.2/image-comparison-slider.js} +0 -0
  15. lib/options/js/{page.js → 0.14.2/page.js} +0 -0
  16. lib/options/js/{purge-cache.js → 0.14.2/purge-cache.js} +0 -0
  17. lib/options/js/{sortable.min.js → 0.14.2/sortable.min.js} +0 -0
  18. lib/options/js/{test-convert.js → 0.14.2/test-convert.js} +0 -0
  19. lib/options/js/{whitelist.js → 0.14.2/whitelist.js} +0 -0
  20. lib/options/js/{whitelist_old.js → 0.14.2/whitelist_old.js} +0 -0
  21. lib/options/page-messages.php +2 -0
  22. lib/options/page-welcome.php +2 -0
  23. lib/options/page.php +2 -0
  24. lib/options/submit.php +2 -0
  25. lib/wpc.php +0 -266
  26. vendor/composer/autoload_classmap.php +78 -0
  27. vendor/composer/autoload_static.php +82 -0
  28. vendor/composer/installed.json +6 -6
  29. vendor/rosell-dk/webp-convert/docs/v2.0/converting/introduction-for-converting.md +7 -3
  30. vendor/rosell-dk/webp-convert/src-build/webp-convert.inc +268 -199
  31. vendor/rosell-dk/webp-convert/src-build/webp-on-demand-2.inc +268 -199
  32. vendor/rosell-dk/webp-convert/src/Convert/Converters/AbstractConverter.php +3 -1
  33. vendor/rosell-dk/webp-convert/src/Convert/Converters/Binaries/cwebp-linux +0 -0
  34. vendor/rosell-dk/webp-convert/src/Convert/Converters/ConverterTraits/EncodingAutoTrait.php +2 -0
  35. vendor/rosell-dk/webp-convert/src/Convert/Converters/Cwebp.php +234 -174
  36. vendor/rosell-dk/webp-convert/src/Convert/Converters/Ewww.php +5 -2
  37. vendor/rosell-dk/webp-convert/src/Convert/Converters/GraphicsMagick.php +6 -4
  38. vendor/rosell-dk/webp-convert/src/Convert/Converters/ImageMagick.php +6 -9
  39. vendor/rosell-dk/webp-convert/src/Convert/Converters/Stack.php +2 -2
  40. vendor/rosell-dk/webp-convert/src/Convert/Converters/Wpc.php +10 -4
  41. vendor/rosell-dk/webp-convert/src/Serve/Report.php +0 -3
  42. vendor/rosell-dk/webp-convert/tests/Convert/Converters/EwwwTest.php +2 -2
  43. vendor/rosell-dk/webp-convert/tests/Convert/Converters/WPCTest.php +12 -12
  44. vendor/rosell-dk/webp-convert/tests/Convert/Exposers/CwebpExposer.php +2 -2
  45. web-service/wpc.php +0 -1
  46. webp-express.php +3 -1
README.md CHANGED
@@ -597,6 +597,15 @@ Here are my current plans ahead: 0.15 will probably be a file manager-like inter
597
 
598
  If you wish to affect priorities, it is certainly possible. You can try to argue your case in the forum or you can simply let the money do the talking. By donating as little as a cup of coffee on [ko-fi.com/rosell](https://ko-fi.com/rosell), you can leave a wish. I shall take these wishes into account when prioritizing between new features.
599
 
 
 
 
 
 
 
 
 
 
600
  ## Changes in 0.14.0
601
  - Added new "encoding" option, which can be set to auto. This can in some cases dramatically reduce the size of the webp. It is supported by all converters except ewww and gd.
602
  - Added new "near-lossless" option (only for cwebp and vips). Using this is a good idea for reducing size of lossless webps with an acceptable loss of quality
597
 
598
  If you wish to affect priorities, it is certainly possible. You can try to argue your case in the forum or you can simply let the money do the talking. By donating as little as a cup of coffee on [ko-fi.com/rosell](https://ko-fi.com/rosell), you can leave a wish. I shall take these wishes into account when prioritizing between new features.
599
 
600
+ ## Changes in 0.14.2
601
+ - Fixed problem with older versions of cwebp
602
+ - Fixed that images was not deleted
603
+ - Fixed cache problem on options page on systems that disables cache busting (it resulted in "SyntaxError: JSON.parse")
604
+
605
+
606
+ ## Changes in 0.14.1
607
+ - A little something
608
+
609
  ## Changes in 0.14.0
610
  - Added new "encoding" option, which can be set to auto. This can in some cases dramatically reduce the size of the webp. It is supported by all converters except ewww and gd.
611
  - Added new "near-lossless" option (only for cwebp and vips). Using this is a good idea for reducing size of lossless webps with an acceptable loss of quality
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.0
8
  Requires PHP: 5.6
9
  License: GPLv3
10
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
@@ -605,10 +605,17 @@ Easy enough! - [Go here!](https://ko-fi.com/rosell). Or [here](https://buymeacof
605
 
606
  == Changelog ==
607
 
 
 
 
 
 
 
 
608
  = 0.14.1 =
609
  *(released: 15 jun 2019)*
610
 
611
- * Strengthened security
612
 
613
  = 0.14.0 =
614
  *(released: 15 jun 2019)*
@@ -802,8 +809,11 @@ For older releases, check out changelog.txt
802
 
803
  == Upgrade Notice ==
804
 
 
 
 
805
  = 0.14.1 =
806
- Strengthening security
807
 
808
  = 0.14.0 =
809
  New awesome conversion options that gets you even smaller webp files without compromising quality.
4
  Tags: webp, images, performance
5
  Requires at least: 4.0
6
  Tested up to: 5.2
7
+ Stable tag: 0.14.2
8
  Requires PHP: 5.6
9
  License: GPLv3
10
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
605
 
606
  == Changelog ==
607
 
608
+ = 0.14.2 =
609
+ *(released: 17 jun 2019)*
610
+
611
+ * Fixed problem with older versions of cwebp
612
+ * Fixed that images was not deleted
613
+ * Fixed cache problem on options page on systems that disables cache busting (it resulted in "SyntaxError: JSON.parse")
614
+
615
  = 0.14.1 =
616
  *(released: 15 jun 2019)*
617
 
618
+ * A little something
619
 
620
  = 0.14.0 =
621
  *(released: 15 jun 2019)*
809
 
810
  == Upgrade Notice ==
811
 
812
+ = 0.14.2 =
813
+ A couple of bugfixes
814
+
815
  = 0.14.1 =
816
+ A little something
817
 
818
  = 0.14.0 =
819
  New awesome conversion options that gets you even smaller webp files without compromising quality.
composer.json CHANGED
@@ -4,7 +4,7 @@
4
  "type": "project",
5
  "license": "MIT",
6
  "require": {
7
- "rosell-dk/webp-convert": "^2.0.2",
8
  "rosell-dk/webp-convert-cloud-service": "^2.0.0",
9
  "rosell-dk/dom-util-for-webp": "^0.3.0"
10
  },
4
  "type": "project",
5
  "license": "MIT",
6
  "require": {
7
+ "rosell-dk/webp-convert": "^2.0.3",
8
  "rosell-dk/webp-convert-cloud-service": "^2.0.0",
9
  "rosell-dk/dom-util-for-webp": "^0.3.0"
10
  },
composer.lock CHANGED
@@ -4,7 +4,7 @@
4
  "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
5
  "This file is @generated automatically"
6
  ],
7
- "content-hash": "d1905bfab23d538f20fae2c74bb476a5",
8
  "packages": [
9
  {
10
  "name": "rosell-dk/dom-util-for-webp",
@@ -118,16 +118,16 @@
118
  },
119
  {
120
  "name": "rosell-dk/webp-convert",
121
- "version": "2.0.2",
122
  "source": {
123
  "type": "git",
124
  "url": "https://github.com/rosell-dk/webp-convert.git",
125
- "reference": "50f59ca429ebe2984a4054696db62bcfcf57d299"
126
  },
127
  "dist": {
128
  "type": "zip",
129
- "url": "https://api.github.com/repos/rosell-dk/webp-convert/zipball/50f59ca429ebe2984a4054696db62bcfcf57d299",
130
- "reference": "50f59ca429ebe2984a4054696db62bcfcf57d299",
131
  "shasum": ""
132
  },
133
  "require": {
@@ -190,7 +190,7 @@
190
  "png",
191
  "png2webp"
192
  ],
193
- "time": "2019-06-15T11:45:10+00:00"
194
  },
195
  {
196
  "name": "rosell-dk/webp-convert-cloud-service",
4
  "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
5
  "This file is @generated automatically"
6
  ],
7
+ "content-hash": "195dde623afd5d43ce9443d4b6670585",
8
  "packages": [
9
  {
10
  "name": "rosell-dk/dom-util-for-webp",
118
  },
119
  {
120
  "name": "rosell-dk/webp-convert",
121
+ "version": "2.0.3",
122
  "source": {
123
  "type": "git",
124
  "url": "https://github.com/rosell-dk/webp-convert.git",
125
+ "reference": "3a2c6ab330e4a99dbce1b05c987cad4f799f75ee"
126
  },
127
  "dist": {
128
  "type": "zip",
129
+ "url": "https://api.github.com/repos/rosell-dk/webp-convert/zipball/3a2c6ab330e4a99dbce1b05c987cad4f799f75ee",
130
+ "reference": "3a2c6ab330e4a99dbce1b05c987cad4f799f75ee",
131
  "shasum": ""
132
  },
133
  "require": {
190
  "png",
191
  "png2webp"
192
  ],
193
+ "time": "2019-06-17T08:13:22+00:00"
194
  },
195
  {
196
  "name": "rosell-dk/webp-convert-cloud-service",
lib/alter-html.php CHANGED
@@ -1,5 +1,7 @@
1
  <?php
2
 
 
 
3
  function webPExpressAlterHtml($content) {
4
  // Don't do anything with the RSS feed.
5
  if (is_feed()) {
1
  <?php
2
 
3
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
4
+
5
  function webPExpressAlterHtml($content) {
6
  // Don't do anything with the RSS feed.
7
  if (is_feed()) {
lib/classes/AdminInit.php CHANGED
@@ -43,10 +43,34 @@ class AdminInit
43
 
44
  public static function adminInitHandler()
45
  {
46
- global $pagenow;
47
- if ((('options-general.php' === $pagenow) || (('settings.php' === $pagenow))) && (isset($_GET['page'])) && ('webp_express_settings_page' === $_GET['page'])) {
48
- add_action('admin_enqueue_scripts', array('\WebPExpress\OptionsPage', 'enqueueScripts'));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  }
 
50
  }
51
 
52
  public static function addHooks()
@@ -57,33 +81,19 @@ class AdminInit
57
  register_deactivation_hook(WEBPEXPRESS_PLUGIN, array('\WebPExpress\PluginDeactivate', 'deactivate'));
58
  register_uninstall_hook(WEBPEXPRESS_PLUGIN, array('\WebPExpress\PluginUninstall', 'uninstall'));
59
 
60
- // Hooks related to options page
 
61
  if (Multisite::isNetworkActivated()) {
62
  add_action("network_admin_menu", array('\WebPExpress\AdminUi', 'networAdminMenuHook'));
63
  } else {
64
  add_action("admin_menu", array('\WebPExpress\AdminUi', 'adminMenuHook'));
65
  }
66
- add_action("admin_post_webpexpress_settings_submit", array('\WebPExpress\OptionsPageHooks', 'submitHandler'));
67
- add_action("admin_init", array('\WebPExpress\AdminInit', 'adminInitHandler'));
68
-
69
 
70
  // Print pending messages, if any
71
  if (Option::getOption('webp-express-messages-pending')) {
72
  add_action(Multisite::isNetworkActivated() ? 'network_admin_notices' : 'admin_notices', array('\WebPExpress\Messenger', 'printPendingMessages'));
73
  }
74
 
75
- // Add settings link on the plugins page
76
- add_filter('plugin_action_links_' . plugin_basename(WEBPEXPRESS_PLUGIN), array('\WebPExpress\AdminUi', 'pluginActionLinksFilter'), 10, 2);
77
-
78
- // Add settings link in multisite
79
- add_filter('network_admin_plugin_action_links_' . plugin_basename(WEBPEXPRESS_PLUGIN), array('\WebPExpress\AdminUi', 'networkPluginActionLinksFilter'), 10, 2);
80
-
81
- // Ajax actions
82
- add_action('wp_ajax_list_unconverted_files', array('\WebPExpress\BulkConvert', 'processAjaxListUnconvertedFiles'));
83
- add_action('wp_ajax_convert_file', array('\WebPExpress\Convert', 'processAjaxConvertFile'));
84
- add_action('wp_ajax_webpexpress_view_log', array('\WebPExpress\ConvertLog', 'processAjaxViewLog'));
85
- add_action('wp_ajax_webpexpress_purge_cache', array('\WebPExpress\CachePurge', 'processAjaxPurgeCache'));
86
- add_action('wp_ajax_webpexpress_dismiss_message', array('\WebPExpress\DismissableMessages', 'processAjaxDismissMessage'));
87
 
88
  // PS:
89
  // Filters for processing upload hooks in order to convert images upon upload (wp_handle_upload / image_make_intermediate_size)
43
 
44
  public static function adminInitHandler()
45
  {
46
+
47
+ if (current_user_can('manage_options')) {
48
+
49
+ // Hooks related to options page
50
+
51
+ global $pagenow;
52
+ if ((('options-general.php' === $pagenow) || (('settings.php' === $pagenow))) && (isset($_GET['page'])) && ('webp_express_settings_page' === $_GET['page'])) {
53
+ add_action('admin_enqueue_scripts', array('\WebPExpress\OptionsPage', 'enqueueScripts'));
54
+ }
55
+
56
+ add_action("admin_post_webpexpress_settings_submit", array('\WebPExpress\OptionsPageHooks', 'submitHandler'));
57
+
58
+
59
+ // Ajax actions
60
+ add_action('wp_ajax_list_unconverted_files', array('\WebPExpress\BulkConvert', 'processAjaxListUnconvertedFiles'));
61
+ add_action('wp_ajax_convert_file', array('\WebPExpress\Convert', 'processAjaxConvertFile'));
62
+ add_action('wp_ajax_webpexpress_view_log', array('\WebPExpress\ConvertLog', 'processAjaxViewLog'));
63
+ add_action('wp_ajax_webpexpress_purge_cache', array('\WebPExpress\CachePurge', 'processAjaxPurgeCache'));
64
+ add_action('wp_ajax_webpexpress_dismiss_message', array('\WebPExpress\DismissableMessages', 'processAjaxDismissMessage'));
65
+
66
+
67
+ // Add settings link on the plugins page
68
+ add_filter('plugin_action_links_' . plugin_basename(WEBPEXPRESS_PLUGIN), array('\WebPExpress\AdminUi', 'pluginActionLinksFilter'), 10, 2);
69
+
70
+ // Add settings link in multisite
71
+ add_filter('network_admin_plugin_action_links_' . plugin_basename(WEBPEXPRESS_PLUGIN), array('\WebPExpress\AdminUi', 'networkPluginActionLinksFilter'), 10, 2);
72
  }
73
+
74
  }
75
 
76
  public static function addHooks()
81
  register_deactivation_hook(WEBPEXPRESS_PLUGIN, array('\WebPExpress\PluginDeactivate', 'deactivate'));
82
  register_uninstall_hook(WEBPEXPRESS_PLUGIN, array('\WebPExpress\PluginUninstall', 'uninstall'));
83
 
84
+ add_action("admin_init", array('\WebPExpress\AdminInit', 'adminInitHandler'));
85
+
86
  if (Multisite::isNetworkActivated()) {
87
  add_action("network_admin_menu", array('\WebPExpress\AdminUi', 'networAdminMenuHook'));
88
  } else {
89
  add_action("admin_menu", array('\WebPExpress\AdminUi', 'adminMenuHook'));
90
  }
 
 
 
91
 
92
  // Print pending messages, if any
93
  if (Option::getOption('webp-express-messages-pending')) {
94
  add_action(Multisite::isNetworkActivated() ? 'network_admin_notices' : 'admin_notices', array('\WebPExpress\Messenger', 'printPendingMessages'));
95
  }
96
 
 
 
 
 
 
 
 
 
 
 
 
 
97
 
98
  // PS:
99
  // Filters for processing upload hooks in order to convert images upon upload (wp_handle_upload / image_make_intermediate_size)
lib/classes/HandleDeleteFileHook.php CHANGED
@@ -17,13 +17,13 @@ class HandleDeleteFileHook
17
  'image/png',
18
  ];
19
  if (!Mime::isOneOfTheseImageMimeTypes($filename, $mimeTypes)) {
20
- return;
21
  }
22
 
23
  $destination = Convert::getDestination($filename);
24
  if (!unlink($destination)) {
25
  error_log('WebP Express failed deleting webp:' . $destination);
26
  }
27
-
28
  }
29
  }
17
  'image/png',
18
  ];
19
  if (!Mime::isOneOfTheseImageMimeTypes($filename, $mimeTypes)) {
20
+ return $filename;
21
  }
22
 
23
  $destination = Convert::getDestination($filename);
24
  if (!unlink($destination)) {
25
  error_log('WebP Express failed deleting webp:' . $destination);
26
  }
27
+ return $filename;
28
  }
29
  }
lib/debug.php CHANGED
@@ -1,5 +1,6 @@
1
  <?php
2
 
 
3
 
4
  function webpexpress_activated() {
5
  update_option( 'webp-express-activation-error', ob_get_contents() );
1
  <?php
2
 
3
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
4
 
5
  function webpexpress_activated() {
6
  update_option( 'webp-express-activation-error', ob_get_contents() );
lib/options/enqueue_scripts.php CHANGED
@@ -1,13 +1,15 @@
1
  <?php
2
 
 
 
3
  include_once __DIR__ . '/../classes/Paths.php';
4
  use \WebPExpress\Paths;
5
 
6
  include_once __DIR__ . '/../classes/Config.php';
7
  use \WebPExpress\Config;
8
 
9
- $version = '0.14.1';
10
-
11
 
12
  if (!function_exists('webp_express_add_inline_script')) {
13
  function webp_express_add_inline_script($id, $script, $position) {
@@ -20,10 +22,10 @@ if (!function_exists('webp_express_add_inline_script')) {
20
  }
21
  }
22
 
23
- wp_register_script('sortable', plugins_url('js/sortable.min.js', __FILE__), [], '1.9.0');
24
  wp_enqueue_script('sortable');
25
 
26
- wp_register_script('daspopup', plugins_url('js/das-popup.js', __FILE__), [], $version);
27
  wp_enqueue_script('daspopup');
28
 
29
  $config = Config::getConfigForOptionsPage();
@@ -42,22 +44,22 @@ if (!(isset($config['operation-mode']) && ($config['operation-mode'] == 'no-conv
42
  }
43
 
44
  // Converters
45
- wp_register_script('converters', plugins_url('js/converters.js', __FILE__), ['sortable','daspopup'], $version);
46
  webp_express_add_inline_script('converters', 'window.webpExpressPaths = ' . json_encode(Paths::getUrlsAndPathsForTheJavascript()) . ';', 'before');
47
  webp_express_add_inline_script('converters', 'window.converters = ' . json_encode($config['converters']) . ';', 'before');
48
  wp_enqueue_script('converters');
49
 
50
  // Whitelist
51
- wp_register_script('whitelist', plugins_url('js/whitelist.js', __FILE__), ['daspopup'], $version);
52
  webp_express_add_inline_script('whitelist', 'window.whitelist = ' . json_encode($config['web-service']['whitelist']) . ';', 'before');
53
  wp_enqueue_script('whitelist');
54
 
55
  // bulk convert
56
- wp_register_script('bulkconvert', plugins_url('js/bulk-convert.js', __FILE__), [], $version);
57
  wp_enqueue_script('bulkconvert');
58
 
59
  // test convert
60
- wp_register_script('testconvert', plugins_url('js/test-convert.js', __FILE__), [], $version);
61
  $canDisplayWebp = (isset($_SERVER['HTTP_ACCEPT']) && (strpos($_SERVER['HTTP_ACCEPT'], 'image/webp') !== false ));
62
 
63
  /*
@@ -72,20 +74,20 @@ if (!(isset($config['operation-mode']) && ($config['operation-mode'] == 'no-conv
72
  webp_express_add_inline_script('testconvert', 'window.canDisplayWebp = ' . ($canDisplayWebp ? 'true' : 'false') . ';', 'before');
73
  wp_enqueue_script('testconvert');
74
 
75
- wp_register_script('image-comparison-slider', plugins_url('js/image-comparison-slider.js', __FILE__), [], $version);
76
  wp_enqueue_script('image-comparison-slider');
77
 
78
 
79
  // purge cache
80
- wp_register_script('purgecache', plugins_url('js/purge-cache.js', __FILE__), [], $version);
81
  wp_enqueue_script('purgecache');
82
 
83
  }
84
 
85
- //wp_register_script('api_keys', plugins_url('js/api-keys.js', __FILE__), ['daspopup'], '0.7.0-dev8');
86
  //wp_enqueue_script('api_keys');
87
 
88
- wp_register_script( 'page', plugins_url('js/page.js', __FILE__), [], $version);
89
  webp_express_add_inline_script(
90
  'page',
91
  'window.webpExpressAjaxConvertNonce = "' . wp_create_nonce('webpexpress-ajax-convert-nonce') . '";' .
@@ -98,13 +100,13 @@ wp_enqueue_script('page');
98
 
99
 
100
  // Register styles
101
- wp_register_style('webp-express-options-page-css', plugins_url('css/webp-express-options-page.css', __FILE__), null, $version);
102
  wp_enqueue_style('webp-express-options-page-css');
103
 
104
- wp_register_style('test-convert-css', plugins_url('css/test-convert.css', __FILE__), null, $version);
105
  wp_enqueue_style('test-convert-css');
106
 
107
- wp_register_style('das-popup-css', plugins_url('css/das-popup.css', __FILE__), null, $version);
108
  wp_enqueue_style('das-popup-css');
109
 
110
  add_thickbox();
1
  <?php
2
 
3
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
4
+
5
  include_once __DIR__ . '/../classes/Paths.php';
6
  use \WebPExpress\Paths;
7
 
8
  include_once __DIR__ . '/../classes/Config.php';
9
  use \WebPExpress\Config;
10
 
11
+ $ver = '1';
12
+ $jsDir = 'js/0.14.2';
13
 
14
  if (!function_exists('webp_express_add_inline_script')) {
15
  function webp_express_add_inline_script($id, $script, $position) {
22
  }
23
  }
24
 
25
+ wp_register_script('sortable', plugins_url($jsDir . '/sortable.min.js', __FILE__), [], '1.9.0');
26
  wp_enqueue_script('sortable');
27
 
28
+ wp_register_script('daspopup', plugins_url($jsDir . '/das-popup.js', __FILE__), [], $ver);
29
  wp_enqueue_script('daspopup');
30
 
31
  $config = Config::getConfigForOptionsPage();
44
  }
45
 
46
  // Converters
47
+ wp_register_script('converters', plugins_url($jsDir . '/converters.js', __FILE__), ['sortable','daspopup'], $ver);
48
  webp_express_add_inline_script('converters', 'window.webpExpressPaths = ' . json_encode(Paths::getUrlsAndPathsForTheJavascript()) . ';', 'before');
49
  webp_express_add_inline_script('converters', 'window.converters = ' . json_encode($config['converters']) . ';', 'before');
50
  wp_enqueue_script('converters');
51
 
52
  // Whitelist
53
+ wp_register_script('whitelist', plugins_url($jsDir . '/whitelist.js', __FILE__), ['daspopup'], $ver);
54
  webp_express_add_inline_script('whitelist', 'window.whitelist = ' . json_encode($config['web-service']['whitelist']) . ';', 'before');
55
  wp_enqueue_script('whitelist');
56
 
57
  // bulk convert
58
+ wp_register_script('bulkconvert', plugins_url($jsDir . '/bulk-convert.js', __FILE__), [], $ver);
59
  wp_enqueue_script('bulkconvert');
60
 
61
  // test convert
62
+ wp_register_script('testconvert', plugins_url($jsDir . '/test-convert.js', __FILE__), [], $ver);
63
  $canDisplayWebp = (isset($_SERVER['HTTP_ACCEPT']) && (strpos($_SERVER['HTTP_ACCEPT'], 'image/webp') !== false ));
64
 
65
  /*
74
  webp_express_add_inline_script('testconvert', 'window.canDisplayWebp = ' . ($canDisplayWebp ? 'true' : 'false') . ';', 'before');
75
  wp_enqueue_script('testconvert');
76
 
77
+ wp_register_script('image-comparison-slider', plugins_url($jsDir . '/image-comparison-slider.js', __FILE__), [], $ver);
78
  wp_enqueue_script('image-comparison-slider');
79
 
80
 
81
  // purge cache
82
+ wp_register_script('purgecache', plugins_url($jsDir . '/purge-cache.js', __FILE__), [], $ver);
83
  wp_enqueue_script('purgecache');
84
 
85
  }
86
 
87
+ //wp_register_script('api_keys', plugins_url($jsDir . 'api-keys.js', __FILE__), ['daspopup'], '0.7.0-dev8');
88
  //wp_enqueue_script('api_keys');
89
 
90
+ wp_register_script( 'page', plugins_url($jsDir . '/page.js', __FILE__), [], $ver);
91
  webp_express_add_inline_script(
92
  'page',
93
  'window.webpExpressAjaxConvertNonce = "' . wp_create_nonce('webpexpress-ajax-convert-nonce') . '";' .
100
 
101
 
102
  // Register styles
103
+ wp_register_style('webp-express-options-page-css', plugins_url('css/webp-express-options-page.css', __FILE__), null, $ver);
104
  wp_enqueue_style('webp-express-options-page-css');
105
 
106
+ wp_register_style('test-convert-css', plugins_url('css/test-convert.css', __FILE__), null, $ver);
107
  wp_enqueue_style('test-convert-css');
108
 
109
+ wp_register_style('das-popup-css', plugins_url('css/das-popup.css', __FILE__), null, $ver);
110
  wp_enqueue_style('das-popup-css');
111
 
112
  add_thickbox();
lib/options/js/{authorized_sites_bak.js → 0.14.2/authorized_sites_bak.js} RENAMED
File without changes
lib/options/js/{bulk-convert.js → 0.14.2/bulk-convert.js} RENAMED
File without changes
lib/options/js/{converters.js → 0.14.2/converters.js} RENAMED
File without changes
lib/options/js/{das-popup.js → 0.14.2/das-popup.js} RENAMED
File without changes
lib/options/js/{image-comparison-slider.js → 0.14.2/image-comparison-slider.js} RENAMED
File without changes
lib/options/js/{page.js → 0.14.2/page.js} RENAMED
File without changes
lib/options/js/{purge-cache.js → 0.14.2/purge-cache.js} RENAMED
File without changes
lib/options/js/{sortable.min.js → 0.14.2/sortable.min.js} RENAMED
File without changes
lib/options/js/{test-convert.js → 0.14.2/test-convert.js} RENAMED
File without changes
lib/options/js/{whitelist.js → 0.14.2/whitelist.js} RENAMED
File without changes
lib/options/js/{whitelist_old.js → 0.14.2/whitelist_old.js} RENAMED
File without changes
lib/options/page-messages.php CHANGED
@@ -1,5 +1,7 @@
1
  <?php
2
 
 
 
3
  use \WebPExpress\CapabilityTest;
4
  use \WebPExpress\Config;
5
  use \WebPExpress\ConvertersHelper;
1
  <?php
2
 
3
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
4
+
5
  use \WebPExpress\CapabilityTest;
6
  use \WebPExpress\Config;
7
  use \WebPExpress\ConvertersHelper;
lib/options/page-welcome.php CHANGED
@@ -1,5 +1,7 @@
1
  <?php
2
 
 
 
3
  use \WebPExpress\Paths;
4
  use \WebPExpress\Config;
5
  use \WebPExpress\State;
1
  <?php
2
 
3
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
4
+
5
  use \WebPExpress\Paths;
6
  use \WebPExpress\Config;
7
  use \WebPExpress\State;
lib/options/page.php CHANGED
@@ -1,5 +1,7 @@
1
  <?php
2
 
 
 
3
  use \WebPExpress\Config;
4
  use \WebPExpress\ConvertersHelper;
5
  use \WebPExpress\FileHelper;
1
  <?php
2
 
3
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
4
+
5
  use \WebPExpress\Config;
6
  use \WebPExpress\ConvertersHelper;
7
  use \WebPExpress\FileHelper;
lib/options/submit.php CHANGED
@@ -1,5 +1,7 @@
1
  <?php
2
 
 
 
3
  use \WebPExpress\CacheMover;
4
  use \WebPExpress\CapabilityTest;
5
  use \WebPExpress\Config;
1
  <?php
2
 
3
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
4
+
5
  use \WebPExpress\CacheMover;
6
  use \WebPExpress\CapabilityTest;
7
  use \WebPExpress\Config;
lib/wpc.php DELETED
@@ -1,266 +0,0 @@
1
- <?php
2
-
3
- //ini_set('display_errors', 1);
4
- //error_reporting(E_ALL);
5
-
6
- //require_once( dirname( dirname( __FILE__ ) ) . '/wp-load.php' );
7
-
8
- include_once __DIR__ . '/classes/Config.php';
9
- use \WebPExpress\Config;
10
-
11
- include_once __DIR__ . '/classes/Paths.php';
12
- use \WebPExpress\Paths;
13
-
14
- include_once __DIR__ . '/classes/State.php';
15
- use \WebPExpress\State;
16
-
17
- require_once __DIR__ . '/../vendor/autoload.php';
18
- use WebPConvert\WebPConvert;
19
-
20
-
21
- const ERROR_SERVER_SETUP = 0;
22
- const ERROR_NOT_ALLOWED = 1;
23
- const ERROR_RUNTIME = 2;
24
-
25
- $action = (isset($_POST['action']) ? $_POST['action'] : 'convert');
26
-
27
- if ($action == 'request-access') {
28
- if (!(State::getState('listening', false))) {
29
- exitWithError(ERROR_NOT_ALLOWED, 'Server is not listening for requests');
30
- } else {
31
- State::setState('request', [
32
- 'label' => isset($_POST['label']) ? $_POST['label'] : 'unknown',
33
- 'key' => isset($_POST['key']) ? $_POST['key'] : 'prut2',
34
- 'ip' => $_SERVER['REMOTE_ADDR'],
35
- 'timestamp' => time(),
36
- ]);
37
- $returnObject = [
38
- 'success' => 1,
39
- ];
40
- echo json_encode($returnObject);
41
- die();
42
- }
43
- }
44
-
45
-
46
-
47
- function exitWithError($errorCode, $msg)
48
- {
49
- $returnObject = [
50
- 'success' => 0,
51
- 'errorCode' => $errorCode,
52
- 'errorMessage' => $msg,
53
- ];
54
- echo json_encode($returnObject);
55
- exit;
56
- }
57
-
58
- $config = Config::loadConfig();
59
- if ($config === false) {
60
- if (Config::isConfigFileThere()) {
61
- exitWithError(ERROR_SERVER_SETUP, 'config file could not be loaded.');
62
- } else {
63
- exitWithError(ERROR_SERVER_SETUP, 'config file could not be loaded (its not there): ' . Paths::getConfigFileName());
64
- }
65
- }
66
-
67
- if (!isset($config['wpc'])) {
68
- exitWithError(ERROR_SERVER_SETUP, 'cloud service is not configured');
69
- }
70
-
71
- $wpcOptions = $config['wpc'];
72
-
73
- if (!isset($wpcOptions['enabled']) || $wpcOptions['enabled'] == false) {
74
- exitWithError(ERROR_SERVER_SETUP, 'cloud service is not enabled');
75
- }
76
-
77
- $whitelisted = false;
78
- $password = '';
79
-
80
- /**
81
- * Note about the whitelist:
82
- * It is not unspoofable. But it does not have to be either.
83
- * The extra layer of "security" is added to avoid massive misuse in case that the password
84
- * is leaked. Massive misuse would be if the password where to spread in internet forums, and
85
- * anyone could easily use it. With the whitelist, the password is not enough, you would also
86
- * be needing to know an entry on the whitelist. This could of course also be leaked. But you
87
- * would also need to do the spoofing. This additional step is probably more than most people
88
- * would bother to go through.
89
- */
90
- function testWhitelistEntry($sitePattern) {
91
- if ($sitePattern == '*') {
92
- return true;
93
- }
94
- $regEx = '/^' . str_replace('*', '.*', $sitePattern) . '$/';
95
-
96
- $ip = $_SERVER['REMOTE_ADDR'];
97
- if (preg_match($regEx, $ip)) {
98
- return true;
99
- }
100
-
101
- // If sitePattern looks like a full IP pattern, exit now,
102
- // so the other methods cant be misused with spoofing.
103
- // ^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$
104
- if (preg_match('/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/', $sitePattern)) {
105
- return false;
106
- }
107
- // Also test a nearly full IP pattern.
108
- // As domain names may now start with numbers, theoretically, we could have a domain
109
- // called 123.127.com, and the user might also have 123.127.net, and therefore add
110
- // a rule '123.127.*'.
111
- if (preg_match('/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.?\\*$/', $sitePattern)) {
112
- return false;
113
- }
114
-
115
- // ^(\d{1,3}(\.)?){1,4}\*?$ works in regexr.com, but not here...
116
-
117
- if (isset($_SERVER['REMOTE_HOST'])) {
118
- // REMOTE_HOST is only available if Apache has been configured
119
- // with HostnameLookups = On (in apache.conf).
120
- // It seldom is, as it is not the default, and it is expensive,as at least one
121
- // DNS lookup will be made per request.
122
- // Anyway, here we are, and we have it.
123
- if (preg_match($regEx, $_SERVER['REMOTE_HOST'])) {
124
- return true;
125
- }
126
- }
127
-
128
- // I know, it can easily be spoofed, simply by changing the source code.
129
- // However, encrypting it would not help, as the bandit would already be
130
- // knowing the secret.
131
- // - And $_SERVER['REMOTE_HOST'] is seldom available, and often misleading
132
- // on shared hosts
133
- if (isset($_POST['servername'])) {
134
- $domain = $_POST['servername'];
135
- if (preg_match($regEx, $_POST['servername'])) {
136
- return true;
137
- }
138
- }
139
-
140
- return false;
141
- }
142
-
143
- foreach ($wpcOptions['whitelist'] as $entry) {
144
- if (testWhitelistEntry($entry['site'])) {
145
- $whitelisted = true;
146
- $password = $entry['password'];
147
- break;
148
- }
149
- }
150
-
151
- if (!$whitelisted) {
152
- if (isset($_SERVER['REMOTE_HOST']) && (!empty($_SERVER['REMOTE_HOST']))) {
153
- if (isset($_POST['servername'])) {
154
- exitWithError(ERROR_NOT_ALLOWED, 'Neither your domain (' . $_POST['servername'] . '), the domain of your webhost (' . $_SERVER['REMOTE_HOST'] . ') or your IP (' . $_SERVER['REMOTE_ADDR'] . ') is on the whitelist');
155
- } else {
156
- exitWithError(ERROR_NOT_ALLOWED, 'Neither the domain of your webhost (' . $_SERVER['REMOTE_HOST'] . ') or your IP (' . $_SERVER['REMOTE_ADDR'] . ') is on the whitelist');
157
- }
158
- } else {
159
- if (isset($_POST['servername'])) {
160
- exitWithError(ERROR_NOT_ALLOWED, 'Neither your domain (' . $_POST['servername'] . ') or your IP (' . $_SERVER['REMOTE_ADDR'] . ') is on the whitelist');
161
- } else {
162
- exitWithError(ERROR_NOT_ALLOWED, 'Your IP (' . $_SERVER['REMOTE_ADDR'] . ') is not on the whitelist');
163
- }
164
- }
165
- }
166
-
167
- $uploaddir = Paths::getCacheDirAbs() . '/wpc';
168
-
169
- if (!is_dir($uploaddir)) {
170
- if (!@mkdir($uploaddir, 0775, true)) {
171
- exitWithError(ERROR_SERVER_SETUP, 'Could not create folder for converted files: ' . $uploaddir);
172
- }
173
- @chmod($uploaddir, 0775);
174
- }
175
-
176
-
177
- if (!isset($_POST['hash'])) {
178
- exitWithError(ERROR_NOT_ALLOWED, 'Restricted access. Hash required, but missing');
179
- }
180
-
181
- if (!isset($_FILES['file']['error'])) {
182
- exitWithError(ERROR_RUNTIME, 'Invalid parameters');
183
- }
184
-
185
- if (is_array($_FILES['file']['error'])) {
186
- exitWithError(ERROR_RUNTIME, 'Cannot convert multiple files');
187
- }
188
-
189
- switch ($_FILES['file']['error']) {
190
- case UPLOAD_ERR_OK:
191
- break;
192
- case UPLOAD_ERR_NO_FILE:
193
- exitWithError(ERROR_RUNTIME, 'No file sent');
194
- case UPLOAD_ERR_INI_SIZE:
195
- case UPLOAD_ERR_FORM_SIZE:
196
- exitWithError(ERROR_RUNTIME, 'Exceeded filesize limit.');
197
- default:
198
- exitWithError(ERROR_RUNTIME, 'Unknown error.');
199
- }
200
-
201
- if ($_FILES['file']['size'] == 0) {
202
- exitWithError(ERROR_NOT_ALLOWED, 'File size is zero. Perhaps exceeded filesize limit?');
203
- }
204
- // Undefined | Multiple Files | $_FILES Corruption Attack
205
- // If this request falls under any of them, treat it invalid.
206
- /*if ($_FILES['file']['size'] > 1000000) {
207
- throw new RuntimeException('Exceeded filesize limit.');
208
- }*/
209
-
210
- // DO NOT TRUST $_FILES['upfile']['mime'] VALUE !!
211
- // Check MIME Type by yourself.
212
- $finfo = new finfo(FILEINFO_MIME_TYPE);
213
- if (false === $ext = array_search(
214
- $finfo->file($_FILES['file']['tmp_name']),
215
- array(
216
- 'jpg' => 'image/jpeg',
217
- 'png' => 'image/png',
218
- 'gif' => 'image/gif',
219
- ),
220
- true
221
- )) {
222
- exitWithError(ERROR_NOT_ALLOWED, 'Invalid file format.');
223
- }
224
-
225
- $uploadfile = $uploaddir . '/' . sha1_file($_FILES['file']['tmp_name']) . '.' . $ext;
226
- //echo $uploadfile;
227
- if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
228
- // File is valid, and was successfully uploaded
229
-
230
- $source = $uploadfile;
231
-
232
- if (!empty($password)) {
233
- $hash = md5(md5_file($source) . $password);
234
-
235
- if ($hash != $_POST['hash']) {
236
- exitWithError(ERROR_NOT_ALLOWED, 'Wrong password.');
237
- }
238
- }
239
-
240
- $destination = $uploadfile . '.webp';
241
-
242
- // Merge in options in $_POST, overwriting those in config.yaml
243
- $convertOptionsInPost = (array) json_decode($_POST['options']);
244
- $options = Config::generateWodOptionsFromConfigObj($config);
245
- $convertOptions = array_merge($options, $convertOptionsInPost);
246
-
247
- try {
248
- if (WebPConvert::convert($source, $destination, $convertOptions)) {
249
- header('Content-type: application/octet-stream');
250
- echo file_get_contents($destination);
251
-
252
- unlink($source);
253
- unlink($destination);
254
- } else {
255
- echo 'no converters could convert the image';
256
- }
257
- } catch (\Exception $e) {
258
- echo 'failed!';
259
- echo $e->getMessage();
260
- }
261
- } else {
262
- // Possible file upload attack!
263
- exitWithError(ERROR_SERVER_SETUP, 'Failed to move uploaded file');
264
-
265
- //echo 'Failed to move uploaded file';
266
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
vendor/composer/autoload_classmap.php CHANGED
@@ -6,4 +6,82 @@ $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\\SourceValidationTrait' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Converters/BaseTraits/SourceValidationTrait.php',
30
+ 'WebPConvert\\Convert\\Converters\\BaseTraits\\WarningLoggerTrait' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Converters/BaseTraits/WarningLoggerTrait.php',
31
+ 'WebPConvert\\Convert\\Converters\\ConverterTraits\\CloudConverterTrait' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Converters/ConverterTraits/CloudConverterTrait.php',
32
+ 'WebPConvert\\Convert\\Converters\\ConverterTraits\\CurlTrait' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Converters/ConverterTraits/CurlTrait.php',
33
+ 'WebPConvert\\Convert\\Converters\\ConverterTraits\\EncodingAutoTrait' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Converters/ConverterTraits/EncodingAutoTrait.php',
34
+ 'WebPConvert\\Convert\\Converters\\ConverterTraits\\ExecTrait' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Converters/ConverterTraits/ExecTrait.php',
35
+ 'WebPConvert\\Convert\\Converters\\Cwebp' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Converters/Cwebp.php',
36
+ 'WebPConvert\\Convert\\Converters\\Ewww' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Converters/Ewww.php',
37
+ 'WebPConvert\\Convert\\Converters\\Gd' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Converters/Gd.php',
38
+ 'WebPConvert\\Convert\\Converters\\Gmagick' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Converters/Gmagick.php',
39
+ 'WebPConvert\\Convert\\Converters\\GmagickBinary' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Converters/GmagickBinary.php',
40
+ 'WebPConvert\\Convert\\Converters\\GraphicsMagick' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Converters/GraphicsMagick.php',
41
+ 'WebPConvert\\Convert\\Converters\\ImageMagick' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Converters/ImageMagick.php',
42
+ 'WebPConvert\\Convert\\Converters\\Imagick' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Converters/Imagick.php',
43
+ 'WebPConvert\\Convert\\Converters\\ImagickBinary' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Converters/ImagickBinary.php',
44
+ 'WebPConvert\\Convert\\Converters\\Stack' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Converters/Stack.php',
45
+ 'WebPConvert\\Convert\\Converters\\Vips' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Converters/Vips.php',
46
+ 'WebPConvert\\Convert\\Converters\\Wpc' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Converters/Wpc.php',
47
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailedException' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailedException.php',
48
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\ConversionSkippedException' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/ConversionSkippedException.php',
49
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\ConverterNotOperationalException' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/ConverterNotOperationalException.php',
50
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\ConverterNotOperational\\InvalidApiKeyException' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/ConverterNotOperational/InvalidApiKeyException.php',
51
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\ConverterNotOperational\\SystemRequirementsNotMetException' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/ConverterNotOperational/SystemRequirementsNotMetException.php',
52
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\FileSystemProblemsException' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/FileSystemProblemsException.php',
53
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\FileSystemProblems\\CreateDestinationFileException' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/FileSystemProblems/CreateDestinationFileException.php',
54
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\FileSystemProblems\\CreateDestinationFolderException' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/FileSystemProblems/CreateDestinationFolderException.php',
55
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\InvalidInputException' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/InvalidInputException.php',
56
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\InvalidInput\\ConverterNotFoundException' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/InvalidInput/ConverterNotFoundException.php',
57
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\InvalidInput\\InvalidImageTypeException' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/InvalidInput/InvalidImageTypeException.php',
58
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\InvalidInput\\TargetNotFoundException' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/InvalidInput/TargetNotFoundException.php',
59
+ 'WebPConvert\\Convert\\Helpers\\JpegQualityDetector' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Helpers/JpegQualityDetector.php',
60
+ 'WebPConvert\\Convert\\Helpers\\PhpIniSizes' => $vendorDir . '/rosell-dk/webp-convert/src/Convert/Helpers/PhpIniSizes.php',
61
+ 'WebPConvert\\Exceptions\\WebPConvertException' => $vendorDir . '/rosell-dk/webp-convert/src/Exceptions/WebPConvertException.php',
62
+ 'WebPConvert\\Loggers\\BaseLogger' => $vendorDir . '/rosell-dk/webp-convert/src/Loggers/BaseLogger.php',
63
+ 'WebPConvert\\Loggers\\BufferLogger' => $vendorDir . '/rosell-dk/webp-convert/src/Loggers/BufferLogger.php',
64
+ 'WebPConvert\\Loggers\\EchoLogger' => $vendorDir . '/rosell-dk/webp-convert/src/Loggers/EchoLogger.php',
65
+ 'WebPConvert\\Options\\ArrayOption' => $vendorDir . '/rosell-dk/webp-convert/src/Options/ArrayOption.php',
66
+ 'WebPConvert\\Options\\BooleanOption' => $vendorDir . '/rosell-dk/webp-convert/src/Options/BooleanOption.php',
67
+ 'WebPConvert\\Options\\Exceptions\\InvalidOptionTypeException' => $vendorDir . '/rosell-dk/webp-convert/src/Options/Exceptions/InvalidOptionTypeException.php',
68
+ 'WebPConvert\\Options\\Exceptions\\InvalidOptionValueException' => $vendorDir . '/rosell-dk/webp-convert/src/Options/Exceptions/InvalidOptionValueException.php',
69
+ 'WebPConvert\\Options\\Exceptions\\OptionNotFoundException' => $vendorDir . '/rosell-dk/webp-convert/src/Options/Exceptions/OptionNotFoundException.php',
70
+ 'WebPConvert\\Options\\GhostOption' => $vendorDir . '/rosell-dk/webp-convert/src/Options/GhostOption.php',
71
+ 'WebPConvert\\Options\\IntegerOption' => $vendorDir . '/rosell-dk/webp-convert/src/Options/IntegerOption.php',
72
+ 'WebPConvert\\Options\\IntegerOrNullOption' => $vendorDir . '/rosell-dk/webp-convert/src/Options/IntegerOrNullOption.php',
73
+ 'WebPConvert\\Options\\MetadataOption' => $vendorDir . '/rosell-dk/webp-convert/src/Options/MetadataOption.php',
74
+ 'WebPConvert\\Options\\Option' => $vendorDir . '/rosell-dk/webp-convert/src/Options/Option.php',
75
+ 'WebPConvert\\Options\\Options' => $vendorDir . '/rosell-dk/webp-convert/src/Options/Options.php',
76
+ 'WebPConvert\\Options\\QualityOption' => $vendorDir . '/rosell-dk/webp-convert/src/Options/QualityOption.php',
77
+ 'WebPConvert\\Options\\SensitiveArrayOption' => $vendorDir . '/rosell-dk/webp-convert/src/Options/SensitiveArrayOption.php',
78
+ 'WebPConvert\\Options\\SensitiveStringOption' => $vendorDir . '/rosell-dk/webp-convert/src/Options/SensitiveStringOption.php',
79
+ 'WebPConvert\\Options\\StringOption' => $vendorDir . '/rosell-dk/webp-convert/src/Options/StringOption.php',
80
+ 'WebPConvert\\Serve\\Exceptions\\ServeFailedException' => $vendorDir . '/rosell-dk/webp-convert/src/Serve/Exceptions/ServeFailedException.php',
81
+ 'WebPConvert\\Serve\\Header' => $vendorDir . '/rosell-dk/webp-convert/src/Serve/Header.php',
82
+ 'WebPConvert\\Serve\\Report' => $vendorDir . '/rosell-dk/webp-convert/src/Serve/Report.php',
83
+ 'WebPConvert\\Serve\\ServeConvertedWebP' => $vendorDir . '/rosell-dk/webp-convert/src/Serve/ServeConvertedWebP.php',
84
+ 'WebPConvert\\Serve\\ServeConvertedWebPWithErrorHandling' => $vendorDir . '/rosell-dk/webp-convert/src/Serve/ServeConvertedWebPWithErrorHandling.php',
85
+ 'WebPConvert\\Serve\\ServeFile' => $vendorDir . '/rosell-dk/webp-convert/src/Serve/ServeFile.php',
86
+ 'WebPConvert\\WebPConvert' => $vendorDir . '/rosell-dk/webp-convert/src/WebPConvert.php',
87
  );
vendor/composer/autoload_static.php CHANGED
@@ -41,11 +41,93 @@ 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
  }
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\\SourceValidationTrait' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Converters/BaseTraits/SourceValidationTrait.php',
66
+ 'WebPConvert\\Convert\\Converters\\BaseTraits\\WarningLoggerTrait' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Converters/BaseTraits/WarningLoggerTrait.php',
67
+ 'WebPConvert\\Convert\\Converters\\ConverterTraits\\CloudConverterTrait' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Converters/ConverterTraits/CloudConverterTrait.php',
68
+ 'WebPConvert\\Convert\\Converters\\ConverterTraits\\CurlTrait' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Converters/ConverterTraits/CurlTrait.php',
69
+ 'WebPConvert\\Convert\\Converters\\ConverterTraits\\EncodingAutoTrait' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Converters/ConverterTraits/EncodingAutoTrait.php',
70
+ 'WebPConvert\\Convert\\Converters\\ConverterTraits\\ExecTrait' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Converters/ConverterTraits/ExecTrait.php',
71
+ 'WebPConvert\\Convert\\Converters\\Cwebp' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Converters/Cwebp.php',
72
+ 'WebPConvert\\Convert\\Converters\\Ewww' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Converters/Ewww.php',
73
+ 'WebPConvert\\Convert\\Converters\\Gd' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Converters/Gd.php',
74
+ 'WebPConvert\\Convert\\Converters\\Gmagick' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Converters/Gmagick.php',
75
+ 'WebPConvert\\Convert\\Converters\\GmagickBinary' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Converters/GmagickBinary.php',
76
+ 'WebPConvert\\Convert\\Converters\\GraphicsMagick' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Converters/GraphicsMagick.php',
77
+ 'WebPConvert\\Convert\\Converters\\ImageMagick' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Converters/ImageMagick.php',
78
+ 'WebPConvert\\Convert\\Converters\\Imagick' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Converters/Imagick.php',
79
+ 'WebPConvert\\Convert\\Converters\\ImagickBinary' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Converters/ImagickBinary.php',
80
+ 'WebPConvert\\Convert\\Converters\\Stack' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Converters/Stack.php',
81
+ 'WebPConvert\\Convert\\Converters\\Vips' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Converters/Vips.php',
82
+ 'WebPConvert\\Convert\\Converters\\Wpc' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Converters/Wpc.php',
83
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailedException' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailedException.php',
84
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\ConversionSkippedException' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/ConversionSkippedException.php',
85
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\ConverterNotOperationalException' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/ConverterNotOperationalException.php',
86
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\ConverterNotOperational\\InvalidApiKeyException' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/ConverterNotOperational/InvalidApiKeyException.php',
87
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\ConverterNotOperational\\SystemRequirementsNotMetException' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/ConverterNotOperational/SystemRequirementsNotMetException.php',
88
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\FileSystemProblemsException' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/FileSystemProblemsException.php',
89
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\FileSystemProblems\\CreateDestinationFileException' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/FileSystemProblems/CreateDestinationFileException.php',
90
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\FileSystemProblems\\CreateDestinationFolderException' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/FileSystemProblems/CreateDestinationFolderException.php',
91
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\InvalidInputException' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/InvalidInputException.php',
92
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\InvalidInput\\ConverterNotFoundException' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/InvalidInput/ConverterNotFoundException.php',
93
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\InvalidInput\\InvalidImageTypeException' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/InvalidInput/InvalidImageTypeException.php',
94
+ 'WebPConvert\\Convert\\Exceptions\\ConversionFailed\\InvalidInput\\TargetNotFoundException' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Exceptions/ConversionFailed/InvalidInput/TargetNotFoundException.php',
95
+ 'WebPConvert\\Convert\\Helpers\\JpegQualityDetector' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Helpers/JpegQualityDetector.php',
96
+ 'WebPConvert\\Convert\\Helpers\\PhpIniSizes' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Convert/Helpers/PhpIniSizes.php',
97
+ 'WebPConvert\\Exceptions\\WebPConvertException' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Exceptions/WebPConvertException.php',
98
+ 'WebPConvert\\Loggers\\BaseLogger' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Loggers/BaseLogger.php',
99
+ 'WebPConvert\\Loggers\\BufferLogger' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Loggers/BufferLogger.php',
100
+ 'WebPConvert\\Loggers\\EchoLogger' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Loggers/EchoLogger.php',
101
+ 'WebPConvert\\Options\\ArrayOption' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Options/ArrayOption.php',
102
+ 'WebPConvert\\Options\\BooleanOption' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Options/BooleanOption.php',
103
+ 'WebPConvert\\Options\\Exceptions\\InvalidOptionTypeException' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Options/Exceptions/InvalidOptionTypeException.php',
104
+ 'WebPConvert\\Options\\Exceptions\\InvalidOptionValueException' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Options/Exceptions/InvalidOptionValueException.php',
105
+ 'WebPConvert\\Options\\Exceptions\\OptionNotFoundException' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Options/Exceptions/OptionNotFoundException.php',
106
+ 'WebPConvert\\Options\\GhostOption' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Options/GhostOption.php',
107
+ 'WebPConvert\\Options\\IntegerOption' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Options/IntegerOption.php',
108
+ 'WebPConvert\\Options\\IntegerOrNullOption' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Options/IntegerOrNullOption.php',
109
+ 'WebPConvert\\Options\\MetadataOption' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Options/MetadataOption.php',
110
+ 'WebPConvert\\Options\\Option' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Options/Option.php',
111
+ 'WebPConvert\\Options\\Options' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Options/Options.php',
112
+ 'WebPConvert\\Options\\QualityOption' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Options/QualityOption.php',
113
+ 'WebPConvert\\Options\\SensitiveArrayOption' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Options/SensitiveArrayOption.php',
114
+ 'WebPConvert\\Options\\SensitiveStringOption' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Options/SensitiveStringOption.php',
115
+ 'WebPConvert\\Options\\StringOption' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Options/StringOption.php',
116
+ 'WebPConvert\\Serve\\Exceptions\\ServeFailedException' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Serve/Exceptions/ServeFailedException.php',
117
+ 'WebPConvert\\Serve\\Header' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Serve/Header.php',
118
+ 'WebPConvert\\Serve\\Report' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Serve/Report.php',
119
+ 'WebPConvert\\Serve\\ServeConvertedWebP' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Serve/ServeConvertedWebP.php',
120
+ 'WebPConvert\\Serve\\ServeConvertedWebPWithErrorHandling' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Serve/ServeConvertedWebPWithErrorHandling.php',
121
+ 'WebPConvert\\Serve\\ServeFile' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/Serve/ServeFile.php',
122
+ 'WebPConvert\\WebPConvert' => __DIR__ . '/..' . '/rosell-dk/webp-convert/src/WebPConvert.php',
123
+ );
124
+
125
  public static function getInitializer(ClassLoader $loader)
126
  {
127
  return \Closure::bind(function () use ($loader) {
128
  $loader->prefixLengthsPsr4 = ComposerStaticInit9a5d1d521aac5c1f4f08f3a90858f030::$prefixLengthsPsr4;
129
  $loader->prefixDirsPsr4 = ComposerStaticInit9a5d1d521aac5c1f4f08f3a90858f030::$prefixDirsPsr4;
130
+ $loader->classMap = ComposerStaticInit9a5d1d521aac5c1f4f08f3a90858f030::$classMap;
131
 
132
  }, null, ClassLoader::class);
133
  }
vendor/composer/installed.json CHANGED
@@ -115,17 +115,17 @@
115
  },
116
  {
117
  "name": "rosell-dk/webp-convert",
118
- "version": "2.0.2",
119
- "version_normalized": "2.0.2.0",
120
  "source": {
121
  "type": "git",
122
  "url": "https://github.com/rosell-dk/webp-convert.git",
123
- "reference": "50f59ca429ebe2984a4054696db62bcfcf57d299"
124
  },
125
  "dist": {
126
  "type": "zip",
127
- "url": "https://api.github.com/repos/rosell-dk/webp-convert/zipball/50f59ca429ebe2984a4054696db62bcfcf57d299",
128
- "reference": "50f59ca429ebe2984a4054696db62bcfcf57d299",
129
  "shasum": ""
130
  },
131
  "require": {
@@ -143,7 +143,7 @@
143
  "ext-vips": "to use Vips extension for converting.",
144
  "php-stan/php-stan": "Suggested for dev, in order to analyse code before committing"
145
  },
146
- "time": "2019-06-15T11:45:10+00:00",
147
  "type": "library",
148
  "extra": {
149
  "scripts-descriptions": {
115
  },
116
  {
117
  "name": "rosell-dk/webp-convert",
118
+ "version": "2.0.3",
119
+ "version_normalized": "2.0.3.0",
120
  "source": {
121
  "type": "git",
122
  "url": "https://github.com/rosell-dk/webp-convert.git",
123
+ "reference": "3a2c6ab330e4a99dbce1b05c987cad4f799f75ee"
124
  },
125
  "dist": {
126
  "type": "zip",
127
+ "url": "https://api.github.com/repos/rosell-dk/webp-convert/zipball/3a2c6ab330e4a99dbce1b05c987cad4f799f75ee",
128
+ "reference": "3a2c6ab330e4a99dbce1b05c987cad4f799f75ee",
129
  "shasum": ""
130
  },
131
  "require": {
143
  "ext-vips": "to use Vips extension for converting.",
144
  "php-stan/php-stan": "Suggested for dev, in order to analyse code before committing"
145
  },
146
+ "time": "2019-06-17T08:13:22+00:00",
147
  "type": "library",
148
  "extra": {
149
  "scripts-descriptions": {
vendor/rosell-dk/webp-convert/docs/v2.0/converting/introduction-for-converting.md CHANGED
@@ -80,15 +80,19 @@ Stack::convert($source, $destination, $options = [
80
  ], $logger=null);
81
  ```
82
 
83
- Note: As an alternative to setting the third party credentials in the options, you can set them through environment variables ("EWWW_API_KEY", "WPC_API_KEY", "WPC_API_URL"). Paths to binaries can also be set with environment variables (it is rarely needed to do this): "CWEBP_PATH", "GRAPHICSMAGICK_PATH" and 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 EWWW_API_KEY yourVerySecretApiKeyGoesHere
89
 
90
  # Set custom path to imagick for WebP Convert
91
- SetEnv IMAGEMAGICK_PATH /usr/local/bin/magick
 
 
 
 
92
  ```
93
 
94
 
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
 
vendor/rosell-dk/webp-convert/src-build/webp-convert.inc CHANGED
@@ -461,7 +461,7 @@ abstract class AbstractConverter
461
  if (isset($trace['file']) && isset($trace['line'])) {
462
  $this->logLn(
463
  $trace['file'] . ':' . $trace['line']
464
- );
465
  }
466
  }
467
  throw $e;
@@ -518,6 +518,8 @@ abstract class AbstractConverter
518
  public function getMimeTypeOfSource()
519
  {
520
  if (!isset($this->sourceMimeType)) {
 
 
521
  $this->sourceMimeType = ImageMimeTypeGuesser::lenientGuess($this->source);
522
  }
523
  return $this->sourceMimeType;
@@ -2161,7 +2163,9 @@ trait EncodingAutoTrait
2161
  abstract public function getOptions();
2162
  abstract protected function setOption($optionName, $optionValue);
2163
  abstract protected function logLn($msg, $style = '');
 
2164
  abstract protected function ln();
 
2165
 
2166
  public function supportsLossless()
2167
  {
@@ -2359,12 +2363,14 @@ class Cwebp extends AbstractConverter
2359
  // OS-specific binaries included in this library, along with hashes
2360
  // If other binaries are going to be added, notice that the first argument is what PHP_OS returns.
2361
  // (possible values, see here: https://stackoverflow.com/questions/738823/possible-values-for-php-os)
 
2362
  private static $suppliedBinariesInfo = [
2363
  'WINNT' => [ 'cwebp.exe', '49e9cb98db30bfa27936933e6fd94d407e0386802cb192800d9fd824f6476873'],
2364
  'Darwin' => [ 'cwebp-mac12', 'a06a3ee436e375c89dbc1b0b2e8bd7729a55139ae072ed3f7bd2e07de0ebb379'],
2365
  'SunOS' => [ 'cwebp-sol', '1febaffbb18e52dc2c524cda9eefd00c6db95bc388732868999c0f48deb73b4f'],
2366
  'FreeBSD' => [ 'cwebp-fbsd', 'e5cbea11c97fadffe221fdf57c093c19af2737e4bbd2cb3cd5e908de64286573'],
2367
- 'Linux' => [ 'cwebp-linux', '916623e5e9183237c851374d969aebdb96e0edc0692ab7937b95ea67dc3b2568']
 
2368
  ];
2369
 
2370
  public function checkOperationality()
@@ -2383,10 +2389,13 @@ class Cwebp extends AbstractConverter
2383
 
2384
  private function executeBinary($binary, $commandOptions, $useNice)
2385
  {
 
 
2386
  $command = ($useNice ? 'nice ' : '') . $binary . ' ' . $commandOptions;
2387
 
2388
  //$logger->logLn('command options:' . $commandOptions);
2389
- //$logger->logLn('Trying to execute binary:' . $binary);
 
2390
  exec($command, $output, $returnCode);
2391
  $this->logExecOutput($output);
2392
  /*
@@ -2440,19 +2449,42 @@ class Cwebp extends AbstractConverter
2440
  }
2441
 
2442
  /**
2443
- * Build command line options
 
 
2444
  *
 
2445
  * @return string
2446
  */
2447
- private function createCommandLineOptions()
2448
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2449
  $options = $this->options;
2450
 
2451
  $cmdOptions = [];
2452
 
2453
  // Metadata (all, exif, icc, xmp or none (default))
2454
  // Comma-separated list of existing metadata to copy from input to output
2455
- $cmdOptions[] = '-metadata ' . $options['metadata'];
 
 
2456
 
2457
  // preset. Appears first in the list as recommended in the docs
2458
  if (!is_null($options['preset'])) {
@@ -2484,18 +2516,31 @@ class Cwebp extends AbstractConverter
2484
 
2485
  // Losless PNG conversion
2486
  if ($options['encoding'] == 'lossless') {
2487
- // No need to add -lossless when near-lossless is used
2488
- if ($options['near-lossless'] === 100) {
2489
  $cmdOptions[] = '-lossless';
2490
  }
2491
  }
2492
 
2493
  // Near-lossles
2494
  if ($options['near-lossless'] !== 100) {
2495
- // We only let near_lossless have effect when encoding is set to "lossless"
2496
- // otherwise encoding=auto would not work as expected
2497
- if ($options['encoding'] == 'lossless') {
2498
- $cmdOptions[] ='-near_lossless ' . $options['near-lossless'];
 
 
 
 
 
 
 
 
 
 
 
 
 
2499
  }
2500
  }
2501
 
@@ -2530,117 +2575,27 @@ class Cwebp extends AbstractConverter
2530
  $cmdOptions[] = '2>&1';
2531
 
2532
  $commandOptions = implode(' ', $cmdOptions);
2533
- $this->logLn('command line options:' . $commandOptions);
2534
 
2535
  return $commandOptions;
2536
  }
2537
 
2538
  /**
 
2539
  *
2540
- *
2541
- * @return string Error message if failure, empty string if successful
2542
- */
2543
- private function composeErrorMessageForCommonSystemPathsFailures($failureCodes)
2544
- {
2545
- if (count($failureCodes) == 1) {
2546
- switch ($failureCodes[0]) {
2547
- case 126:
2548
- return 'Permission denied. The user that the command was run with (' .
2549
- shell_exec('whoami') . ') does not have permission to execute any of the ' .
2550
- 'cweb binaries found in common system locations. ';
2551
- case 127:
2552
- return 'Found no cwebp binaries in any common system locations. ';
2553
- default:
2554
- return 'Tried executing cwebp binaries in common system locations. ' .
2555
- 'All failed (exit code: ' . $failureCodes[0] . '). ';
2556
- }
2557
- } else {
2558
- /**
2559
- * $failureCodesBesides127 is used to check first position ($failureCodesBesides127[0])
2560
- * however position can vary as index can be 1 or something else. array_values() would
2561
- * always start from 0.
2562
- */
2563
- $failureCodesBesides127 = array_values(array_diff($failureCodes, [127]));
2564
-
2565
- if (count($failureCodesBesides127) == 1) {
2566
- switch ($failureCodesBesides127[0]) {
2567
- case 126:
2568
- return 'Permission denied. The user that the command was run with (' .
2569
- shell_exec('whoami') . ') does not have permission to execute any of the cweb ' .
2570
- 'binaries found in common system locations. ';
2571
- break;
2572
- default:
2573
- return 'Tried executing cwebp binaries in common system locations. ' .
2574
- 'All failed (exit code: ' . $failureCodesBesides127[0] . '). ';
2575
- }
2576
- } else {
2577
- return 'None of the cwebp binaries in the common system locations could be executed ' .
2578
- '(mixed results - got the following exit codes: ' . implode(',', $failureCodes) . '). ';
2579
- }
2580
- }
2581
- }
2582
-
2583
- /**
2584
- * Try executing cwebp in common system paths
2585
- *
2586
- * @param boolean $useNice Whether to use nice
2587
- * @param string $commandOptions for the exec call
2588
- *
2589
- * @return array Unique failure codes in case of failure, empty array in case of success
2590
- */
2591
- private function tryCommonSystemPaths($useNice, $commandOptions)
2592
- {
2593
- $failureCodes = [];
2594
-
2595
- $paths = self::$cwebpDefaultPaths;
2596
-
2597
- if (!empty(getenv('CWEBP_PATH'))) {
2598
- array_unshift($paths, getenv('CWEBP_PATH'));
2599
- }
2600
-
2601
- // Loop through paths
2602
- foreach ($paths as $index => $binary) {
2603
- $returnCode = $this->executeBinary($binary, $commandOptions, $useNice);
2604
- if ($returnCode == 0) {
2605
- $this->logLn('Successfully executed binary: ' . $binary);
2606
- return [];
2607
- } else {
2608
- if ($returnCode == 127) {
2609
- $this->logLn(
2610
- 'Trying to execute binary: ' . $binary . '. Failed (not found)'
2611
- );
2612
- } else {
2613
- $this->logLn(
2614
- 'Trying to execute binary: ' . $binary . '. Failed (return code: ' . $returnCode . ')'
2615
- );
2616
- }
2617
- if (!in_array($returnCode, $failureCodes)) {
2618
- $failureCodes[] = $returnCode;
2619
- }
2620
- }
2621
- }
2622
- return $failureCodes;
2623
- }
2624
-
2625
- /**
2626
- * Try executing supplied cwebp for PHP_OS.
2627
- *
2628
- * @param boolean $useNice Whether to use nice
2629
- * @param string $commandOptions for the exec call
2630
- * @param array $failureCodesForCommonSystemPaths Return codes from the other attempt
2631
- * (in order to produce short error message)
2632
- *
2633
- * @return string Error message if failure, empty string if successful
2634
  */
2635
- private function trySuppliedBinaryForOS($useNice, $commandOptions, $failureCodesForCommonSystemPaths)
2636
  {
2637
- $this->logLn('Trying to execute supplied binary for OS: ' . PHP_OS);
2638
 
2639
  // Try supplied binary (if available for OS, and hash is correct)
2640
  $options = $this->options;
2641
  if (!isset(self::$suppliedBinariesInfo[PHP_OS])) {
2642
- return 'No supplied binaries found for OS:' . PHP_OS;
 
2643
  }
 
2644
 
2645
  $info = self::$suppliedBinariesInfo[PHP_OS];
2646
 
@@ -2649,14 +2604,13 @@ class Cwebp extends AbstractConverter
2649
 
2650
  $binaryFile = __DIR__ . '/' . $options['rel-path-to-precompiled-binaries'] . '/' . $file;
2651
 
2652
-
2653
  // The file should exist, but may have been removed manually.
2654
  if (!file_exists($binaryFile)) {
2655
- return 'Supplied binary not found! It ought to be here:' . $binaryFile;
 
2656
  }
2657
 
2658
  // File exists, now generate its hash
2659
-
2660
  // hash_file() is normally available, but it is not always
2661
  // - https://stackoverflow.com/questions/17382712/php-5-3-20-undefined-function-hash
2662
  // If available, validate that hash is correct.
@@ -2665,92 +2619,204 @@ class Cwebp extends AbstractConverter
2665
  $binaryHash = hash_file('sha256', $binaryFile);
2666
 
2667
  if ($binaryHash != $hash) {
2668
- return 'Binary checksum of supplied binary is invalid! ' .
 
2669
  'Did you transfer with FTP, but not in binary mode? ' .
2670
  'File:' . $binaryFile . '. ' .
2671
  'Expected checksum: ' . $hash . '. ' .
2672
- 'Actual checksum:' . $binaryHash . '.';
 
 
2673
  }
2674
  }
 
 
2675
 
2676
- $returnCode = $this->executeBinary($binaryFile, $commandOptions, $useNice);
2677
- if ($returnCode == 0) {
2678
- // yay!
2679
- $this->logLn('success!');
2680
- return '';
 
 
 
 
 
 
 
 
 
 
2681
  }
2682
 
2683
- $errorMsg = 'Tried executing supplied binary for ' . PHP_OS . ', ' .
2684
- ($options['try-common-system-paths'] ? 'but that failed too' : 'but failed');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2685
 
 
 
 
 
 
 
2686
 
2687
- if (($options['try-common-system-paths']) && (count($failureCodesForCommonSystemPaths) > 0)) {
2688
- // check if it was the same error
2689
- // if it was, simply refer to that with "(same problem)"
2690
- $majorFailCode = 0;
2691
- if (count($failureCodesForCommonSystemPaths) == 1) {
2692
- $majorFailCode = $failureCodesForCommonSystemPaths[0];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2693
  } else {
2694
- $failureCodesBesides127 = array_values(array_diff($failureCodesForCommonSystemPaths, [127]));
2695
- if (count($failureCodesBesides127) == 1) {
2696
- $majorFailCode = $failureCodesBesides127[0];
2697
- } else {
2698
- // it cannot be summarized into a single code
 
 
 
 
2699
  }
2700
  }
2701
- if ($majorFailCode != 0) {
2702
- $errorMsg .= ' (same problem)';
2703
- return $errorMsg;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2704
  }
2705
  }
 
 
 
 
 
 
 
 
2706
 
2707
- if ($returnCode > 128) {
2708
- $errorMsg .= '. The binary did not work (exit code: ' . $returnCode . '). ' .
2709
- 'Check out https://github.com/rosell-dk/webp-convert/issues/92';
 
 
 
 
2710
  } else {
2711
- switch ($returnCode) {
2712
- case 0:
2713
- // success!
2714
- break;
2715
- case 126:
2716
- $errorMsg .= ': Permission denied. The user that the command was run' .
2717
- ' with (' . shell_exec('whoami') . ') does not have permission to ' .
2718
- 'execute that binary.';
2719
- break;
2720
- case 127:
2721
- $errorMsg .= '. The binary was not found! ' .
2722
- 'It ought to be here: ' . $binaryFile;
2723
- break;
2724
- default:
2725
- $errorMsg .= ' (exit code:' . $returnCode . ').';
2726
- }
2727
  }
2728
- return $errorMsg;
2729
  }
2730
 
2731
  protected function doActualConvert()
2732
  {
2733
- $errorMsg = '';
2734
- $options = $this->options;
2735
- $useNice = (($options['use-nice']) && self::hasNiceSupport());
2736
 
2737
- $commandOptions = $this->createCommandLineOptions();
 
 
 
 
2738
 
2739
- // Try all common paths that exists
2740
- $success = false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2741
 
2742
- $failureCodes = [];
2743
 
2744
- if ($options['try-common-system-paths']) {
2745
- $failureCodes = $this->tryCommonSystemPaths($useNice, $commandOptions);
2746
- $success = (count($failureCodes) == 0);
2747
- $errorMsg = $this->composeErrorMessageForCommonSystemPathsFailures($failureCodes);
2748
  }
 
 
 
 
2749
 
2750
- if (!$success && $options['try-supplied-binary-for-os']) {
2751
- $errorMsg2 = $this->trySuppliedBinaryForOS($useNice, $commandOptions, $failureCodes);
2752
- $errorMsg .= $errorMsg2;
2753
- $success = ($errorMsg2 == '');
 
 
 
 
 
 
2754
  }
2755
 
2756
  // cwebp sets file permissions to 664 but instead ..
@@ -2765,10 +2831,8 @@ class Cwebp extends AbstractConverter
2765
  $permissions = $fileStatistics['mode'] & 0000666;
2766
  chmod($this->destination, $permissions);
2767
  }
2768
- }
2769
-
2770
- if (!$success) {
2771
- throw new SystemRequirementsNotMetException($errorMsg);
2772
  }
2773
  }
2774
  }
@@ -2828,8 +2892,11 @@ class Ewww extends AbstractConverter
2828
  if (!empty($this->options['api-key'])) {
2829
  return $this->options['api-key'];
2830
  }
2831
- if (!empty(getenv('EWWW_API_KEY'))) {
2832
- return getenv('EWWW_API_KEY');
 
 
 
2833
  }
2834
  return false;
2835
  }
@@ -3811,11 +3878,13 @@ class GraphicsMagick extends AbstractConverter
3811
 
3812
  private function getPath()
3813
  {
3814
- if (empty(getenv('GRAPHICSMAGICK_PATH'))) {
3815
- return 'gm';
3816
- } else {
3817
- return getenv('GRAPHICSMAGICK_PATH');
 
3818
  }
 
3819
  }
3820
 
3821
  public function isInstalled()
@@ -3983,16 +4052,13 @@ class ImageMagick extends AbstractConverter
3983
 
3984
  private function getPath()
3985
  {
3986
- // Should we use "magick" or "convert" command?
3987
- // It seems they do the same. But which is best supported? Which is mostly available (whitelisted)?
3988
- // Should we perhaps try both?
3989
- // For now, we just go with "convert"
3990
-
3991
- if (!empty(getenv('IMAGEMAGICK_PATH'))) {
3992
- return getenv('IMAGEMAGICK_PATH');
3993
- } else {
3994
- return 'convert';
3995
  }
 
 
 
 
3996
  }
3997
 
3998
  private function getVersion()
@@ -4550,11 +4616,11 @@ class Stack extends AbstractConverter
4550
  $this->ln();
4551
  $this->logLn('Stack failed in ' . round((microtime(true) - $beginTimeStack) * 1000) . ' ms');
4552
 
 
4553
  if ($anyRuntimeErrors) {
4554
  // At least one converter failed
4555
  throw new ConversionFailedException(
4556
- 'None of the converters in the stack could convert the image. ' .
4557
- 'At least one failed, even though its requirements seemed to be met.'
4558
  );
4559
  } else {
4560
  // All converters threw a SystemRequirementsNotMetException
@@ -4892,8 +4958,11 @@ class Wpc extends AbstractConverter
4892
  return $this->options['api-key'];
4893
  }
4894
  }
4895
- if (!empty(getenv('WPC_API_KEY'))) {
4896
- return getenv('WPC_API_KEY');
 
 
 
4897
  }
4898
  return '';
4899
  }
@@ -4908,8 +4977,11 @@ class Wpc extends AbstractConverter
4908
  if (!empty($this->options['api-url'])) {
4909
  return $this->options['api-url'];
4910
  }
4911
- if (!empty(getenv('WPC_API_URL'))) {
4912
- return getenv('WPC_API_URL');
 
 
 
4913
  }
4914
  return '';
4915
  }
@@ -5860,10 +5932,7 @@ class Report
5860
  $options['log-call-arguments'] = true;
5861
  WebPConvert::convert($source, $destination, $options, $echoLogger);
5862
  } catch (\Exception $e) {
5863
- $success = false;
5864
-
5865
  $msg = $e->getMessage();
5866
-
5867
  echo '<b>' . $msg . '</b>';
5868
 
5869
  //echo '<p>Rethrowing exception for your convenience</p>';
461
  if (isset($trace['file']) && isset($trace['line'])) {
462
  $this->logLn(
463
  $trace['file'] . ':' . $trace['line']
464
+ );
465
  }
466
  }
467
  throw $e;
518
  public function getMimeTypeOfSource()
519
  {
520
  if (!isset($this->sourceMimeType)) {
521
+ // PS: Scrutinizer complains that ImageMimeTypeGuesser::lenientGuess could also return a boolean
522
+ // but this is not true! - it returns string|false|null, just as this method does.
523
  $this->sourceMimeType = ImageMimeTypeGuesser::lenientGuess($this->source);
524
  }
525
  return $this->sourceMimeType;
2163
  abstract public function getOptions();
2164
  abstract protected function setOption($optionName, $optionValue);
2165
  abstract protected function logLn($msg, $style = '');
2166
+ abstract protected function log($msg, $style = '');
2167
  abstract protected function ln();
2168
+ abstract protected function logReduction($source, $destination);
2169
 
2170
  public function supportsLossless()
2171
  {
2363
  // OS-specific binaries included in this library, along with hashes
2364
  // If other binaries are going to be added, notice that the first argument is what PHP_OS returns.
2365
  // (possible values, see here: https://stackoverflow.com/questions/738823/possible-values-for-php-os)
2366
+ // Got the precompiled binaries here: https://developers.google.com/speed/webp/docs/precompiled
2367
  private static $suppliedBinariesInfo = [
2368
  'WINNT' => [ 'cwebp.exe', '49e9cb98db30bfa27936933e6fd94d407e0386802cb192800d9fd824f6476873'],
2369
  'Darwin' => [ 'cwebp-mac12', 'a06a3ee436e375c89dbc1b0b2e8bd7729a55139ae072ed3f7bd2e07de0ebb379'],
2370
  'SunOS' => [ 'cwebp-sol', '1febaffbb18e52dc2c524cda9eefd00c6db95bc388732868999c0f48deb73b4f'],
2371
  'FreeBSD' => [ 'cwebp-fbsd', 'e5cbea11c97fadffe221fdf57c093c19af2737e4bbd2cb3cd5e908de64286573'],
2372
+ 'Linux' => [ 'cwebp-linux2', 'd6142e9da2f1cab541de10a31527c597225fff5644e66e31d62bb391c41bfbf4'] // 1.0.2
2373
+
2374
  ];
2375
 
2376
  public function checkOperationality()
2389
 
2390
  private function executeBinary($binary, $commandOptions, $useNice)
2391
  {
2392
+ //$version = $this->detectVersion($binary);
2393
+
2394
  $command = ($useNice ? 'nice ' : '') . $binary . ' ' . $commandOptions;
2395
 
2396
  //$logger->logLn('command options:' . $commandOptions);
2397
+ $this->logLn('Trying to convert by executing the following command:');
2398
+ $this->logLn($command);
2399
  exec($command, $output, $returnCode);
2400
  $this->logExecOutput($output);
2401
  /*
2449
  }
2450
 
2451
  /**
2452
+ * Build command line options for a given version of cwebp.
2453
+ *
2454
+ * The "-near_lossless" param is not supported on older versions of cwebp, so skip on those.
2455
  *
2456
+ * @param string $version Version of cwebp.
2457
  * @return string
2458
  */
2459
+ private function createCommandLineOptions($version)
2460
  {
2461
+
2462
+ $this->logLn('Creating command line options for version: ' . $version);
2463
+
2464
+ // we only need two decimal places for version.
2465
+ // convert to number to make it easier to compare
2466
+ $version = preg_match('#^\d+\.\d+#', $version, $matches);
2467
+ $versionNum = 0;
2468
+ if (isset($matches[0])) {
2469
+ $versionNum = floatval($matches[0]);
2470
+ } else {
2471
+ $this->logLn(
2472
+ 'Could not extract version number from the following version string: ' . $version,
2473
+ 'bold'
2474
+ );
2475
+ }
2476
+
2477
+ //$this->logLn('version:' . strval($versionNum));
2478
+
2479
  $options = $this->options;
2480
 
2481
  $cmdOptions = [];
2482
 
2483
  // Metadata (all, exif, icc, xmp or none (default))
2484
  // Comma-separated list of existing metadata to copy from input to output
2485
+ if ($versionNum >= 0.3) {
2486
+ $cmdOptions[] = '-metadata ' . $options['metadata'];
2487
+ }
2488
 
2489
  // preset. Appears first in the list as recommended in the docs
2490
  if (!is_null($options['preset'])) {
2516
 
2517
  // Losless PNG conversion
2518
  if ($options['encoding'] == 'lossless') {
2519
+ // No need to add -lossless when near-lossless is used (on version >= 0.5)
2520
+ if (($options['near-lossless'] === 100) || ($versionNum < 0.5)) {
2521
  $cmdOptions[] = '-lossless';
2522
  }
2523
  }
2524
 
2525
  // Near-lossles
2526
  if ($options['near-lossless'] !== 100) {
2527
+ if ($versionNum < 0.5) {
2528
+ $this->logLn(
2529
+ 'The near-lossless option is not supported on this (rather old) version of cwebp' .
2530
+ '- skipping it.',
2531
+ 'italic'
2532
+ );
2533
+ } else {
2534
+ // We only let near_lossless have effect when encoding is set to "lossless"
2535
+ // otherwise encoding=auto would not work as expected
2536
+
2537
+ if ($options['encoding'] == 'lossless') {
2538
+ $cmdOptions[] ='-near_lossless ' . $options['near-lossless'];
2539
+ } else {
2540
+ $this->logLn(
2541
+ 'The near-lossless option ignored for lossy'
2542
+ );
2543
+ }
2544
  }
2545
  }
2546
 
2575
  $cmdOptions[] = '2>&1';
2576
 
2577
  $commandOptions = implode(' ', $cmdOptions);
2578
+ //$this->logLn('command line options:' . $commandOptions);
2579
 
2580
  return $commandOptions;
2581
  }
2582
 
2583
  /**
2584
+ * Get path for supplied binary for current OS - and validate hash.
2585
  *
2586
+ * @return string|false False if something is wrong, otherwise the path.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2587
  */
2588
+ private function getSuppliedBinaryPathForOS()
2589
  {
2590
+ $this->log('Checking if we have a supplied binary for OS: ' . PHP_OS . '... ');
2591
 
2592
  // Try supplied binary (if available for OS, and hash is correct)
2593
  $options = $this->options;
2594
  if (!isset(self::$suppliedBinariesInfo[PHP_OS])) {
2595
+ $this->logLn('No we dont - not for that OS');
2596
+ return false;
2597
  }
2598
+ $this->logLn('We do.');
2599
 
2600
  $info = self::$suppliedBinariesInfo[PHP_OS];
2601
 
2604
 
2605
  $binaryFile = __DIR__ . '/' . $options['rel-path-to-precompiled-binaries'] . '/' . $file;
2606
 
 
2607
  // The file should exist, but may have been removed manually.
2608
  if (!file_exists($binaryFile)) {
2609
+ $this->logLn('Supplied binary not found! It ought to be here:' . $binaryFile, 'italic');
2610
+ return false;
2611
  }
2612
 
2613
  // File exists, now generate its hash
 
2614
  // hash_file() is normally available, but it is not always
2615
  // - https://stackoverflow.com/questions/17382712/php-5-3-20-undefined-function-hash
2616
  // If available, validate that hash is correct.
2619
  $binaryHash = hash_file('sha256', $binaryFile);
2620
 
2621
  if ($binaryHash != $hash) {
2622
+ $this->logLn(
2623
+ 'Binary checksum of supplied binary is invalid! ' .
2624
  'Did you transfer with FTP, but not in binary mode? ' .
2625
  'File:' . $binaryFile . '. ' .
2626
  'Expected checksum: ' . $hash . '. ' .
2627
+ 'Actual checksum:' . $binaryHash . '.',
2628
+ 'bold'
2629
+ );
2630
  }
2631
  }
2632
+ return $binaryFile;
2633
+ }
2634
 
2635
+ private function discoverBinaries()
2636
+ {
2637
+ $this->logLn('Locating cwebp binaries');
2638
+
2639
+ if (defined('WEBPCONVERT_CWEBP_PATH')) {
2640
+ $this->logLn('WEBPCONVERT_CWEBP_PATH was defined, so using that path and ignoring any other');
2641
+ //$this->logLn('Value: "' . getenv('WEBPCONVERT_CWEBP_PATH') . '"');
2642
+ return [constant('WEBPCONVERT_CWEBP_PATH')];
2643
+ }
2644
+ if (!empty(getenv('WEBPCONVERT_CWEBP_PATH'))) {
2645
+ $this->logLn(
2646
+ 'WEBPCONVERT_CWEBP_PATH environment variable was set, so using that path and ignoring any other'
2647
+ );
2648
+ //$this->logLn('Value: "' . getenv('WEBPCONVERT_CWEBP_PATH') . '"');
2649
+ return [getenv('WEBPCONVERT_CWEBP_PATH')];
2650
  }
2651
 
2652
+ $binaries = [];
2653
+ if ($this->options['try-common-system-paths']) {
2654
+ foreach (self::$cwebpDefaultPaths as $binary) {
2655
+ if (@file_exists($binary)) {
2656
+ $binaries[] = $binary;
2657
+ }
2658
+ }
2659
+ if (count($binaries) == 0) {
2660
+ $this->logLn('No cwebp binaries where located in common system locations');
2661
+ } else {
2662
+ $this->logLn(strval(count($binaries)) . ' cwebp binaries found in common system locations');
2663
+ }
2664
+ }
2665
+ // TODO: exec('whereis cwebp');
2666
+ if ($this->options['try-supplied-binary-for-os']) {
2667
+ $suppliedBinary = $this->getSuppliedBinaryPathForOS();
2668
+ if ($suppliedBinary !== false) {
2669
+ $binaries[] = $suppliedBinary;
2670
+ }
2671
+ } else {
2672
+ $this->logLn('Configured not to try the cwebp binary that comes bundled with webp-convert');
2673
+ }
2674
 
2675
+ if (count($binaries) == 0) {
2676
+ $this->logLn('No cwebp binaries to try!');
2677
+ }
2678
+ $this->logLn('A total of ' . strval(count($binaries)) . ' cwebp binaries where found');
2679
+ return $binaries;
2680
+ }
2681
 
2682
+ /**
2683
+ *
2684
+ * @return string|int Version string (ie "1.0.2") OR return code, in case of failure
2685
+ */
2686
+ private function detectVersion($binary)
2687
+ {
2688
+ //$this->logLn('Examining binary: ' . $binary);
2689
+ $command = $binary . ' -version';
2690
+ $this->log('Executing: ' . $command);
2691
+ exec($command, $output, $returnCode);
2692
+
2693
+ if ($returnCode == 0) {
2694
+ //$this->logLn('Success');
2695
+ if (isset($output[0])) {
2696
+ $this->logLn('. Result: version: ' . $output[0]);
2697
+ return $output[0];
2698
+ }
2699
+ } else {
2700
+ $this->logExecOutput($output);
2701
+ $this->logLn('');
2702
+ if ($returnCode == 127) {
2703
+ $this->logLn('Exec failed (the cwebp binary was not found at path: ' . $binary. ')');
2704
  } else {
2705
+ $this->logLn(
2706
+ 'Exec failed (return code: ' . $returnCode . ')'
2707
+ );
2708
+ if ($returnCode == 126) {
2709
+ $this->logLn(
2710
+ 'PS: Return code 126 means "Permission denied". The user that the command was run with does ' .
2711
+ 'not have permission to execute that binary.'
2712
+ );
2713
+ // TODO: further info: shell_exec('whoami')
2714
  }
2715
  }
2716
+ return $returnCode;
2717
+ }
2718
+ }
2719
+
2720
+ /**
2721
+ * Check versions for binaries, and return array (indexed by the binary, value being the version of the binary).
2722
+ *
2723
+ * @return array
2724
+ */
2725
+ private function detectVersions($binaries)
2726
+ {
2727
+ $binariesWithVersions = [];
2728
+ $binariesWithFailCodes = [];
2729
+
2730
+ $this->logLn(
2731
+ 'Detecting versions of the cwebp binaries found (and verifying that they can be executed in the process)'
2732
+ );
2733
+ foreach ($binaries as $binary) {
2734
+ $versionStringOrFailCode = $this->detectVersion($binary);
2735
+ // $this->logLn($binary . ': ' . $versionString);
2736
+ if (gettype($versionStringOrFailCode) == 'string') {
2737
+ $binariesWithVersions[$binary] = $versionStringOrFailCode;
2738
+ } else {
2739
+ $binariesWithFailCodes[$binary] = $versionStringOrFailCode;
2740
  }
2741
  }
2742
+ return ['detected' => $binariesWithVersions, 'failed' => $binariesWithFailCodes];
2743
+ }
2744
+
2745
+ /**
2746
+ * @return boolean success or not.
2747
+ */
2748
+ private function tryBinary($binary, $version, $useNice)
2749
+ {
2750
 
2751
+ //$this->logLn('Trying binary: ' . $binary);
2752
+ $commandOptions = $this->createCommandLineOptions($version);
2753
+
2754
+ $returnCode = $this->executeBinary($binary, $commandOptions, $useNice);
2755
+ if ($returnCode == 0) {
2756
+ $this->logLn('Success');
2757
+ return true;
2758
  } else {
2759
+ $this->logLn(
2760
+ 'Exec failed (return code: ' . $returnCode . ')'
2761
+ );
2762
+ return false;
 
 
 
 
 
 
 
 
 
 
 
 
2763
  }
 
2764
  }
2765
 
2766
  protected function doActualConvert()
2767
  {
2768
+ $binaries = $this->discoverBinaries();
 
 
2769
 
2770
+ if (count($binaries) == 0) {
2771
+ throw new SystemRequirementsNotMetException(
2772
+ 'No cwebp binaries located. Check the conversion log for details.'
2773
+ );
2774
+ }
2775
 
2776
+ $versions = $this->detectVersions($binaries);
2777
+ if (count($versions['detected']) == 0) {
2778
+ //$this->logLn('None of the cwebp files located can be executed.');
2779
+ if (count($binaries) == 1) {
2780
+ $errorMsg = 'The cwebp file found cannot be can be executed.';
2781
+ } else {
2782
+ $errorMsg = 'None of the cwebp files located can be executed.';
2783
+ }
2784
+ $uniqueFailCodes = array_unique(array_values($versions['failed']));
2785
+ if (count($uniqueFailCodes) == 1) {
2786
+ $errorMsg .= ' ' . (count($binaries) == 1 ? 'It' : 'All') .
2787
+ ' failed with return code ' . $uniqueFailCodes[0];
2788
+ if ($uniqueFailCodes[0] == 126) {
2789
+ $errorMsg .= ' (permission denied)';
2790
+ }
2791
+ } else {
2792
+ $errorMsg .= ' Failure codes : ' . implode(', ', $uniqueFailCodes);
2793
+ }
2794
+
2795
+ throw new SystemRequirementsNotMetException($errorMsg);
2796
+ }
2797
 
2798
+ $binaryVersions = $versions['detected'];
2799
 
2800
+ if (count($binaries) > 1) {
2801
+ $this->logLn(
2802
+ 'Trying executing the cwebs found until success. Starting with the ones with highest version number.'
2803
+ );
2804
  }
2805
+ //$this->logLn('binary versions: ' . print_r($binaryVersions, true));
2806
+
2807
+ // Sort binaries so those with highest numbers comes first
2808
+ arsort($binaryVersions);
2809
 
2810
+ //$this->logLn('binary versions (ordered by version): ' . print_r($binaryVersions, true));
2811
+
2812
+ $useNice = (($this->options['use-nice']) && self::hasNiceSupport());
2813
+
2814
+ $success = false;
2815
+ foreach ($binaryVersions as $binary => $version) {
2816
+ if ($this->tryBinary($binary, $version, $useNice)) {
2817
+ $success = true;
2818
+ break;
2819
+ }
2820
  }
2821
 
2822
  // cwebp sets file permissions to 664 but instead ..
2831
  $permissions = $fileStatistics['mode'] & 0000666;
2832
  chmod($this->destination, $permissions);
2833
  }
2834
+ } else {
2835
+ throw new SystemRequirementsNotMetException('Failed converting. Check the conversion log for details.');
 
 
2836
  }
2837
  }
2838
  }
2892
  if (!empty($this->options['api-key'])) {
2893
  return $this->options['api-key'];
2894
  }
2895
+ if (defined('WEBPCONVERT_EWWW_API_KEY')) {
2896
+ return constant('WEBPCONVERT_EWWW_API_KEY');
2897
+ }
2898
+ if (!empty(getenv('WEBPCONVERT_EWWW_API_KEY'))) {
2899
+ return getenv('WEBPCONVERT_EWWW_API_KEY');
2900
  }
2901
  return false;
2902
  }
3878
 
3879
  private function getPath()
3880
  {
3881
+ if (defined('WEBPCONVERT_GRAPHICSMAGICK_PATH')) {
3882
+ return constant('WEBPCONVERT_GRAPHICSMAGICK_PATH');
3883
+ }
3884
+ if (!empty(getenv('WEBPCONVERT_GRAPHICSMAGICK_PATH'))) {
3885
+ return getenv('WEBPCONVERT_GRAPHICSMAGICK_PATH');
3886
  }
3887
+ return 'gm';
3888
  }
3889
 
3890
  public function isInstalled()
4052
 
4053
  private function getPath()
4054
  {
4055
+ if (defined('WEBPCONVERT_IMAGEMAGICK_PATH')) {
4056
+ return constant('WEBPCONVERT_IMAGEMAGICK_PATH');
 
 
 
 
 
 
 
4057
  }
4058
+ if (!empty(getenv('WEBPCONVERT_IMAGEMAGICK_PATH'))) {
4059
+ return getenv('WEBPCONVERT_IMAGEMAGICK_PATH');
4060
+ }
4061
+ return 'convert';
4062
  }
4063
 
4064
  private function getVersion()
4616
  $this->ln();
4617
  $this->logLn('Stack failed in ' . round((microtime(true) - $beginTimeStack) * 1000) . ' ms');
4618
 
4619
+ // Hm, Scrutinizer complains that $anyRuntimeErrors is always false. But that is not true!
4620
  if ($anyRuntimeErrors) {
4621
  // At least one converter failed
4622
  throw new ConversionFailedException(
4623
+ 'None of the converters in the stack could convert the image.'
 
4624
  );
4625
  } else {
4626
  // All converters threw a SystemRequirementsNotMetException
4958
  return $this->options['api-key'];
4959
  }
4960
  }
4961
+ if (defined('WEBPCONVERT_WPC_API_KEY')) {
4962
+ return constant('WEBPCONVERT_WPC_API_KEY');
4963
+ }
4964
+ if (!empty(getenv('WEBPCONVERT_WPC_API_KEY'))) {
4965
+ return getenv('WEBPCONVERT_WPC_API_KEY');
4966
  }
4967
  return '';
4968
  }
4977
  if (!empty($this->options['api-url'])) {
4978
  return $this->options['api-url'];
4979
  }
4980
+ if (defined('WEBPCONVERT_WPC_API_URL')) {
4981
+ return constant('WEBPCONVERT_WPC_API_URL');
4982
+ }
4983
+ if (!empty(getenv('WEBPCONVERT_WPC_API_URL'))) {
4984
+ return getenv('WEBPCONVERT_WPC_API_URL');
4985
  }
4986
  return '';
4987
  }
5932
  $options['log-call-arguments'] = true;
5933
  WebPConvert::convert($source, $destination, $options, $echoLogger);
5934
  } catch (\Exception $e) {
 
 
5935
  $msg = $e->getMessage();
 
5936
  echo '<b>' . $msg . '</b>';
5937
 
5938
  //echo '<p>Rethrowing exception for your convenience</p>';
vendor/rosell-dk/webp-convert/src-build/webp-on-demand-2.inc CHANGED
@@ -461,7 +461,7 @@ abstract class AbstractConverter
461
  if (isset($trace['file']) && isset($trace['line'])) {
462
  $this->logLn(
463
  $trace['file'] . ':' . $trace['line']
464
- );
465
  }
466
  }
467
  throw $e;
@@ -518,6 +518,8 @@ abstract class AbstractConverter
518
  public function getMimeTypeOfSource()
519
  {
520
  if (!isset($this->sourceMimeType)) {
 
 
521
  $this->sourceMimeType = ImageMimeTypeGuesser::lenientGuess($this->source);
522
  }
523
  return $this->sourceMimeType;
@@ -2083,7 +2085,9 @@ trait EncodingAutoTrait
2083
  abstract public function getOptions();
2084
  abstract protected function setOption($optionName, $optionValue);
2085
  abstract protected function logLn($msg, $style = '');
 
2086
  abstract protected function ln();
 
2087
 
2088
  public function supportsLossless()
2089
  {
@@ -2281,12 +2285,14 @@ class Cwebp extends AbstractConverter
2281
  // OS-specific binaries included in this library, along with hashes
2282
  // If other binaries are going to be added, notice that the first argument is what PHP_OS returns.
2283
  // (possible values, see here: https://stackoverflow.com/questions/738823/possible-values-for-php-os)
 
2284
  private static $suppliedBinariesInfo = [
2285
  'WINNT' => [ 'cwebp.exe', '49e9cb98db30bfa27936933e6fd94d407e0386802cb192800d9fd824f6476873'],
2286
  'Darwin' => [ 'cwebp-mac12', 'a06a3ee436e375c89dbc1b0b2e8bd7729a55139ae072ed3f7bd2e07de0ebb379'],
2287
  'SunOS' => [ 'cwebp-sol', '1febaffbb18e52dc2c524cda9eefd00c6db95bc388732868999c0f48deb73b4f'],
2288
  'FreeBSD' => [ 'cwebp-fbsd', 'e5cbea11c97fadffe221fdf57c093c19af2737e4bbd2cb3cd5e908de64286573'],
2289
- 'Linux' => [ 'cwebp-linux', '916623e5e9183237c851374d969aebdb96e0edc0692ab7937b95ea67dc3b2568']
 
2290
  ];
2291
 
2292
  public function checkOperationality()
@@ -2305,10 +2311,13 @@ class Cwebp extends AbstractConverter
2305
 
2306
  private function executeBinary($binary, $commandOptions, $useNice)
2307
  {
 
 
2308
  $command = ($useNice ? 'nice ' : '') . $binary . ' ' . $commandOptions;
2309
 
2310
  //$logger->logLn('command options:' . $commandOptions);
2311
- //$logger->logLn('Trying to execute binary:' . $binary);
 
2312
  exec($command, $output, $returnCode);
2313
  $this->logExecOutput($output);
2314
  /*
@@ -2362,19 +2371,42 @@ class Cwebp extends AbstractConverter
2362
  }
2363
 
2364
  /**
2365
- * Build command line options
 
 
2366
  *
 
2367
  * @return string
2368
  */
2369
- private function createCommandLineOptions()
2370
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2371
  $options = $this->options;
2372
 
2373
  $cmdOptions = [];
2374
 
2375
  // Metadata (all, exif, icc, xmp or none (default))
2376
  // Comma-separated list of existing metadata to copy from input to output
2377
- $cmdOptions[] = '-metadata ' . $options['metadata'];
 
 
2378
 
2379
  // preset. Appears first in the list as recommended in the docs
2380
  if (!is_null($options['preset'])) {
@@ -2406,18 +2438,31 @@ class Cwebp extends AbstractConverter
2406
 
2407
  // Losless PNG conversion
2408
  if ($options['encoding'] == 'lossless') {
2409
- // No need to add -lossless when near-lossless is used
2410
- if ($options['near-lossless'] === 100) {
2411
  $cmdOptions[] = '-lossless';
2412
  }
2413
  }
2414
 
2415
  // Near-lossles
2416
  if ($options['near-lossless'] !== 100) {
2417
- // We only let near_lossless have effect when encoding is set to "lossless"
2418
- // otherwise encoding=auto would not work as expected
2419
- if ($options['encoding'] == 'lossless') {
2420
- $cmdOptions[] ='-near_lossless ' . $options['near-lossless'];
 
 
 
 
 
 
 
 
 
 
 
 
 
2421
  }
2422
  }
2423
 
@@ -2452,117 +2497,27 @@ class Cwebp extends AbstractConverter
2452
  $cmdOptions[] = '2>&1';
2453
 
2454
  $commandOptions = implode(' ', $cmdOptions);
2455
- $this->logLn('command line options:' . $commandOptions);
2456
 
2457
  return $commandOptions;
2458
  }
2459
 
2460
  /**
 
2461
  *
2462
- *
2463
- * @return string Error message if failure, empty string if successful
2464
- */
2465
- private function composeErrorMessageForCommonSystemPathsFailures($failureCodes)
2466
- {
2467
- if (count($failureCodes) == 1) {
2468
- switch ($failureCodes[0]) {
2469
- case 126:
2470
- return 'Permission denied. The user that the command was run with (' .
2471
- shell_exec('whoami') . ') does not have permission to execute any of the ' .
2472
- 'cweb binaries found in common system locations. ';
2473
- case 127:
2474
- return 'Found no cwebp binaries in any common system locations. ';
2475
- default:
2476
- return 'Tried executing cwebp binaries in common system locations. ' .
2477
- 'All failed (exit code: ' . $failureCodes[0] . '). ';
2478
- }
2479
- } else {
2480
- /**
2481
- * $failureCodesBesides127 is used to check first position ($failureCodesBesides127[0])
2482
- * however position can vary as index can be 1 or something else. array_values() would
2483
- * always start from 0.
2484
- */
2485
- $failureCodesBesides127 = array_values(array_diff($failureCodes, [127]));
2486
-
2487
- if (count($failureCodesBesides127) == 1) {
2488
- switch ($failureCodesBesides127[0]) {
2489
- case 126:
2490
- return 'Permission denied. The user that the command was run with (' .
2491
- shell_exec('whoami') . ') does not have permission to execute any of the cweb ' .
2492
- 'binaries found in common system locations. ';
2493
- break;
2494
- default:
2495
- return 'Tried executing cwebp binaries in common system locations. ' .
2496
- 'All failed (exit code: ' . $failureCodesBesides127[0] . '). ';
2497
- }
2498
- } else {
2499
- return 'None of the cwebp binaries in the common system locations could be executed ' .
2500
- '(mixed results - got the following exit codes: ' . implode(',', $failureCodes) . '). ';
2501
- }
2502
- }
2503
- }
2504
-
2505
- /**
2506
- * Try executing cwebp in common system paths
2507
- *
2508
- * @param boolean $useNice Whether to use nice
2509
- * @param string $commandOptions for the exec call
2510
- *
2511
- * @return array Unique failure codes in case of failure, empty array in case of success
2512
- */
2513
- private function tryCommonSystemPaths($useNice, $commandOptions)
2514
- {
2515
- $failureCodes = [];
2516
-
2517
- $paths = self::$cwebpDefaultPaths;
2518
-
2519
- if (!empty(getenv('CWEBP_PATH'))) {
2520
- array_unshift($paths, getenv('CWEBP_PATH'));
2521
- }
2522
-
2523
- // Loop through paths
2524
- foreach ($paths as $index => $binary) {
2525
- $returnCode = $this->executeBinary($binary, $commandOptions, $useNice);
2526
- if ($returnCode == 0) {
2527
- $this->logLn('Successfully executed binary: ' . $binary);
2528
- return [];
2529
- } else {
2530
- if ($returnCode == 127) {
2531
- $this->logLn(
2532
- 'Trying to execute binary: ' . $binary . '. Failed (not found)'
2533
- );
2534
- } else {
2535
- $this->logLn(
2536
- 'Trying to execute binary: ' . $binary . '. Failed (return code: ' . $returnCode . ')'
2537
- );
2538
- }
2539
- if (!in_array($returnCode, $failureCodes)) {
2540
- $failureCodes[] = $returnCode;
2541
- }
2542
- }
2543
- }
2544
- return $failureCodes;
2545
- }
2546
-
2547
- /**
2548
- * Try executing supplied cwebp for PHP_OS.
2549
- *
2550
- * @param boolean $useNice Whether to use nice
2551
- * @param string $commandOptions for the exec call
2552
- * @param array $failureCodesForCommonSystemPaths Return codes from the other attempt
2553
- * (in order to produce short error message)
2554
- *
2555
- * @return string Error message if failure, empty string if successful
2556
  */
2557
- private function trySuppliedBinaryForOS($useNice, $commandOptions, $failureCodesForCommonSystemPaths)
2558
  {
2559
- $this->logLn('Trying to execute supplied binary for OS: ' . PHP_OS);
2560
 
2561
  // Try supplied binary (if available for OS, and hash is correct)
2562
  $options = $this->options;
2563
  if (!isset(self::$suppliedBinariesInfo[PHP_OS])) {
2564
- return 'No supplied binaries found for OS:' . PHP_OS;
 
2565
  }
 
2566
 
2567
  $info = self::$suppliedBinariesInfo[PHP_OS];
2568
 
@@ -2571,14 +2526,13 @@ class Cwebp extends AbstractConverter
2571
 
2572
  $binaryFile = __DIR__ . '/' . $options['rel-path-to-precompiled-binaries'] . '/' . $file;
2573
 
2574
-
2575
  // The file should exist, but may have been removed manually.
2576
  if (!file_exists($binaryFile)) {
2577
- return 'Supplied binary not found! It ought to be here:' . $binaryFile;
 
2578
  }
2579
 
2580
  // File exists, now generate its hash
2581
-
2582
  // hash_file() is normally available, but it is not always
2583
  // - https://stackoverflow.com/questions/17382712/php-5-3-20-undefined-function-hash
2584
  // If available, validate that hash is correct.
@@ -2587,92 +2541,204 @@ class Cwebp extends AbstractConverter
2587
  $binaryHash = hash_file('sha256', $binaryFile);
2588
 
2589
  if ($binaryHash != $hash) {
2590
- return 'Binary checksum of supplied binary is invalid! ' .
 
2591
  'Did you transfer with FTP, but not in binary mode? ' .
2592
  'File:' . $binaryFile . '. ' .
2593
  'Expected checksum: ' . $hash . '. ' .
2594
- 'Actual checksum:' . $binaryHash . '.';
 
 
2595
  }
2596
  }
 
 
2597
 
2598
- $returnCode = $this->executeBinary($binaryFile, $commandOptions, $useNice);
2599
- if ($returnCode == 0) {
2600
- // yay!
2601
- $this->logLn('success!');
2602
- return '';
 
 
 
 
 
 
 
 
 
 
2603
  }
2604
 
2605
- $errorMsg = 'Tried executing supplied binary for ' . PHP_OS . ', ' .
2606
- ($options['try-common-system-paths'] ? 'but that failed too' : 'but failed');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2607
 
 
 
 
 
 
 
2608
 
2609
- if (($options['try-common-system-paths']) && (count($failureCodesForCommonSystemPaths) > 0)) {
2610
- // check if it was the same error
2611
- // if it was, simply refer to that with "(same problem)"
2612
- $majorFailCode = 0;
2613
- if (count($failureCodesForCommonSystemPaths) == 1) {
2614
- $majorFailCode = $failureCodesForCommonSystemPaths[0];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2615
  } else {
2616
- $failureCodesBesides127 = array_values(array_diff($failureCodesForCommonSystemPaths, [127]));
2617
- if (count($failureCodesBesides127) == 1) {
2618
- $majorFailCode = $failureCodesBesides127[0];
2619
- } else {
2620
- // it cannot be summarized into a single code
 
 
 
 
2621
  }
2622
  }
2623
- if ($majorFailCode != 0) {
2624
- $errorMsg .= ' (same problem)';
2625
- return $errorMsg;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2626
  }
2627
  }
 
 
 
 
 
 
 
 
2628
 
2629
- if ($returnCode > 128) {
2630
- $errorMsg .= '. The binary did not work (exit code: ' . $returnCode . '). ' .
2631
- 'Check out https://github.com/rosell-dk/webp-convert/issues/92';
 
 
 
 
2632
  } else {
2633
- switch ($returnCode) {
2634
- case 0:
2635
- // success!
2636
- break;
2637
- case 126:
2638
- $errorMsg .= ': Permission denied. The user that the command was run' .
2639
- ' with (' . shell_exec('whoami') . ') does not have permission to ' .
2640
- 'execute that binary.';
2641
- break;
2642
- case 127:
2643
- $errorMsg .= '. The binary was not found! ' .
2644
- 'It ought to be here: ' . $binaryFile;
2645
- break;
2646
- default:
2647
- $errorMsg .= ' (exit code:' . $returnCode . ').';
2648
- }
2649
  }
2650
- return $errorMsg;
2651
  }
2652
 
2653
  protected function doActualConvert()
2654
  {
2655
- $errorMsg = '';
2656
- $options = $this->options;
2657
- $useNice = (($options['use-nice']) && self::hasNiceSupport());
2658
 
2659
- $commandOptions = $this->createCommandLineOptions();
 
 
 
 
2660
 
2661
- // Try all common paths that exists
2662
- $success = false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2663
 
2664
- $failureCodes = [];
2665
 
2666
- if ($options['try-common-system-paths']) {
2667
- $failureCodes = $this->tryCommonSystemPaths($useNice, $commandOptions);
2668
- $success = (count($failureCodes) == 0);
2669
- $errorMsg = $this->composeErrorMessageForCommonSystemPathsFailures($failureCodes);
2670
  }
 
 
 
 
2671
 
2672
- if (!$success && $options['try-supplied-binary-for-os']) {
2673
- $errorMsg2 = $this->trySuppliedBinaryForOS($useNice, $commandOptions, $failureCodes);
2674
- $errorMsg .= $errorMsg2;
2675
- $success = ($errorMsg2 == '');
 
 
 
 
 
 
2676
  }
2677
 
2678
  // cwebp sets file permissions to 664 but instead ..
@@ -2687,10 +2753,8 @@ class Cwebp extends AbstractConverter
2687
  $permissions = $fileStatistics['mode'] & 0000666;
2688
  chmod($this->destination, $permissions);
2689
  }
2690
- }
2691
-
2692
- if (!$success) {
2693
- throw new SystemRequirementsNotMetException($errorMsg);
2694
  }
2695
  }
2696
  }
@@ -2750,8 +2814,11 @@ class Ewww extends AbstractConverter
2750
  if (!empty($this->options['api-key'])) {
2751
  return $this->options['api-key'];
2752
  }
2753
- if (!empty(getenv('EWWW_API_KEY'))) {
2754
- return getenv('EWWW_API_KEY');
 
 
 
2755
  }
2756
  return false;
2757
  }
@@ -3733,11 +3800,13 @@ class GraphicsMagick extends AbstractConverter
3733
 
3734
  private function getPath()
3735
  {
3736
- if (empty(getenv('GRAPHICSMAGICK_PATH'))) {
3737
- return 'gm';
3738
- } else {
3739
- return getenv('GRAPHICSMAGICK_PATH');
 
3740
  }
 
3741
  }
3742
 
3743
  public function isInstalled()
@@ -3905,16 +3974,13 @@ class ImageMagick extends AbstractConverter
3905
 
3906
  private function getPath()
3907
  {
3908
- // Should we use "magick" or "convert" command?
3909
- // It seems they do the same. But which is best supported? Which is mostly available (whitelisted)?
3910
- // Should we perhaps try both?
3911
- // For now, we just go with "convert"
3912
-
3913
- if (!empty(getenv('IMAGEMAGICK_PATH'))) {
3914
- return getenv('IMAGEMAGICK_PATH');
3915
- } else {
3916
- return 'convert';
3917
  }
 
 
 
 
3918
  }
3919
 
3920
  private function getVersion()
@@ -4472,11 +4538,11 @@ class Stack extends AbstractConverter
4472
  $this->ln();
4473
  $this->logLn('Stack failed in ' . round((microtime(true) - $beginTimeStack) * 1000) . ' ms');
4474
 
 
4475
  if ($anyRuntimeErrors) {
4476
  // At least one converter failed
4477
  throw new ConversionFailedException(
4478
- 'None of the converters in the stack could convert the image. ' .
4479
- 'At least one failed, even though its requirements seemed to be met.'
4480
  );
4481
  } else {
4482
  // All converters threw a SystemRequirementsNotMetException
@@ -4814,8 +4880,11 @@ class Wpc extends AbstractConverter
4814
  return $this->options['api-key'];
4815
  }
4816
  }
4817
- if (!empty(getenv('WPC_API_KEY'))) {
4818
- return getenv('WPC_API_KEY');
 
 
 
4819
  }
4820
  return '';
4821
  }
@@ -4830,8 +4899,11 @@ class Wpc extends AbstractConverter
4830
  if (!empty($this->options['api-url'])) {
4831
  return $this->options['api-url'];
4832
  }
4833
- if (!empty(getenv('WPC_API_URL'))) {
4834
- return getenv('WPC_API_URL');
 
 
 
4835
  }
4836
  return '';
4837
  }
@@ -5730,10 +5802,7 @@ class Report
5730
  $options['log-call-arguments'] = true;
5731
  WebPConvert::convert($source, $destination, $options, $echoLogger);
5732
  } catch (\Exception $e) {
5733
- $success = false;
5734
-
5735
  $msg = $e->getMessage();
5736
-
5737
  echo '<b>' . $msg . '</b>';
5738
 
5739
  //echo '<p>Rethrowing exception for your convenience</p>';
461
  if (isset($trace['file']) && isset($trace['line'])) {
462
  $this->logLn(
463
  $trace['file'] . ':' . $trace['line']
464
+ );
465
  }
466
  }
467
  throw $e;
518
  public function getMimeTypeOfSource()
519
  {
520
  if (!isset($this->sourceMimeType)) {
521
+ // PS: Scrutinizer complains that ImageMimeTypeGuesser::lenientGuess could also return a boolean
522
+ // but this is not true! - it returns string|false|null, just as this method does.
523
  $this->sourceMimeType = ImageMimeTypeGuesser::lenientGuess($this->source);
524
  }
525
  return $this->sourceMimeType;
2085
  abstract public function getOptions();
2086
  abstract protected function setOption($optionName, $optionValue);
2087
  abstract protected function logLn($msg, $style = '');
2088
+ abstract protected function log($msg, $style = '');
2089
  abstract protected function ln();
2090
+ abstract protected function logReduction($source, $destination);
2091
 
2092
  public function supportsLossless()
2093
  {
2285
  // OS-specific binaries included in this library, along with hashes
2286
  // If other binaries are going to be added, notice that the first argument is what PHP_OS returns.
2287
  // (possible values, see here: https://stackoverflow.com/questions/738823/possible-values-for-php-os)
2288
+ // Got the precompiled binaries here: https://developers.google.com/speed/webp/docs/precompiled
2289
  private static $suppliedBinariesInfo = [
2290
  'WINNT' => [ 'cwebp.exe', '49e9cb98db30bfa27936933e6fd94d407e0386802cb192800d9fd824f6476873'],
2291
  'Darwin' => [ 'cwebp-mac12', 'a06a3ee436e375c89dbc1b0b2e8bd7729a55139ae072ed3f7bd2e07de0ebb379'],
2292
  'SunOS' => [ 'cwebp-sol', '1febaffbb18e52dc2c524cda9eefd00c6db95bc388732868999c0f48deb73b4f'],
2293
  'FreeBSD' => [ 'cwebp-fbsd', 'e5cbea11c97fadffe221fdf57c093c19af2737e4bbd2cb3cd5e908de64286573'],
2294
+ 'Linux' => [ 'cwebp-linux2', 'd6142e9da2f1cab541de10a31527c597225fff5644e66e31d62bb391c41bfbf4'] // 1.0.2
2295
+
2296
  ];
2297
 
2298
  public function checkOperationality()
2311
 
2312
  private function executeBinary($binary, $commandOptions, $useNice)
2313
  {
2314
+ //$version = $this->detectVersion($binary);
2315
+
2316
  $command = ($useNice ? 'nice ' : '') . $binary . ' ' . $commandOptions;
2317
 
2318
  //$logger->logLn('command options:' . $commandOptions);
2319
+ $this->logLn('Trying to convert by executing the following command:');
2320
+ $this->logLn($command);
2321
  exec($command, $output, $returnCode);
2322
  $this->logExecOutput($output);
2323
  /*
2371
  }
2372
 
2373
  /**
2374
+ * Build command line options for a given version of cwebp.
2375
+ *
2376
+ * The "-near_lossless" param is not supported on older versions of cwebp, so skip on those.
2377
  *
2378
+ * @param string $version Version of cwebp.
2379
  * @return string
2380
  */
2381
+ private function createCommandLineOptions($version)
2382
  {
2383
+
2384
+ $this->logLn('Creating command line options for version: ' . $version);
2385
+
2386
+ // we only need two decimal places for version.
2387
+ // convert to number to make it easier to compare
2388
+ $version = preg_match('#^\d+\.\d+#', $version, $matches);
2389
+ $versionNum = 0;
2390
+ if (isset($matches[0])) {
2391
+ $versionNum = floatval($matches[0]);
2392
+ } else {
2393
+ $this->logLn(
2394
+ 'Could not extract version number from the following version string: ' . $version,
2395
+ 'bold'
2396
+ );
2397
+ }
2398
+
2399
+ //$this->logLn('version:' . strval($versionNum));
2400
+
2401
  $options = $this->options;
2402
 
2403
  $cmdOptions = [];
2404
 
2405
  // Metadata (all, exif, icc, xmp or none (default))
2406
  // Comma-separated list of existing metadata to copy from input to output
2407
+ if ($versionNum >= 0.3) {
2408
+ $cmdOptions[] = '-metadata ' . $options['metadata'];
2409
+ }
2410
 
2411
  // preset. Appears first in the list as recommended in the docs
2412
  if (!is_null($options['preset'])) {
2438
 
2439
  // Losless PNG conversion
2440
  if ($options['encoding'] == 'lossless') {
2441
+ // No need to add -lossless when near-lossless is used (on version >= 0.5)
2442
+ if (($options['near-lossless'] === 100) || ($versionNum < 0.5)) {
2443
  $cmdOptions[] = '-lossless';
2444
  }
2445
  }
2446
 
2447
  // Near-lossles
2448
  if ($options['near-lossless'] !== 100) {
2449
+ if ($versionNum < 0.5) {
2450
+ $this->logLn(
2451
+ 'The near-lossless option is not supported on this (rather old) version of cwebp' .
2452
+ '- skipping it.',
2453
+ 'italic'
2454
+ );
2455
+ } else {
2456
+ // We only let near_lossless have effect when encoding is set to "lossless"
2457
+ // otherwise encoding=auto would not work as expected
2458
+
2459
+ if ($options['encoding'] == 'lossless') {
2460
+ $cmdOptions[] ='-near_lossless ' . $options['near-lossless'];
2461
+ } else {
2462
+ $this->logLn(
2463
+ 'The near-lossless option ignored for lossy'
2464
+ );
2465
+ }
2466
  }
2467
  }
2468
 
2497
  $cmdOptions[] = '2>&1';
2498
 
2499
  $commandOptions = implode(' ', $cmdOptions);
2500
+ //$this->logLn('command line options:' . $commandOptions);
2501
 
2502
  return $commandOptions;
2503
  }
2504
 
2505
  /**
2506
+ * Get path for supplied binary for current OS - and validate hash.
2507
  *
2508
+ * @return string|false False if something is wrong, otherwise the path.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2509
  */
2510
+ private function getSuppliedBinaryPathForOS()
2511
  {
2512
+ $this->log('Checking if we have a supplied binary for OS: ' . PHP_OS . '... ');
2513
 
2514
  // Try supplied binary (if available for OS, and hash is correct)
2515
  $options = $this->options;
2516
  if (!isset(self::$suppliedBinariesInfo[PHP_OS])) {
2517
+ $this->logLn('No we dont - not for that OS');
2518
+ return false;
2519
  }
2520
+ $this->logLn('We do.');
2521
 
2522
  $info = self::$suppliedBinariesInfo[PHP_OS];
2523
 
2526
 
2527
  $binaryFile = __DIR__ . '/' . $options['rel-path-to-precompiled-binaries'] . '/' . $file;
2528
 
 
2529
  // The file should exist, but may have been removed manually.
2530
  if (!file_exists($binaryFile)) {
2531
+ $this->logLn('Supplied binary not found! It ought to be here:' . $binaryFile, 'italic');
2532
+ return false;
2533
  }
2534
 
2535
  // File exists, now generate its hash
 
2536
  // hash_file() is normally available, but it is not always
2537
  // - https://stackoverflow.com/questions/17382712/php-5-3-20-undefined-function-hash
2538
  // If available, validate that hash is correct.
2541
  $binaryHash = hash_file('sha256', $binaryFile);
2542
 
2543
  if ($binaryHash != $hash) {
2544
+ $this->logLn(
2545
+ 'Binary checksum of supplied binary is invalid! ' .
2546
  'Did you transfer with FTP, but not in binary mode? ' .
2547
  'File:' . $binaryFile . '. ' .
2548
  'Expected checksum: ' . $hash . '. ' .
2549
+ 'Actual checksum:' . $binaryHash . '.',
2550
+ 'bold'
2551
+ );
2552
  }
2553
  }
2554
+ return $binaryFile;
2555
+ }
2556
 
2557
+ private function discoverBinaries()
2558
+ {
2559
+ $this->logLn('Locating cwebp binaries');
2560
+
2561
+ if (defined('WEBPCONVERT_CWEBP_PATH')) {
2562
+ $this->logLn('WEBPCONVERT_CWEBP_PATH was defined, so using that path and ignoring any other');
2563
+ //$this->logLn('Value: "' . getenv('WEBPCONVERT_CWEBP_PATH') . '"');
2564
+ return [constant('WEBPCONVERT_CWEBP_PATH')];
2565
+ }
2566
+ if (!empty(getenv('WEBPCONVERT_CWEBP_PATH'))) {
2567
+ $this->logLn(
2568
+ 'WEBPCONVERT_CWEBP_PATH environment variable was set, so using that path and ignoring any other'
2569
+ );
2570
+ //$this->logLn('Value: "' . getenv('WEBPCONVERT_CWEBP_PATH') . '"');
2571
+ return [getenv('WEBPCONVERT_CWEBP_PATH')];
2572
  }
2573
 
2574
+ $binaries = [];
2575
+ if ($this->options['try-common-system-paths']) {
2576
+ foreach (self::$cwebpDefaultPaths as $binary) {
2577
+ if (@file_exists($binary)) {
2578
+ $binaries[] = $binary;
2579
+ }
2580
+ }
2581
+ if (count($binaries) == 0) {
2582
+ $this->logLn('No cwebp binaries where located in common system locations');
2583
+ } else {
2584
+ $this->logLn(strval(count($binaries)) . ' cwebp binaries found in common system locations');
2585
+ }
2586
+ }
2587
+ // TODO: exec('whereis cwebp');
2588
+ if ($this->options['try-supplied-binary-for-os']) {
2589
+ $suppliedBinary = $this->getSuppliedBinaryPathForOS();
2590
+ if ($suppliedBinary !== false) {
2591
+ $binaries[] = $suppliedBinary;
2592
+ }
2593
+ } else {
2594
+ $this->logLn('Configured not to try the cwebp binary that comes bundled with webp-convert');
2595
+ }
2596
 
2597
+ if (count($binaries) == 0) {
2598
+ $this->logLn('No cwebp binaries to try!');
2599
+ }
2600
+ $this->logLn('A total of ' . strval(count($binaries)) . ' cwebp binaries where found');
2601
+ return $binaries;
2602
+ }
2603
 
2604
+ /**
2605
+ *
2606
+ * @return string|int Version string (ie "1.0.2") OR return code, in case of failure
2607
+ */
2608
+ private function detectVersion($binary)
2609
+ {
2610
+ //$this->logLn('Examining binary: ' . $binary);
2611
+ $command = $binary . ' -version';
2612
+ $this->log('Executing: ' . $command);
2613
+ exec($command, $output, $returnCode);
2614
+
2615
+ if ($returnCode == 0) {
2616
+ //$this->logLn('Success');
2617
+ if (isset($output[0])) {
2618
+ $this->logLn('. Result: version: ' . $output[0]);
2619
+ return $output[0];
2620
+ }
2621
+ } else {
2622
+ $this->logExecOutput($output);
2623
+ $this->logLn('');
2624
+ if ($returnCode == 127) {
2625
+ $this->logLn('Exec failed (the cwebp binary was not found at path: ' . $binary. ')');
2626
  } else {
2627
+ $this->logLn(
2628
+ 'Exec failed (return code: ' . $returnCode . ')'
2629
+ );
2630
+ if ($returnCode == 126) {
2631
+ $this->logLn(
2632
+ 'PS: Return code 126 means "Permission denied". The user that the command was run with does ' .
2633
+ 'not have permission to execute that binary.'
2634
+ );
2635
+ // TODO: further info: shell_exec('whoami')
2636
  }
2637
  }
2638
+ return $returnCode;
2639
+ }
2640
+ }
2641
+
2642
+ /**
2643
+ * Check versions for binaries, and return array (indexed by the binary, value being the version of the binary).
2644
+ *
2645
+ * @return array
2646
+ */
2647
+ private function detectVersions($binaries)
2648
+ {
2649
+ $binariesWithVersions = [];
2650
+ $binariesWithFailCodes = [];
2651
+
2652
+ $this->logLn(
2653
+ 'Detecting versions of the cwebp binaries found (and verifying that they can be executed in the process)'
2654
+ );
2655
+ foreach ($binaries as $binary) {
2656
+ $versionStringOrFailCode = $this->detectVersion($binary);
2657
+ // $this->logLn($binary . ': ' . $versionString);
2658
+ if (gettype($versionStringOrFailCode) == 'string') {
2659
+ $binariesWithVersions[$binary] = $versionStringOrFailCode;
2660
+ } else {
2661
+ $binariesWithFailCodes[$binary] = $versionStringOrFailCode;
2662
  }
2663
  }
2664
+ return ['detected' => $binariesWithVersions, 'failed' => $binariesWithFailCodes];
2665
+ }
2666
+
2667
+ /**
2668
+ * @return boolean success or not.
2669
+ */
2670
+ private function tryBinary($binary, $version, $useNice)
2671
+ {
2672
 
2673
+ //$this->logLn('Trying binary: ' . $binary);
2674
+ $commandOptions = $this->createCommandLineOptions($version);
2675
+
2676
+ $returnCode = $this->executeBinary($binary, $commandOptions, $useNice);
2677
+ if ($returnCode == 0) {
2678
+ $this->logLn('Success');
2679
+ return true;
2680
  } else {
2681
+ $this->logLn(
2682
+ 'Exec failed (return code: ' . $returnCode . ')'
2683
+ );
2684
+ return false;
 
 
 
 
 
 
 
 
 
 
 
 
2685
  }
 
2686
  }
2687
 
2688
  protected function doActualConvert()
2689
  {
2690
+ $binaries = $this->discoverBinaries();
 
 
2691
 
2692
+ if (count($binaries) == 0) {
2693
+ throw new SystemRequirementsNotMetException(
2694
+ 'No cwebp binaries located. Check the conversion log for details.'
2695
+ );
2696
+ }
2697
 
2698
+ $versions = $this->detectVersions($binaries);
2699
+ if (count($versions['detected']) == 0) {
2700
+ //$this->logLn('None of the cwebp files located can be executed.');
2701
+ if (count($binaries) == 1) {
2702
+ $errorMsg = 'The cwebp file found cannot be can be executed.';
2703
+ } else {
2704
+ $errorMsg = 'None of the cwebp files located can be executed.';
2705
+ }
2706
+ $uniqueFailCodes = array_unique(array_values($versions['failed']));
2707
+ if (count($uniqueFailCodes) == 1) {
2708
+ $errorMsg .= ' ' . (count($binaries) == 1 ? 'It' : 'All') .
2709
+ ' failed with return code ' . $uniqueFailCodes[0];
2710
+ if ($uniqueFailCodes[0] == 126) {
2711
+ $errorMsg .= ' (permission denied)';
2712
+ }
2713
+ } else {
2714
+ $errorMsg .= ' Failure codes : ' . implode(', ', $uniqueFailCodes);
2715
+ }
2716
+
2717
+ throw new SystemRequirementsNotMetException($errorMsg);
2718
+ }
2719
 
2720
+ $binaryVersions = $versions['detected'];
2721
 
2722
+ if (count($binaries) > 1) {
2723
+ $this->logLn(
2724
+ 'Trying executing the cwebs found until success. Starting with the ones with highest version number.'
2725
+ );
2726
  }
2727
+ //$this->logLn('binary versions: ' . print_r($binaryVersions, true));
2728
+
2729
+ // Sort binaries so those with highest numbers comes first
2730
+ arsort($binaryVersions);
2731
 
2732
+ //$this->logLn('binary versions (ordered by version): ' . print_r($binaryVersions, true));
2733
+
2734
+ $useNice = (($this->options['use-nice']) && self::hasNiceSupport());
2735
+
2736
+ $success = false;
2737
+ foreach ($binaryVersions as $binary => $version) {
2738
+ if ($this->tryBinary($binary, $version, $useNice)) {
2739
+ $success = true;
2740
+ break;
2741
+ }
2742
  }
2743
 
2744
  // cwebp sets file permissions to 664 but instead ..
2753
  $permissions = $fileStatistics['mode'] & 0000666;
2754
  chmod($this->destination, $permissions);
2755
  }
2756
+ } else {
2757
+ throw new SystemRequirementsNotMetException('Failed converting. Check the conversion log for details.');
 
 
2758
  }
2759
  }
2760
  }
2814
  if (!empty($this->options['api-key'])) {
2815
  return $this->options['api-key'];
2816
  }
2817
+ if (defined('WEBPCONVERT_EWWW_API_KEY')) {
2818
+ return constant('WEBPCONVERT_EWWW_API_KEY');
2819
+ }
2820
+ if (!empty(getenv('WEBPCONVERT_EWWW_API_KEY'))) {
2821
+ return getenv('WEBPCONVERT_EWWW_API_KEY');
2822
  }
2823
  return false;
2824
  }
3800
 
3801
  private function getPath()
3802
  {
3803
+ if (defined('WEBPCONVERT_GRAPHICSMAGICK_PATH')) {
3804
+ return constant('WEBPCONVERT_GRAPHICSMAGICK_PATH');
3805
+ }
3806
+ if (!empty(getenv('WEBPCONVERT_GRAPHICSMAGICK_PATH'))) {
3807
+ return getenv('WEBPCONVERT_GRAPHICSMAGICK_PATH');
3808
  }
3809
+ return 'gm';
3810
  }
3811
 
3812
  public function isInstalled()
3974
 
3975
  private function getPath()
3976
  {
3977
+ if (defined('WEBPCONVERT_IMAGEMAGICK_PATH')) {
3978
+ return constant('WEBPCONVERT_IMAGEMAGICK_PATH');
 
 
 
 
 
 
 
3979
  }
3980
+ if (!empty(getenv('WEBPCONVERT_IMAGEMAGICK_PATH'))) {
3981
+ return getenv('WEBPCONVERT_IMAGEMAGICK_PATH');
3982
+ }
3983
+ return 'convert';
3984
  }
3985
 
3986
  private function getVersion()
4538
  $this->ln();
4539
  $this->logLn('Stack failed in ' . round((microtime(true) - $beginTimeStack) * 1000) . ' ms');
4540
 
4541
+ // Hm, Scrutinizer complains that $anyRuntimeErrors is always false. But that is not true!
4542
  if ($anyRuntimeErrors) {
4543
  // At least one converter failed
4544
  throw new ConversionFailedException(
4545
+ 'None of the converters in the stack could convert the image.'
 
4546
  );
4547
  } else {
4548
  // All converters threw a SystemRequirementsNotMetException
4880
  return $this->options['api-key'];
4881
  }
4882
  }
4883
+ if (defined('WEBPCONVERT_WPC_API_KEY')) {
4884
+ return constant('WEBPCONVERT_WPC_API_KEY');
4885
+ }
4886
+ if (!empty(getenv('WEBPCONVERT_WPC_API_KEY'))) {
4887
+ return getenv('WEBPCONVERT_WPC_API_KEY');
4888
  }
4889
  return '';
4890
  }
4899
  if (!empty($this->options['api-url'])) {
4900
  return $this->options['api-url'];
4901
  }
4902
+ if (defined('WEBPCONVERT_WPC_API_URL')) {
4903
+ return constant('WEBPCONVERT_WPC_API_URL');
4904
+ }
4905
+ if (!empty(getenv('WEBPCONVERT_WPC_API_URL'))) {
4906
+ return getenv('WEBPCONVERT_WPC_API_URL');
4907
  }
4908
  return '';
4909
  }
5802
  $options['log-call-arguments'] = true;
5803
  WebPConvert::convert($source, $destination, $options, $echoLogger);
5804
  } catch (\Exception $e) {
 
 
5805
  $msg = $e->getMessage();
 
5806
  echo '<b>' . $msg . '</b>';
5807
 
5808
  //echo '<p>Rethrowing exception for your convenience</p>';
vendor/rosell-dk/webp-convert/src/Convert/Converters/AbstractConverter.php CHANGED
@@ -324,7 +324,7 @@ abstract class AbstractConverter
324
  if (isset($trace['file']) && isset($trace['line'])) {
325
  $this->logLn(
326
  $trace['file'] . ':' . $trace['line']
327
- );
328
  }
329
  }
330
  throw $e;
@@ -381,6 +381,8 @@ abstract class AbstractConverter
381
  public function getMimeTypeOfSource()
382
  {
383
  if (!isset($this->sourceMimeType)) {
 
 
384
  $this->sourceMimeType = ImageMimeTypeGuesser::lenientGuess($this->source);
385
  }
386
  return $this->sourceMimeType;
324
  if (isset($trace['file']) && isset($trace['line'])) {
325
  $this->logLn(
326
  $trace['file'] . ':' . $trace['line']
327
+ );
328
  }
329
  }
330
  throw $e;
381
  public function getMimeTypeOfSource()
382
  {
383
  if (!isset($this->sourceMimeType)) {
384
+ // PS: Scrutinizer complains that ImageMimeTypeGuesser::lenientGuess could also return a boolean
385
+ // but this is not true! - it returns string|false|null, just as this method does.
386
  $this->sourceMimeType = ImageMimeTypeGuesser::lenientGuess($this->source);
387
  }
388
  return $this->sourceMimeType;
vendor/rosell-dk/webp-convert/src/Convert/Converters/Binaries/cwebp-linux CHANGED
Binary file
vendor/rosell-dk/webp-convert/src/Convert/Converters/ConverterTraits/EncodingAutoTrait.php CHANGED
@@ -20,7 +20,9 @@ trait EncodingAutoTrait
20
  abstract public function getOptions();
21
  abstract protected function setOption($optionName, $optionValue);
22
  abstract protected function logLn($msg, $style = '');
 
23
  abstract protected function ln();
 
24
 
25
  public function supportsLossless()
26
  {
20
  abstract public function getOptions();
21
  abstract protected function setOption($optionName, $optionValue);
22
  abstract protected function logLn($msg, $style = '');
23
+ abstract protected function log($msg, $style = '');
24
  abstract protected function ln();
25
+ abstract protected function logReduction($source, $destination);
26
 
27
  public function supportsLossless()
28
  {
vendor/rosell-dk/webp-convert/src/Convert/Converters/Cwebp.php CHANGED
@@ -54,12 +54,14 @@ class Cwebp extends AbstractConverter
54
  // OS-specific binaries included in this library, along with hashes
55
  // If other binaries are going to be added, notice that the first argument is what PHP_OS returns.
56
  // (possible values, see here: https://stackoverflow.com/questions/738823/possible-values-for-php-os)
 
57
  private static $suppliedBinariesInfo = [
58
  'WINNT' => [ 'cwebp.exe', '49e9cb98db30bfa27936933e6fd94d407e0386802cb192800d9fd824f6476873'],
59
  'Darwin' => [ 'cwebp-mac12', 'a06a3ee436e375c89dbc1b0b2e8bd7729a55139ae072ed3f7bd2e07de0ebb379'],
60
  'SunOS' => [ 'cwebp-sol', '1febaffbb18e52dc2c524cda9eefd00c6db95bc388732868999c0f48deb73b4f'],
61
  'FreeBSD' => [ 'cwebp-fbsd', 'e5cbea11c97fadffe221fdf57c093c19af2737e4bbd2cb3cd5e908de64286573'],
62
- 'Linux' => [ 'cwebp-linux', '916623e5e9183237c851374d969aebdb96e0edc0692ab7937b95ea67dc3b2568']
 
63
  ];
64
 
65
  public function checkOperationality()
@@ -78,10 +80,13 @@ class Cwebp extends AbstractConverter
78
 
79
  private function executeBinary($binary, $commandOptions, $useNice)
80
  {
 
 
81
  $command = ($useNice ? 'nice ' : '') . $binary . ' ' . $commandOptions;
82
 
83
  //$logger->logLn('command options:' . $commandOptions);
84
- //$logger->logLn('Trying to execute binary:' . $binary);
 
85
  exec($command, $output, $returnCode);
86
  $this->logExecOutput($output);
87
  /*
@@ -135,19 +140,42 @@ class Cwebp extends AbstractConverter
135
  }
136
 
137
  /**
138
- * Build command line options
139
  *
 
 
 
140
  * @return string
141
  */
142
- private function createCommandLineOptions()
143
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
  $options = $this->options;
145
 
146
  $cmdOptions = [];
147
 
148
  // Metadata (all, exif, icc, xmp or none (default))
149
  // Comma-separated list of existing metadata to copy from input to output
150
- $cmdOptions[] = '-metadata ' . $options['metadata'];
 
 
151
 
152
  // preset. Appears first in the list as recommended in the docs
153
  if (!is_null($options['preset'])) {
@@ -179,18 +207,31 @@ class Cwebp extends AbstractConverter
179
 
180
  // Losless PNG conversion
181
  if ($options['encoding'] == 'lossless') {
182
- // No need to add -lossless when near-lossless is used
183
- if ($options['near-lossless'] === 100) {
184
  $cmdOptions[] = '-lossless';
185
  }
186
  }
187
 
188
  // Near-lossles
189
  if ($options['near-lossless'] !== 100) {
190
- // We only let near_lossless have effect when encoding is set to "lossless"
191
- // otherwise encoding=auto would not work as expected
192
- if ($options['encoding'] == 'lossless') {
193
- $cmdOptions[] ='-near_lossless ' . $options['near-lossless'];
 
 
 
 
 
 
 
 
 
 
 
 
 
194
  }
195
  }
196
 
@@ -225,117 +266,27 @@ class Cwebp extends AbstractConverter
225
  $cmdOptions[] = '2>&1';
226
 
227
  $commandOptions = implode(' ', $cmdOptions);
228
- $this->logLn('command line options:' . $commandOptions);
229
 
230
  return $commandOptions;
231
  }
232
 
233
  /**
 
234
  *
235
- *
236
- * @return string Error message if failure, empty string if successful
237
- */
238
- private function composeErrorMessageForCommonSystemPathsFailures($failureCodes)
239
- {
240
- if (count($failureCodes) == 1) {
241
- switch ($failureCodes[0]) {
242
- case 126:
243
- return 'Permission denied. The user that the command was run with (' .
244
- shell_exec('whoami') . ') does not have permission to execute any of the ' .
245
- 'cweb binaries found in common system locations. ';
246
- case 127:
247
- return 'Found no cwebp binaries in any common system locations. ';
248
- default:
249
- return 'Tried executing cwebp binaries in common system locations. ' .
250
- 'All failed (exit code: ' . $failureCodes[0] . '). ';
251
- }
252
- } else {
253
- /**
254
- * $failureCodesBesides127 is used to check first position ($failureCodesBesides127[0])
255
- * however position can vary as index can be 1 or something else. array_values() would
256
- * always start from 0.
257
- */
258
- $failureCodesBesides127 = array_values(array_diff($failureCodes, [127]));
259
-
260
- if (count($failureCodesBesides127) == 1) {
261
- switch ($failureCodesBesides127[0]) {
262
- case 126:
263
- return 'Permission denied. The user that the command was run with (' .
264
- shell_exec('whoami') . ') does not have permission to execute any of the cweb ' .
265
- 'binaries found in common system locations. ';
266
- break;
267
- default:
268
- return 'Tried executing cwebp binaries in common system locations. ' .
269
- 'All failed (exit code: ' . $failureCodesBesides127[0] . '). ';
270
- }
271
- } else {
272
- return 'None of the cwebp binaries in the common system locations could be executed ' .
273
- '(mixed results - got the following exit codes: ' . implode(',', $failureCodes) . '). ';
274
- }
275
- }
276
- }
277
-
278
- /**
279
- * Try executing cwebp in common system paths
280
- *
281
- * @param boolean $useNice Whether to use nice
282
- * @param string $commandOptions for the exec call
283
- *
284
- * @return array Unique failure codes in case of failure, empty array in case of success
285
- */
286
- private function tryCommonSystemPaths($useNice, $commandOptions)
287
- {
288
- $failureCodes = [];
289
-
290
- $paths = self::$cwebpDefaultPaths;
291
-
292
- if (!empty(getenv('CWEBP_PATH'))) {
293
- array_unshift($paths, getenv('CWEBP_PATH'));
294
- }
295
-
296
- // Loop through paths
297
- foreach ($paths as $index => $binary) {
298
- $returnCode = $this->executeBinary($binary, $commandOptions, $useNice);
299
- if ($returnCode == 0) {
300
- $this->logLn('Successfully executed binary: ' . $binary);
301
- return [];
302
- } else {
303
- if ($returnCode == 127) {
304
- $this->logLn(
305
- 'Trying to execute binary: ' . $binary . '. Failed (not found)'
306
- );
307
- } else {
308
- $this->logLn(
309
- 'Trying to execute binary: ' . $binary . '. Failed (return code: ' . $returnCode . ')'
310
- );
311
- }
312
- if (!in_array($returnCode, $failureCodes)) {
313
- $failureCodes[] = $returnCode;
314
- }
315
- }
316
- }
317
- return $failureCodes;
318
- }
319
-
320
- /**
321
- * Try executing supplied cwebp for PHP_OS.
322
- *
323
- * @param boolean $useNice Whether to use nice
324
- * @param string $commandOptions for the exec call
325
- * @param array $failureCodesForCommonSystemPaths Return codes from the other attempt
326
- * (in order to produce short error message)
327
- *
328
- * @return string Error message if failure, empty string if successful
329
  */
330
- private function trySuppliedBinaryForOS($useNice, $commandOptions, $failureCodesForCommonSystemPaths)
331
  {
332
- $this->logLn('Trying to execute supplied binary for OS: ' . PHP_OS);
333
 
334
  // Try supplied binary (if available for OS, and hash is correct)
335
  $options = $this->options;
336
  if (!isset(self::$suppliedBinariesInfo[PHP_OS])) {
337
- return 'No supplied binaries found for OS:' . PHP_OS;
 
338
  }
 
339
 
340
  $info = self::$suppliedBinariesInfo[PHP_OS];
341
 
@@ -344,14 +295,13 @@ class Cwebp extends AbstractConverter
344
 
345
  $binaryFile = __DIR__ . '/' . $options['rel-path-to-precompiled-binaries'] . '/' . $file;
346
 
347
-
348
  // The file should exist, but may have been removed manually.
349
  if (!file_exists($binaryFile)) {
350
- return 'Supplied binary not found! It ought to be here:' . $binaryFile;
 
351
  }
352
 
353
  // File exists, now generate its hash
354
-
355
  // hash_file() is normally available, but it is not always
356
  // - https://stackoverflow.com/questions/17382712/php-5-3-20-undefined-function-hash
357
  // If available, validate that hash is correct.
@@ -360,92 +310,204 @@ class Cwebp extends AbstractConverter
360
  $binaryHash = hash_file('sha256', $binaryFile);
361
 
362
  if ($binaryHash != $hash) {
363
- return 'Binary checksum of supplied binary is invalid! ' .
 
364
  'Did you transfer with FTP, but not in binary mode? ' .
365
  'File:' . $binaryFile . '. ' .
366
  'Expected checksum: ' . $hash . '. ' .
367
- 'Actual checksum:' . $binaryHash . '.';
 
 
368
  }
369
  }
 
 
370
 
371
- $returnCode = $this->executeBinary($binaryFile, $commandOptions, $useNice);
372
- if ($returnCode == 0) {
373
- // yay!
374
- $this->logLn('success!');
375
- return '';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
376
  }
377
 
378
- $errorMsg = 'Tried executing supplied binary for ' . PHP_OS . ', ' .
379
- ($options['try-common-system-paths'] ? 'but that failed too' : 'but failed');
 
 
 
 
380
 
 
 
 
 
 
 
 
 
 
 
381
 
382
- if (($options['try-common-system-paths']) && (count($failureCodesForCommonSystemPaths) > 0)) {
383
- // check if it was the same error
384
- // if it was, simply refer to that with "(same problem)"
385
- $majorFailCode = 0;
386
- if (count($failureCodesForCommonSystemPaths) == 1) {
387
- $majorFailCode = $failureCodesForCommonSystemPaths[0];
 
 
 
 
 
388
  } else {
389
- $failureCodesBesides127 = array_values(array_diff($failureCodesForCommonSystemPaths, [127]));
390
- if (count($failureCodesBesides127) == 1) {
391
- $majorFailCode = $failureCodesBesides127[0];
392
- } else {
393
- // it cannot be summarized into a single code
 
 
 
 
394
  }
395
  }
396
- if ($majorFailCode != 0) {
397
- $errorMsg .= ' (same problem)';
398
- return $errorMsg;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
399
  }
400
  }
 
 
 
 
 
 
 
 
 
 
 
401
 
402
- if ($returnCode > 128) {
403
- $errorMsg .= '. The binary did not work (exit code: ' . $returnCode . '). ' .
404
- 'Check out https://github.com/rosell-dk/webp-convert/issues/92';
 
405
  } else {
406
- switch ($returnCode) {
407
- case 0:
408
- // success!
409
- break;
410
- case 126:
411
- $errorMsg .= ': Permission denied. The user that the command was run' .
412
- ' with (' . shell_exec('whoami') . ') does not have permission to ' .
413
- 'execute that binary.';
414
- break;
415
- case 127:
416
- $errorMsg .= '. The binary was not found! ' .
417
- 'It ought to be here: ' . $binaryFile;
418
- break;
419
- default:
420
- $errorMsg .= ' (exit code:' . $returnCode . ').';
421
- }
422
  }
423
- return $errorMsg;
424
  }
425
 
426
  protected function doActualConvert()
427
  {
428
- $errorMsg = '';
429
- $options = $this->options;
430
- $useNice = (($options['use-nice']) && self::hasNiceSupport());
431
 
432
- $commandOptions = $this->createCommandLineOptions();
 
 
 
 
433
 
434
- // Try all common paths that exists
435
- $success = false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
436
 
437
- $failureCodes = [];
438
 
439
- if ($options['try-common-system-paths']) {
440
- $failureCodes = $this->tryCommonSystemPaths($useNice, $commandOptions);
441
- $success = (count($failureCodes) == 0);
442
- $errorMsg = $this->composeErrorMessageForCommonSystemPathsFailures($failureCodes);
443
  }
 
 
 
 
 
 
444
 
445
- if (!$success && $options['try-supplied-binary-for-os']) {
446
- $errorMsg2 = $this->trySuppliedBinaryForOS($useNice, $commandOptions, $failureCodes);
447
- $errorMsg .= $errorMsg2;
448
- $success = ($errorMsg2 == '');
 
 
 
 
449
  }
450
 
451
  // cwebp sets file permissions to 664 but instead ..
@@ -460,10 +522,8 @@ class Cwebp extends AbstractConverter
460
  $permissions = $fileStatistics['mode'] & 0000666;
461
  chmod($this->destination, $permissions);
462
  }
463
- }
464
-
465
- if (!$success) {
466
- throw new SystemRequirementsNotMetException($errorMsg);
467
  }
468
  }
469
  }
54
  // OS-specific binaries included in this library, along with hashes
55
  // If other binaries are going to be added, notice that the first argument is what PHP_OS returns.
56
  // (possible values, see here: https://stackoverflow.com/questions/738823/possible-values-for-php-os)
57
+ // Got the precompiled binaries here: https://developers.google.com/speed/webp/docs/precompiled
58
  private static $suppliedBinariesInfo = [
59
  'WINNT' => [ 'cwebp.exe', '49e9cb98db30bfa27936933e6fd94d407e0386802cb192800d9fd824f6476873'],
60
  'Darwin' => [ 'cwebp-mac12', 'a06a3ee436e375c89dbc1b0b2e8bd7729a55139ae072ed3f7bd2e07de0ebb379'],
61
  'SunOS' => [ 'cwebp-sol', '1febaffbb18e52dc2c524cda9eefd00c6db95bc388732868999c0f48deb73b4f'],
62
  'FreeBSD' => [ 'cwebp-fbsd', 'e5cbea11c97fadffe221fdf57c093c19af2737e4bbd2cb3cd5e908de64286573'],
63
+ 'Linux' => [ 'cwebp-linux2', 'd6142e9da2f1cab541de10a31527c597225fff5644e66e31d62bb391c41bfbf4'] // 1.0.2
64
+
65
  ];
66
 
67
  public function checkOperationality()
80
 
81
  private function executeBinary($binary, $commandOptions, $useNice)
82
  {
83
+ //$version = $this->detectVersion($binary);
84
+
85
  $command = ($useNice ? 'nice ' : '') . $binary . ' ' . $commandOptions;
86
 
87
  //$logger->logLn('command options:' . $commandOptions);
88
+ $this->logLn('Trying to convert by executing the following command:');
89
+ $this->logLn($command);
90
  exec($command, $output, $returnCode);
91
  $this->logExecOutput($output);
92
  /*
140
  }
141
 
142
  /**
143
+ * Build command line options for a given version of cwebp.
144
  *
145
+ * The "-near_lossless" param is not supported on older versions of cwebp, so skip on those.
146
+ *
147
+ * @param string $version Version of cwebp.
148
  * @return string
149
  */
150
+ private function createCommandLineOptions($version)
151
  {
152
+
153
+ $this->logLn('Creating command line options for version: ' . $version);
154
+
155
+ // we only need two decimal places for version.
156
+ // convert to number to make it easier to compare
157
+ $version = preg_match('#^\d+\.\d+#', $version, $matches);
158
+ $versionNum = 0;
159
+ if (isset($matches[0])) {
160
+ $versionNum = floatval($matches[0]);
161
+ } else {
162
+ $this->logLn(
163
+ 'Could not extract version number from the following version string: ' . $version,
164
+ 'bold'
165
+ );
166
+ }
167
+
168
+ //$this->logLn('version:' . strval($versionNum));
169
+
170
  $options = $this->options;
171
 
172
  $cmdOptions = [];
173
 
174
  // Metadata (all, exif, icc, xmp or none (default))
175
  // Comma-separated list of existing metadata to copy from input to output
176
+ if ($versionNum >= 0.3) {
177
+ $cmdOptions[] = '-metadata ' . $options['metadata'];
178
+ }
179
 
180
  // preset. Appears first in the list as recommended in the docs
181
  if (!is_null($options['preset'])) {
207
 
208
  // Losless PNG conversion
209
  if ($options['encoding'] == 'lossless') {
210
+ // No need to add -lossless when near-lossless is used (on version >= 0.5)
211
+ if (($options['near-lossless'] === 100) || ($versionNum < 0.5)) {
212
  $cmdOptions[] = '-lossless';
213
  }
214
  }
215
 
216
  // Near-lossles
217
  if ($options['near-lossless'] !== 100) {
218
+ if ($versionNum < 0.5) {
219
+ $this->logLn(
220
+ 'The near-lossless option is not supported on this (rather old) version of cwebp' .
221
+ '- skipping it.',
222
+ 'italic'
223
+ );
224
+ } else {
225
+ // We only let near_lossless have effect when encoding is set to "lossless"
226
+ // otherwise encoding=auto would not work as expected
227
+
228
+ if ($options['encoding'] == 'lossless') {
229
+ $cmdOptions[] ='-near_lossless ' . $options['near-lossless'];
230
+ } else {
231
+ $this->logLn(
232
+ 'The near-lossless option ignored for lossy'
233
+ );
234
+ }
235
  }
236
  }
237
 
266
  $cmdOptions[] = '2>&1';
267
 
268
  $commandOptions = implode(' ', $cmdOptions);
269
+ //$this->logLn('command line options:' . $commandOptions);
270
 
271
  return $commandOptions;
272
  }
273
 
274
  /**
275
+ * Get path for supplied binary for current OS - and validate hash.
276
  *
277
+ * @return string|false False if something is wrong, otherwise the path.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
278
  */
279
+ private function getSuppliedBinaryPathForOS()
280
  {
281
+ $this->log('Checking if we have a supplied binary for OS: ' . PHP_OS . '... ');
282
 
283
  // Try supplied binary (if available for OS, and hash is correct)
284
  $options = $this->options;
285
  if (!isset(self::$suppliedBinariesInfo[PHP_OS])) {
286
+ $this->logLn('No we dont - not for that OS');
287
+ return false;
288
  }
289
+ $this->logLn('We do.');
290
 
291
  $info = self::$suppliedBinariesInfo[PHP_OS];
292
 
295
 
296
  $binaryFile = __DIR__ . '/' . $options['rel-path-to-precompiled-binaries'] . '/' . $file;
297
 
 
298
  // The file should exist, but may have been removed manually.
299
  if (!file_exists($binaryFile)) {
300
+ $this->logLn('Supplied binary not found! It ought to be here:' . $binaryFile, 'italic');
301
+ return false;
302
  }
303
 
304
  // File exists, now generate its hash
 
305
  // hash_file() is normally available, but it is not always
306
  // - https://stackoverflow.com/questions/17382712/php-5-3-20-undefined-function-hash
307
  // If available, validate that hash is correct.
310
  $binaryHash = hash_file('sha256', $binaryFile);
311
 
312
  if ($binaryHash != $hash) {
313
+ $this->logLn(
314
+ 'Binary checksum of supplied binary is invalid! ' .
315
  'Did you transfer with FTP, but not in binary mode? ' .
316
  'File:' . $binaryFile . '. ' .
317
  'Expected checksum: ' . $hash . '. ' .
318
+ 'Actual checksum:' . $binaryHash . '.',
319
+ 'bold'
320
+ );
321
  }
322
  }
323
+ return $binaryFile;
324
+ }
325
 
326
+ private function discoverBinaries()
327
+ {
328
+ $this->logLn('Locating cwebp binaries');
329
+
330
+ if (defined('WEBPCONVERT_CWEBP_PATH')) {
331
+ $this->logLn('WEBPCONVERT_CWEBP_PATH was defined, so using that path and ignoring any other');
332
+ //$this->logLn('Value: "' . getenv('WEBPCONVERT_CWEBP_PATH') . '"');
333
+ return [constant('WEBPCONVERT_CWEBP_PATH')];
334
+ }
335
+ if (!empty(getenv('WEBPCONVERT_CWEBP_PATH'))) {
336
+ $this->logLn(
337
+ 'WEBPCONVERT_CWEBP_PATH environment variable was set, so using that path and ignoring any other'
338
+ );
339
+ //$this->logLn('Value: "' . getenv('WEBPCONVERT_CWEBP_PATH') . '"');
340
+ return [getenv('WEBPCONVERT_CWEBP_PATH')];
341
+ }
342
+
343
+ $binaries = [];
344
+ if ($this->options['try-common-system-paths']) {
345
+ foreach (self::$cwebpDefaultPaths as $binary) {
346
+ if (@file_exists($binary)) {
347
+ $binaries[] = $binary;
348
+ }
349
+ }
350
+ if (count($binaries) == 0) {
351
+ $this->logLn('No cwebp binaries where located in common system locations');
352
+ } else {
353
+ $this->logLn(strval(count($binaries)) . ' cwebp binaries found in common system locations');
354
+ }
355
+ }
356
+ // TODO: exec('whereis cwebp');
357
+ if ($this->options['try-supplied-binary-for-os']) {
358
+ $suppliedBinary = $this->getSuppliedBinaryPathForOS();
359
+ if ($suppliedBinary !== false) {
360
+ $binaries[] = $suppliedBinary;
361
+ }
362
+ } else {
363
+ $this->logLn('Configured not to try the cwebp binary that comes bundled with webp-convert');
364
  }
365
 
366
+ if (count($binaries) == 0) {
367
+ $this->logLn('No cwebp binaries to try!');
368
+ }
369
+ $this->logLn('A total of ' . strval(count($binaries)) . ' cwebp binaries where found');
370
+ return $binaries;
371
+ }
372
 
373
+ /**
374
+ *
375
+ * @return string|int Version string (ie "1.0.2") OR return code, in case of failure
376
+ */
377
+ private function detectVersion($binary)
378
+ {
379
+ //$this->logLn('Examining binary: ' . $binary);
380
+ $command = $binary . ' -version';
381
+ $this->log('Executing: ' . $command);
382
+ exec($command, $output, $returnCode);
383
 
384
+ if ($returnCode == 0) {
385
+ //$this->logLn('Success');
386
+ if (isset($output[0])) {
387
+ $this->logLn('. Result: version: ' . $output[0]);
388
+ return $output[0];
389
+ }
390
+ } else {
391
+ $this->logExecOutput($output);
392
+ $this->logLn('');
393
+ if ($returnCode == 127) {
394
+ $this->logLn('Exec failed (the cwebp binary was not found at path: ' . $binary. ')');
395
  } else {
396
+ $this->logLn(
397
+ 'Exec failed (return code: ' . $returnCode . ')'
398
+ );
399
+ if ($returnCode == 126) {
400
+ $this->logLn(
401
+ 'PS: Return code 126 means "Permission denied". The user that the command was run with does ' .
402
+ 'not have permission to execute that binary.'
403
+ );
404
+ // TODO: further info: shell_exec('whoami')
405
  }
406
  }
407
+ return $returnCode;
408
+ }
409
+ }
410
+
411
+ /**
412
+ * Check versions for binaries, and return array (indexed by the binary, value being the version of the binary).
413
+ *
414
+ * @return array
415
+ */
416
+ private function detectVersions($binaries)
417
+ {
418
+ $binariesWithVersions = [];
419
+ $binariesWithFailCodes = [];
420
+
421
+ $this->logLn(
422
+ 'Detecting versions of the cwebp binaries found (and verifying that they can be executed in the process)'
423
+ );
424
+ foreach ($binaries as $binary) {
425
+ $versionStringOrFailCode = $this->detectVersion($binary);
426
+ // $this->logLn($binary . ': ' . $versionString);
427
+ if (gettype($versionStringOrFailCode) == 'string') {
428
+ $binariesWithVersions[$binary] = $versionStringOrFailCode;
429
+ } else {
430
+ $binariesWithFailCodes[$binary] = $versionStringOrFailCode;
431
  }
432
  }
433
+ return ['detected' => $binariesWithVersions, 'failed' => $binariesWithFailCodes];
434
+ }
435
+
436
+ /**
437
+ * @return boolean success or not.
438
+ */
439
+ private function tryBinary($binary, $version, $useNice)
440
+ {
441
+
442
+ //$this->logLn('Trying binary: ' . $binary);
443
+ $commandOptions = $this->createCommandLineOptions($version);
444
 
445
+ $returnCode = $this->executeBinary($binary, $commandOptions, $useNice);
446
+ if ($returnCode == 0) {
447
+ $this->logLn('Success');
448
+ return true;
449
  } else {
450
+ $this->logLn(
451
+ 'Exec failed (return code: ' . $returnCode . ')'
452
+ );
453
+ return false;
 
 
 
 
 
 
 
 
 
 
 
 
454
  }
 
455
  }
456
 
457
  protected function doActualConvert()
458
  {
459
+ $binaries = $this->discoverBinaries();
 
 
460
 
461
+ if (count($binaries) == 0) {
462
+ throw new SystemRequirementsNotMetException(
463
+ 'No cwebp binaries located. Check the conversion log for details.'
464
+ );
465
+ }
466
 
467
+ $versions = $this->detectVersions($binaries);
468
+ if (count($versions['detected']) == 0) {
469
+ //$this->logLn('None of the cwebp files located can be executed.');
470
+ if (count($binaries) == 1) {
471
+ $errorMsg = 'The cwebp file found cannot be can be executed.';
472
+ } else {
473
+ $errorMsg = 'None of the cwebp files located can be executed.';
474
+ }
475
+ $uniqueFailCodes = array_unique(array_values($versions['failed']));
476
+ if (count($uniqueFailCodes) == 1) {
477
+ $errorMsg .= ' ' . (count($binaries) == 1 ? 'It' : 'All') .
478
+ ' failed with return code ' . $uniqueFailCodes[0];
479
+ if ($uniqueFailCodes[0] == 126) {
480
+ $errorMsg .= ' (permission denied)';
481
+ }
482
+ } else {
483
+ $errorMsg .= ' Failure codes : ' . implode(', ', $uniqueFailCodes);
484
+ }
485
+
486
+ throw new SystemRequirementsNotMetException($errorMsg);
487
+ }
488
 
489
+ $binaryVersions = $versions['detected'];
490
 
491
+ if (count($binaries) > 1) {
492
+ $this->logLn(
493
+ 'Trying executing the cwebs found until success. Starting with the ones with highest version number.'
494
+ );
495
  }
496
+ //$this->logLn('binary versions: ' . print_r($binaryVersions, true));
497
+
498
+ // Sort binaries so those with highest numbers comes first
499
+ arsort($binaryVersions);
500
+
501
+ //$this->logLn('binary versions (ordered by version): ' . print_r($binaryVersions, true));
502
 
503
+ $useNice = (($this->options['use-nice']) && self::hasNiceSupport());
504
+
505
+ $success = false;
506
+ foreach ($binaryVersions as $binary => $version) {
507
+ if ($this->tryBinary($binary, $version, $useNice)) {
508
+ $success = true;
509
+ break;
510
+ }
511
  }
512
 
513
  // cwebp sets file permissions to 664 but instead ..
522
  $permissions = $fileStatistics['mode'] & 0000666;
523
  chmod($this->destination, $permissions);
524
  }
525
+ } else {
526
+ throw new SystemRequirementsNotMetException('Failed converting. Check the conversion log for details.');
 
 
527
  }
528
  }
529
  }
vendor/rosell-dk/webp-convert/src/Convert/Converters/Ewww.php CHANGED
@@ -53,8 +53,11 @@ class Ewww extends AbstractConverter
53
  if (!empty($this->options['api-key'])) {
54
  return $this->options['api-key'];
55
  }
56
- if (!empty(getenv('EWWW_API_KEY'))) {
57
- return getenv('EWWW_API_KEY');
 
 
 
58
  }
59
  return false;
60
  }
53
  if (!empty($this->options['api-key'])) {
54
  return $this->options['api-key'];
55
  }
56
+ if (defined('WEBPCONVERT_EWWW_API_KEY')) {
57
+ return constant('WEBPCONVERT_EWWW_API_KEY');
58
+ }
59
+ if (!empty(getenv('WEBPCONVERT_EWWW_API_KEY'))) {
60
+ return getenv('WEBPCONVERT_EWWW_API_KEY');
61
  }
62
  return false;
63
  }
vendor/rosell-dk/webp-convert/src/Convert/Converters/GraphicsMagick.php CHANGED
@@ -35,11 +35,13 @@ class GraphicsMagick extends AbstractConverter
35
 
36
  private function getPath()
37
  {
38
- if (empty(getenv('GRAPHICSMAGICK_PATH'))) {
39
- return 'gm';
40
- } else {
41
- return getenv('GRAPHICSMAGICK_PATH');
 
42
  }
 
43
  }
44
 
45
  public function isInstalled()
35
 
36
  private function getPath()
37
  {
38
+ if (defined('WEBPCONVERT_GRAPHICSMAGICK_PATH')) {
39
+ return constant('WEBPCONVERT_GRAPHICSMAGICK_PATH');
40
+ }
41
+ if (!empty(getenv('WEBPCONVERT_GRAPHICSMAGICK_PATH'))) {
42
+ return getenv('WEBPCONVERT_GRAPHICSMAGICK_PATH');
43
  }
44
+ return 'gm';
45
  }
46
 
47
  public function isInstalled()
vendor/rosell-dk/webp-convert/src/Convert/Converters/ImageMagick.php CHANGED
@@ -36,16 +36,13 @@ class ImageMagick extends AbstractConverter
36
 
37
  private function getPath()
38
  {
39
- // Should we use "magick" or "convert" command?
40
- // It seems they do the same. But which is best supported? Which is mostly available (whitelisted)?
41
- // Should we perhaps try both?
42
- // For now, we just go with "convert"
43
-
44
- if (!empty(getenv('IMAGEMAGICK_PATH'))) {
45
- return getenv('IMAGEMAGICK_PATH');
46
- } else {
47
- return 'convert';
48
  }
 
49
  }
50
 
51
  private function getVersion()
36
 
37
  private function getPath()
38
  {
39
+ if (defined('WEBPCONVERT_IMAGEMAGICK_PATH')) {
40
+ return constant('WEBPCONVERT_IMAGEMAGICK_PATH');
41
+ }
42
+ if (!empty(getenv('WEBPCONVERT_IMAGEMAGICK_PATH'))) {
43
+ return getenv('WEBPCONVERT_IMAGEMAGICK_PATH');
 
 
 
 
44
  }
45
+ return 'convert';
46
  }
47
 
48
  private function getVersion()
vendor/rosell-dk/webp-convert/src/Convert/Converters/Stack.php CHANGED
@@ -220,11 +220,11 @@ class Stack extends AbstractConverter
220
  $this->ln();
221
  $this->logLn('Stack failed in ' . round((microtime(true) - $beginTimeStack) * 1000) . ' ms');
222
 
 
223
  if ($anyRuntimeErrors) {
224
  // At least one converter failed
225
  throw new ConversionFailedException(
226
- 'None of the converters in the stack could convert the image. ' .
227
- 'At least one failed, even though its requirements seemed to be met.'
228
  );
229
  } else {
230
  // All converters threw a SystemRequirementsNotMetException
220
  $this->ln();
221
  $this->logLn('Stack failed in ' . round((microtime(true) - $beginTimeStack) * 1000) . ' ms');
222
 
223
+ // Hm, Scrutinizer complains that $anyRuntimeErrors is always false. But that is not true!
224
  if ($anyRuntimeErrors) {
225
  // At least one converter failed
226
  throw new ConversionFailedException(
227
+ 'None of the converters in the stack could convert the image.'
 
228
  );
229
  } else {
230
  // All converters threw a SystemRequirementsNotMetException
vendor/rosell-dk/webp-convert/src/Convert/Converters/Wpc.php CHANGED
@@ -90,8 +90,11 @@ class Wpc extends AbstractConverter
90
  return $this->options['api-key'];
91
  }
92
  }
93
- if (!empty(getenv('WPC_API_KEY'))) {
94
- return getenv('WPC_API_KEY');
 
 
 
95
  }
96
  return '';
97
  }
@@ -106,8 +109,11 @@ class Wpc extends AbstractConverter
106
  if (!empty($this->options['api-url'])) {
107
  return $this->options['api-url'];
108
  }
109
- if (!empty(getenv('WPC_API_URL'))) {
110
- return getenv('WPC_API_URL');
 
 
 
111
  }
112
  return '';
113
  }
90
  return $this->options['api-key'];
91
  }
92
  }
93
+ if (defined('WEBPCONVERT_WPC_API_KEY')) {
94
+ return constant('WEBPCONVERT_WPC_API_KEY');
95
+ }
96
+ if (!empty(getenv('WEBPCONVERT_WPC_API_KEY'))) {
97
+ return getenv('WEBPCONVERT_WPC_API_KEY');
98
  }
99
  return '';
100
  }
109
  if (!empty($this->options['api-url'])) {
110
  return $this->options['api-url'];
111
  }
112
+ if (defined('WEBPCONVERT_WPC_API_URL')) {
113
+ return constant('WEBPCONVERT_WPC_API_URL');
114
+ }
115
+ if (!empty(getenv('WEBPCONVERT_WPC_API_URL'))) {
116
+ return getenv('WEBPCONVERT_WPC_API_URL');
117
  }
118
  return '';
119
  }
vendor/rosell-dk/webp-convert/src/Serve/Report.php CHANGED
@@ -38,10 +38,7 @@ class Report
38
  $options['log-call-arguments'] = true;
39
  WebPConvert::convert($source, $destination, $options, $echoLogger);
40
  } catch (\Exception $e) {
41
- $success = false;
42
-
43
  $msg = $e->getMessage();
44
-
45
  echo '<b>' . $msg . '</b>';
46
 
47
  //echo '<p>Rethrowing exception for your convenience</p>';
38
  $options['log-call-arguments'] = true;
39
  WebPConvert::convert($source, $destination, $options, $echoLogger);
40
  } catch (\Exception $e) {
 
 
41
  $msg = $e->getMessage();
 
42
  echo '<b>' . $msg . '</b>';
43
 
44
  //echo '<p>Rethrowing exception for your convenience</p>';
vendor/rosell-dk/webp-convert/tests/Convert/Converters/EwwwTest.php CHANGED
@@ -81,8 +81,8 @@ class EwwwTest extends TestCase
81
  $invalidKey = 'notvalidno';
82
  $this->assertFalse(Ewww::isWorkingKey($invalidKey));
83
 
84
- if (!empty(getenv('EWWW_API_KEY'))) {
85
- $realWorkingKey = getenv('EWWW_API_KEY');
86
  $this->assertTrue(Ewww::isWorkingKey($realWorkingKey));
87
  }
88
  }
81
  $invalidKey = 'notvalidno';
82
  $this->assertFalse(Ewww::isWorkingKey($invalidKey));
83
 
84
+ if (!empty(getenv('WEBPCONVERT_EWWW_API_KEY'))) {
85
+ $realWorkingKey = getenv('WEBPCONVERT_EWWW_API_KEY');
86
  $this->assertTrue(Ewww::isWorkingKey($realWorkingKey));
87
  }
88
  }
vendor/rosell-dk/webp-convert/tests/Convert/Converters/WPCTest.php CHANGED
@@ -29,11 +29,11 @@ class WpcTest extends TestCase
29
 
30
  /* public function testApi0()
31
  {
32
- if (!empty(getenv('WPC_API_URL_API0'))) {
33
  $source = $this->imageDir . '/test.png';
34
  Wpc::convert($source, $source . '.webp', [
35
  'api-version' => 0,
36
- 'api-url' => getenv('WPC_API_URL_API0')
37
  ]);
38
  }
39
  }
@@ -71,14 +71,14 @@ class WpcTest extends TestCase
71
 
72
  public function testApi0()
73
  {
74
- if (empty(getenv('WPC_API_URL_API0'))) {
75
  return;
76
  }
77
 
78
  $source = $this->imageDir . '/test.png';
79
  $options = [
80
  'api-version' => 0,
81
- 'api-url' => getenv('WPC_API_URL_API0'),
82
  'lossless' => true,
83
  ];
84
 
@@ -89,7 +89,7 @@ class WpcTest extends TestCase
89
 
90
  public function testApi1()
91
  {
92
- if (empty(getenv('WPC_API_URL'))) {
93
  return;
94
  }
95
 
@@ -105,7 +105,7 @@ class WpcTest extends TestCase
105
 
106
  public function testWrongSecretButRightUrl()
107
  {
108
- if (empty(getenv('WPC_API_URL'))) {
109
  return;
110
  }
111
 
@@ -113,7 +113,7 @@ class WpcTest extends TestCase
113
  $options = [
114
  'api-version' => 1,
115
  'crypt-api-key-in-transfer' => true,
116
- 'api-key' => 'wrong!'
117
  ];
118
 
119
  $this->expectException(InvalidApiKeyException::class);
@@ -178,17 +178,17 @@ class WpcTest extends TestCase
178
 
179
  public function testApi0()
180
  {
181
- if (!empty(getenv('WPC_API_URL_API0'))) {
182
  ConverterTestHelper::runAllConvertTests($this, 'Wpc', [
183
  'api-version' => 0,
184
- 'api-url' => getenv('WPC_API_URL_API0')
185
  ]);
186
  }
187
  }
188
 
189
  public function testApi1()
190
  {
191
- if (empty(getenv('WPC_API_URL')) || empty(getenv('WPC_API_KEY'))) {
192
  return;
193
  }
194
 
@@ -216,7 +216,7 @@ class WpcTest extends TestCase
216
  /*
217
  public function testWrongSecretButRightUrl()
218
  {
219
- if (empty(getenv('WPC_API_URL'))) {
220
  return;
221
  }
222
 
@@ -224,7 +224,7 @@ class WpcTest extends TestCase
224
 
225
  Wpc::convert($this->imageDir . '/test.png', $this->imageDir . '/test.webp', [
226
  'api-version' => 0,
227
- 'api-url' => getenv('WPC_API_URL'),
228
  'secret' => 'purposely-wrong-secret!'
229
  ]);
230
  }
29
 
30
  /* public function testApi0()
31
  {
32
+ if (!empty(getenv('WEBPCONVERT_WPC_API_URL_API0'))) {
33
  $source = $this->imageDir . '/test.png';
34
  Wpc::convert($source, $source . '.webp', [
35
  'api-version' => 0,
36
+ 'api-url' => getenv('WEBPCONVERT_WPC_API_URL_API0')
37
  ]);
38
  }
39
  }
71
 
72
  public function testApi0()
73
  {
74
+ if (empty(getenv('WEBPCONVERT_WPC_API_URL_API0'))) {
75
  return;
76
  }
77
 
78
  $source = $this->imageDir . '/test.png';
79
  $options = [
80
  'api-version' => 0,
81
+ 'api-url' => getenv('WEBPCONVERT_WPC_API_URL_API0'),
82
  'lossless' => true,
83
  ];
84
 
89
 
90
  public function testApi1()
91
  {
92
+ if (empty(getenv('WEBPCONVERT_WPC_API_URL'))) {
93
  return;
94
  }
95
 
105
 
106
  public function testWrongSecretButRightUrl()
107
  {
108
+ if (empty(getenv('WEBPCONVERT_WPC_API_URL'))) {
109
  return;
110
  }
111
 
113
  $options = [
114
  'api-version' => 1,
115
  'crypt-api-key-in-transfer' => true,
116
+ 'api-key' => 'wrong!',
117
  ];
118
 
119
  $this->expectException(InvalidApiKeyException::class);
178
 
179
  public function testApi0()
180
  {
181
+ if (!empty(getenv('WEBPCONVERT_WPC_API_URL_API0'))) {
182
  ConverterTestHelper::runAllConvertTests($this, 'Wpc', [
183
  'api-version' => 0,
184
+ 'api-url' => getenv('WEBPCONVERT_WPC_API_URL_API0')
185
  ]);
186
  }
187
  }
188
 
189
  public function testApi1()
190
  {
191
+ if (empty(getenv('WEBPCONVERT_WPC_API_URL')) || empty(getenv('WEBPCONVERT_WPC_API_KEY'))) {
192
  return;
193
  }
194
 
216
  /*
217
  public function testWrongSecretButRightUrl()
218
  {
219
+ if (empty(getenv('WEBPCONVERT_WPC_API_URL'))) {
220
  return;
221
  }
222
 
224
 
225
  Wpc::convert($this->imageDir . '/test.png', $this->imageDir . '/test.webp', [
226
  'api-version' => 0,
227
+ 'api-url' => getenv('WEBPCONVERT_WPC_API_URL'),
228
  'secret' => 'purposely-wrong-secret!'
229
  ]);
230
  }
vendor/rosell-dk/webp-convert/tests/Convert/Exposers/CwebpExposer.php CHANGED
@@ -15,9 +15,9 @@ class CwebpExposer extends AbstractConverterExposer {
15
  parent::__construct($gd);
16
  }
17
 
18
- public function createCommandLineOptions()
19
  {
20
- return $this->callPrivateFunction('createCommandLineOptions');
21
  }
22
 
23
  }
15
  parent::__construct($gd);
16
  }
17
 
18
+ public function createCommandLineOptions($version = '0.6.1')
19
  {
20
+ return $this->callPrivateFunction('createCommandLineOptions', null, $version);
21
  }
22
 
23
  }
web-service/wpc.php CHANGED
@@ -1,6 +1,5 @@
1
  <?php
2
 
3
- //require '../vendor/rosell-dk/webp-convert/build/webp-on-demand-1.inc';
4
  require __DIR__ . '/../vendor/autoload.php';
5
  use \WebPConvertCloudService\WebPConvertCloudService;
6
 
1
  <?php
2
 
 
3
  require __DIR__ . '/../vendor/autoload.php';
4
  use \WebPConvertCloudService\WebPConvertCloudService;
5
 
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.1
7
  * Author: Bjørn Rosell
8
  * Author URI: https://www.bitwise-it.dk
9
  * License: GPL2
@@ -14,6 +14,8 @@
14
  Note: Perhaps create a plugin page on my website?, ie https://www.bitwise-it.dk/software/wordpress/webp-express
15
  */
16
 
 
 
17
  use \WebPExpress\AdminInit;
18
  use \WebPExpress\Option;
19
 
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.2
7
  * Author: Bjørn Rosell
8
  * Author URI: https://www.bitwise-it.dk
9
  * License: GPL2
14
  Note: Perhaps create a plugin page on my website?, ie https://www.bitwise-it.dk/software/wordpress/webp-express
15
  */
16
 
17
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
18
+
19
  use \WebPExpress\AdminInit;
20
  use \WebPExpress\Option;
21