Generate WebP variants of users' cover photos
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / data / user / cover / photo / UserCoverPhoto.class.php
index eafa4967d4fa4a972792945c138333a71704095d..ddb00a1ac97f6d9b992704c40aaa49dbcb88b651 100644 (file)
@@ -13,7 +13,7 @@ use wcf\util\ImageUtil;
  * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @package WoltLabSuite\Core\Data\User\Cover\Photo
  */
-class UserCoverPhoto implements IUserCoverPhoto
+class UserCoverPhoto implements IWebpUserCoverPhoto
 {
     /**
      * file extension
@@ -105,6 +105,21 @@ class UserCoverPhoto implements IUserCoverPhoto
         ) . '/' . $this->userID . '-' . $this->coverPhotoHash . '.' . ($useWebP ? 'webp' : $this->coverPhotoExtension);
     }
 
+    /**
+     * @inheritDoc
+     */
+    public function createWebpVariant()
+    {
+        if ($this->coverPhotoHasWebP) {
+            return;
+        }
+
+        $sourceLocation = WCF_DIR . $this->getFilename($this->coverPhotoExtension === 'webp');
+        $outputFilenameWithoutExtension = \preg_replace('~\.[a-z]+$~', '', $sourceLocation);
+
+        return ImageUtil::createWebpVariant($sourceLocation, $outputFilenameWithoutExtension);
+    }
+
     /**
      * Returns the minimum and maximum dimensions for cover photos.
      *