--- /dev/null
+<?php
+
+namespace wcf\data\user\cover\photo;
+
+/**
+ * Any displayable cover photo type should implement this class.
+ *
+ * @author Alexander Ebert
+ * @copyright 2001-2021 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\Data\User\Cover\Photo
+ * @since 5.4
+ */
+interface IWebpUserCoverPhoto extends IUserCoverPhoto
+{
+ /**
+ * @return null|bool
+ */
+ public function createWebpVariant();
+}
* @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
) . '/' . $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.
*
use wcf\data\user\avatar\UserAvatar;
use wcf\data\user\avatar\UserAvatarEditor;
use wcf\data\user\avatar\UserAvatarList;
+use wcf\data\user\cover\photo\IWebpUserCoverPhoto;
use wcf\data\user\User;
use wcf\data\user\UserEditor;
use wcf\data\user\UserList;
use wcf\data\user\UserProfileAction;
use wcf\system\bbcode\BBCodeHandler;
+use wcf\system\cache\runtime\UserProfileRuntimeCache;
use wcf\system\database\util\PreparedStatementConditionBuilder;
use wcf\system\exception\SystemException;
use wcf\system\html\input\HtmlInputProcessor;
'height' => $height,
]);
}
+
+ // Create WebP variants of existing cover photos.
+ $userProfiles = UserProfileRuntimeCache::getInstance()->getObjects($userIDs);
+ foreach ($userProfiles as $userProfile) {
+ if ($userProfile->coverPhotoHash) {
+ $coverPhoto = $userProfile->getCoverPhoto(true);
+ if ($coverPhoto instanceof IWebpUserCoverPhoto) {
+ $coverPhoto->createWebpVariant();
+ }
+ }
+ }
}
}
}