Skip to content

Commit

Permalink
[BUGFIX] #25: Regenerate missing magic image on rendering images with…
Browse files Browse the repository at this point in the history
…in links (#57)
  • Loading branch information
muh-nr authored Jul 16, 2019
1 parent fd6a165 commit 7ad1bdd
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions Classes/Controller/ImageLinkRenderingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,17 @@ public function renderImages($conf)
if (!empty($passedAttributes['data-htmlarea-file-uid'])) {
try {
$systemImage = Resource\ResourceFactory::getInstance()->getFileObject($passedAttributes['data-htmlarea-file-uid']);
$imageConfiguration = [
'width' => ($passedAttributes['width']) ? $passedAttributes['width'] : $systemImage->getProperty('width'),
'height' => ($passedAttributes['height']) ? $passedAttributes['height'] : $systemImage->getProperty('height')
];
$processedFile = $this->getMagicImageService()->createMagicImage($systemImage, $imageConfiguration);
$imageAttributes = [
'src' => $passedAttributes['src'],
'src' => $processedFile->getPublicUrl(),
'title' => ($passedAttributes['title']) ? $passedAttributes['title'] : $systemImage->getProperty('title'),
'alt' => ($passedAttributes['alt']) ? $passedAttributes['alt'] : $systemImage->getProperty('alternative'),
'width' => ($passedAttributes['width']) ? $passedAttributes['width'] : $systemImage->getProperty('width'),
'height' => ($passedAttributes['height']) ? $passedAttributes['height'] : $systemImage->getProperty('height'),
'style' => ($passedAttributes['style']) ? $passedAttributes['style'] : $systemImage->getProperty('style')
'height' => ($passedAttributes['height']) ? $passedAttributes['height'] : $systemImage->getProperty('height')
];
// Add original attributes, if not already parsed
$imageAttributes = $imageAttributes + $passedAttributes;
Expand Down Expand Up @@ -124,6 +128,26 @@ public function renderImages($conf)
return $linkContent;
}

/**
* Instantiates and prepares the Magic Image service.
*
* @return \TYPO3\CMS\Core\Resource\Service\MagicImageService
*/
protected function getMagicImageService()
{
/** @var $magicImageService Resource\Service\MagicImageService */
static $magicImageService;
if (!$magicImageService) {
$magicImageService = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\Service\MagicImageService::class);
// Get RTE configuration
$pageTSConfig = $this->frontendController->getPagesTSconfig();
if (is_array($pageTSConfig) && is_array($pageTSConfig['RTE.']['default.'])) {
$magicImageService->setMagicImageMaximumDimensions($pageTSConfig['RTE.']['default.']);
}
}
return $magicImageService;
}

/**
* @return \TYPO3\CMS\Core\Log\Logger
*/
Expand Down

0 comments on commit 7ad1bdd

Please sign in to comment.