Skip to content

Commit

Permalink
[BUGFIX] Respect configured size in Avatar ImageProvider
Browse files Browse the repository at this point in the history
Fixes: #73
Releases: master, 9.1, 9.0, 8.7
  • Loading branch information
benjaminkott committed May 2, 2019
1 parent 5b9c567 commit 41bf4ba
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion Classes/AvatarProvider/ImageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,34 @@

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;

class ImageProvider implements AvatarProviderInterface
{
public function getAvatarUrl(Author $author): string
{
$image = $author->getImage();
if ($image instanceof FileReference) {
return $image->getOriginalResource()->getPublicUrl();
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);

$configurationManager = $objectManager->get(ConfigurationManagerInterface::class);
$settings = $configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS, 'blog');
$size = $settings['authors']['avatar']['provider']['size'] ?: 32;

$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 '';
}
Expand Down

0 comments on commit 41bf4ba

Please sign in to comment.