Created
March 4, 2020 15:03
-
-
Save wazum/1201a47b0301cafa662ddfcdaf1b27a6 to your computer and use it in GitHub Desktop.
Create an image with a specific cropping variant in a TYPO3 user function or similar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$contentObjectRenderer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class); | |
$filesContent = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\ContentObject\FilesContentObject::class, | |
$contentObjectRenderer); | |
$filesConfiguration = [ | |
'references' => '50', // this is a UID from sys_file_reference | |
'renderObj' => 'IMAGE', | |
'renderObj.' => [ | |
'file' => '50', // this is the same UID as above | |
'file.' => [ | |
'treatIdAsReference' => true, | |
'width' => '265c', | |
'height' => '143c', | |
'crop.' => [ | |
'data' => 'file:current:crop' | |
], | |
'cropVariant' => 'xs' // the name of the crop variant | |
] | |
] | |
]; | |
$imageTag = $filesContent->render($filesConfiguration); | |
echo $imageTag; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works fine up to TYPO3 v11.
Breaks with v12. The problem is that I don't have a valid content object in my request, since I'm running the process as a user func.
If this is in extbase context where you initialize the process through a plugin, it probably also works fine in v12.
In my case, this solution works in v12 without initializing a frontend request: