Helper method to check for WebP support
authorAlexander Ebert <ebert@woltlab.com>
Tue, 15 Jun 2021 13:47:53 +0000 (15:47 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 15 Jun 2021 13:47:53 +0000 (15:47 +0200)
wcfsetup/install/files/lib/system/image/adapter/GDImageAdapter.class.php
wcfsetup/install/files/lib/system/image/adapter/IWebpImageAdapter.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/image/adapter/ImagickImageAdapter.class.php

index 2bea38d6a020f0184cb90e74c55d7efc4fadc513..674cf649bbe9dbd3b4a692374f7021890bca18f0 100644 (file)
@@ -13,7 +13,7 @@ use wcf\util\StringUtil;
  * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @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 (file)
index 0000000..5fbcc72
--- /dev/null
@@ -0,0 +1,21 @@
+<?php
+
+namespace wcf\system\image\adapter;
+
+/**
+ * A WebP capable image adapter exposes a helper method to verify the
+ * support for the creation and processing of WebP images.
+ *
+ * @author Alexander Ebert
+ * @copyright 2001-2021 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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;
+}
index afedf3d3c9373b41053773b7be3115f9f66487a8..bd62d899e8d6551e11521014df8242ee7f451a7a 100644 (file)
@@ -14,7 +14,7 @@ use wcf\util\StringUtil;
  * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @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());
+    }
 }