diff --git a/Classes/AvatarProvider/ImageProvider.php b/Classes/AvatarProvider/ImageProvider.php index 23ce959a..0d4eb15f 100644 --- a/Classes/AvatarProvider/ImageProvider.php +++ b/Classes/AvatarProvider/ImageProvider.php @@ -12,6 +12,7 @@ use T3G\AgencyPack\Blog\AvatarProviderInterface; use T3G\AgencyPack\Blog\Domain\Model\Author; +use TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; use TYPO3\CMS\Extbase\Domain\Model\FileReference; @@ -33,11 +34,19 @@ public function getAvatarUrl(Author $author): string $imageService = $objectManager->get(ImageService::class); $image = $imageService->getImage('', $image, false); + + if ($image->hasProperty('crop') && $image->getProperty('crop')) { + $cropString = $image->getProperty('crop'); + } + $cropVariantCollection = CropVariantCollection::create((string)$cropString); + $cropArea = $cropVariantCollection->getCropArea('default'); + $processingInstructions = [ 'width' => $size . 'c', 'height' => $size, 'minWidth' => $size, 'minHeight' => $size, + 'crop' => $cropArea->isEmpty() ? null : $cropArea->makeAbsoluteBasedOnFile($image), ]; $processedImage = $imageService->applyProcessingInstructions($image, $processingInstructions); return $imageService->getImageUri($processedImage); diff --git a/Configuration/TCA/tx_blog_domain_model_author.php b/Configuration/TCA/tx_blog_domain_model_author.php index 19ef85a6..baa815da 100644 --- a/Configuration/TCA/tx_blog_domain_model_author.php +++ b/Configuration/TCA/tx_blog_domain_model_author.php @@ -130,33 +130,27 @@ 'exclude' => 0, 'label' => $ll . 'tx_blog_domain_model_author.image', 'displayCond' => 'FIELD:avatar_provider:=:T3G\AgencyPack\Blog\AvatarProvider\ImageProvider', - 'overrideChildTca' => [ - 'types' => [ - '0' => [ - 'showitem' => ' - --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette, - --palette--;;filePalette', + 'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig( + 'image', + [ + 'appearance' => [ + 'createNewRelationLinkTitle' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:images.addFileReference' ], - \TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE => [ - 'showitem' => ' - --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette, - --palette--;;filePalette', + 'overrideChildTca' => [ + 'types' => [ + \TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE => [ + 'showitem' => ' + crop, + --palette--;;filePalette + ' + ], + ], ], - ] - ], - 'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig('image', [ - 'appearance' => [ - 'createNewRelationLinkTitle' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:images.addFileReference', - ], - 'maxitems' => 1, - // custom configuration for displaying fields in the overlay/reference table - // to use the imageoverlayPalette instead of the basicoverlayPalette - 'foreign_match_fields' => [ - 'fieldname' => 'image', - 'tablenames' => 'tx_blog_domain_model_author', - 'table_local' => 'sys_file', + 'minitems' => 0, + 'maxitems' => 1, ], - ], $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']), + $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'] + ), ], 'title' => [ 'exclude' => 0,