diff --git a/Classes/AvatarProvider/GravatarProvider.php b/Classes/AvatarProvider/GravatarProvider.php index 1248d290..90d7d7f6 100644 --- a/Classes/AvatarProvider/GravatarProvider.php +++ b/Classes/AvatarProvider/GravatarProvider.php @@ -46,9 +46,12 @@ public function getAvatarUrl(Author $author) $configurationManager = $objectManager->get(ConfigurationManagerInterface::class); $settings = $configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS, 'blog'); - $size = $settings['authors']['avatar']['provider']['size'] ?: 32; - $default = $settings['authors']['avatar']['provider']['default'] ?: 'mm'; - $rating = $settings['authors']['avatar']['provider']['rating'] ?: 'g'; + $defaultSize = 32; + $defaultDefault = 'mm'; + $defaultRating = 'g'; + $size = ($settings['authors']['avatar']['provider']['size'] ?? $defaultSize) ?: $defaultSize; + $default = ($settings['authors']['avatar']['provider']['default'] ?? $defaultDefault) ?: $defaultDefault; + $rating = ($settings['authors']['avatar']['provider']['rating'] ?? $defaultRating) ?: $defaultRating; $gravatarUrl = 'https://www.gravatar.com/avatar/' . md5($author->getEmail()); $gravatarUrl .= '?s=' . $size; diff --git a/Classes/AvatarProvider/ImageProvider.php b/Classes/AvatarProvider/ImageProvider.php index ac5737c8..1b499977 100644 --- a/Classes/AvatarProvider/ImageProvider.php +++ b/Classes/AvatarProvider/ImageProvider.php @@ -11,7 +11,11 @@ use T3G\AgencyPack\Blog\AvatarProviderInterface; use T3G\AgencyPack\Blog\Domain\Model\Author; +use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; use TYPO3\CMS\Extbase\Domain\Model\FileReference; +use TYPO3\CMS\Extbase\Object\ObjectManager; +use TYPO3\CMS\Extbase\Service\ImageService; /* * This file is part of the TYPO3 CMS project. @@ -42,7 +46,23 @@ public function getAvatarUrl(Author $author) { $image = $author->getImage(); if ($image instanceof FileReference) { - return $author->getImage()->getOriginalResource()->getPublicUrl(); + $defaultSize = 32; + $objectManager = GeneralUtility::makeInstance(ObjectManager::class); + + $configurationManager = $objectManager->get(ConfigurationManagerInterface::class); + $settings = $configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS, 'blog'); + $size = ($settings['authors']['avatar']['provider']['size'] ?? $defaultSize) ?: $defaultSize; + + $imageService = $objectManager->get(ImageService::class); + $image = $imageService->getImage('', $image, false); + $processingInstructions = [ + 'width' => $size . 'c', + 'height' => $size, + 'minWidth' => $size, + 'minHeight' => $size, + ]; + $processedImage = $imageService->applyProcessingInstructions($image, $processingInstructions); + return $imageService->getImageUri($processedImage); } return ''; }