From cecb02dee775af36b6491e696356dfa8b66697e7 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Tue, 15 Jun 2021 15:47:53 +0200 Subject: [PATCH] Helper method to check for WebP support --- .../image/adapter/GDImageAdapter.class.php | 10 ++++++++- .../image/adapter/IWebpImageAdapter.class.php | 21 +++++++++++++++++++ .../adapter/ImagickImageAdapter.class.php | 10 ++++++++- 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 wcfsetup/install/files/lib/system/image/adapter/IWebpImageAdapter.class.php diff --git a/wcfsetup/install/files/lib/system/image/adapter/GDImageAdapter.class.php b/wcfsetup/install/files/lib/system/image/adapter/GDImageAdapter.class.php index 2bea38d6a0..674cf649bb 100644 --- a/wcfsetup/install/files/lib/system/image/adapter/GDImageAdapter.class.php +++ b/wcfsetup/install/files/lib/system/image/adapter/GDImageAdapter.class.php @@ -13,7 +13,7 @@ use wcf\util\StringUtil; * @license GNU Lesser General Public License * @package WoltLabSuite\Core\System\Image\Adapter */ -class GDImageAdapter implements IImageAdapter +class GDImageAdapter implements IImageAdapter, IWebpImageAdapter { /** * active color @@ -613,4 +613,12 @@ class GDImageAdapter implements IImageAdapter { return \function_exists('gd_info'); } + + /** + * @inheritDoc + */ + public static function supportsWebp(): bool + { + return !empty(\gd_info()['WebP Support']); + } } diff --git a/wcfsetup/install/files/lib/system/image/adapter/IWebpImageAdapter.class.php b/wcfsetup/install/files/lib/system/image/adapter/IWebpImageAdapter.class.php new file mode 100644 index 0000000000..5fbcc7236f --- /dev/null +++ b/wcfsetup/install/files/lib/system/image/adapter/IWebpImageAdapter.class.php @@ -0,0 +1,21 @@ + + * @package WoltLabSuite\Core\System\Image\Adapter + * @since 5.4 + */ +interface IWebpImageAdapter extends IImageAdapter +{ + /** + * Reports the ability to create and process WebP images. + */ + public static function supportsWebp(): bool; +} diff --git a/wcfsetup/install/files/lib/system/image/adapter/ImagickImageAdapter.class.php b/wcfsetup/install/files/lib/system/image/adapter/ImagickImageAdapter.class.php index afedf3d3c9..bd62d899e8 100644 --- a/wcfsetup/install/files/lib/system/image/adapter/ImagickImageAdapter.class.php +++ b/wcfsetup/install/files/lib/system/image/adapter/ImagickImageAdapter.class.php @@ -14,7 +14,7 @@ use wcf\util\StringUtil; * @license GNU Lesser General Public License * @package WoltLabSuite\Core\System\Image\Adapter */ -class ImagickImageAdapter implements IImageAdapter +class ImagickImageAdapter implements IImageAdapter, IWebpImageAdapter { /** * active color @@ -527,4 +527,12 @@ class ImagickImageAdapter implements IImageAdapter { return \version_compare($version, '6.3.6') >= 0; } + + /** + * @inheritDoc + */ + public static function supportsWebp(): bool + { + return \in_array('WEBP', \Imagick::queryFormats()); + } } -- 2.20.1