Skip to content

Commit

Permalink
[BUGFIX] Respect configured size in Avatar ImageProvider (#74)
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 3, 2019
1 parent 694e7ad commit 89bf706
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
9 changes: 6 additions & 3 deletions Classes/AvatarProvider/GravatarProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 21 additions & 1 deletion Classes/AvatarProvider/ImageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 '';
}
Expand Down

0 comments on commit 89bf706

Please sign in to comment.