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 authored May 3, 2019
1 parent cfbacfa commit f695236
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 @@ -24,9 +24,12 @@ public function getAvatarUrl(Author $author): string
$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;

$avatarUrl = 'https://www.gravatar.com/avatar/' . md5($author->getEmail())
. '?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 @@ -12,15 +12,35 @@

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();
$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 f695236

Please sign in to comment.