| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('WPO_VERSION')) die('No direct access allowed'); |
| 4 |
|
| 5 |
if (!class_exists('WPO_WebP_Test_Run')) : |
| 6 |
/** |
| 7 |
* Test run |
| 8 |
*/ |
| 9 |
class WPO_WebP_Test_Run { |
| 10 |
|
| 11 |
/** |
| 12 |
* Get a test result object OR false, if tests cannot be made. |
| 13 |
* |
| 14 |
* @return object|false |
| 15 |
*/ |
| 16 |
public static function get_converter_status() { |
| 17 |
$source = WPO_PLUGIN_MAIN_PATH . 'images/logo/wpo_logo_small.png'; |
| 18 |
$upload_dir = wp_upload_dir(); |
| 19 |
$destination = $upload_dir['basedir']. '/wpo/images/wpo_logo_small.png.webp'; |
| 20 |
|
| 21 |
$converters = array( |
| 22 |
// 'cwebp', |
| 23 |
'vips', |
| 24 |
'imagemagick', |
| 25 |
'graphicsmagick', |
| 26 |
'ffmpeg', |
| 27 |
'wpc', |
| 28 |
'ewww', |
| 29 |
'imagick', |
| 30 |
'gmagick', |
| 31 |
'gd', |
| 32 |
); |
| 33 |
$working_converters = array(); |
| 34 |
$errors = array(); |
| 35 |
|
| 36 |
foreach ($converters as $converter) { |
| 37 |
$converter_id = $converter; |
| 38 |
try { |
| 39 |
WPO_WebP_Utils::perform_webp_conversion($converter_id, $source, $destination); |
| 40 |
$working_converters[] = $converter_id; |
| 41 |
// Copying source file to `uploads` folder. To be used test redirection |
| 42 |
// We're doing it here, to make sure folders already exists `/wpo/images/` |
| 43 |
copy($source, $upload_dir['basedir'] . '/wpo/images/wpo_logo_small.png'); |
| 44 |
} catch (\Exception $e) { |
| 45 |
$errors[$converter_id] = $e->getMessage(); |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
return array( |
| 50 |
'working_converters' => $working_converters, |
| 51 |
'errors' => $errors, |
| 52 |
); |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
endif; |
| 57 |
|