4

I'm using a webp image in a default image content element.

webp images are enabled:

$GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'] .= ',webp';

But in frontend, a png is rendered, instead of a webp, when it's processed by TYPO3/ImageMagick/GraphicsMagick.

When explicitly saying webp should be generated, it works as expected:

<f:image image="{file}" fileExtension="webp" />

How to configure TYPO3 or ImageMagick/GraphicsMagick to not convert webp to png automatically?

6
  • Have you found any additional information by now? Is there a bug report for this or configuration which needs to be changed? Commented Jan 17 at 13:44
  • BeforeFileProcessingEvent could be used for setting $configuration['fileExtension'] = 'webp';. Should solve this use-case. Commented Jan 17 at 15:05
  • @Julian Thanks, that looked really promising. However it is was not possible for me to modify the configuration via the BeforeFileProcessingEvent. I could add it to the $configuration array, but there is only getConfiguration(), not setConfiguration(), otherwise I am pretty sure, it would work. Can you confirm? Am I missing something? Commented Jan 18 at 12:41
  • BTW, for anyone else, it looks like this is resolved in TYPO3 v13 but was not backported, see forge.typo3.org/issues/88537 and patch: review.typo3.org/c/Packages/TYPO3.CMS/+/82196 Commented Jan 18 at 12:42
  • I have a working solution now, I posted an answer. Commented Jan 18 at 14:03

2 Answers 2

1

For TYPO3 v13, some issues with Webp (including the above) should now be resolved by:


For versions below TYPO3 v13 you could try

  1. the approach with an event listener for BeforeFileProcessingEvent and set $configuration['fileExtension'] = 'webp' as Julian Hofmann suggested
  2. OR try to backport the patch. You can make the change in AbstractGraphicalTask instead of ImageCropScaleMaskTask and ImagePreviewTask.php
  3. OR do not support .webp files natively (e.g. don't allow to upload them) in older TYPO3 versions and use an additional extension such as EXT:webp to automatically generate .webp

For the EventListener, this should work (but might need some more tweaking):

class BeforeFileProcessingEventListener
{
    public function __invoke(BeforeFileProcessingEvent $event): void
    {
        if ($event->getFile()->getExtension() === 'webp') {
            $processedFile = $event->getProcessedFile();
            // if file was already processed, we do nothing here!
            if (!$processedFile->isProcessed()) {
                $configuration = $processedFile->getProcessingConfiguration();
                $configuration['fileExtension'] = 'webp';
                // there is no setProcessingConfiguration in ProcessedFile so we create a new ProcessedFile
                $processedFileRepository = GeneralUtility::makeInstance(ProcessedFileRepository::class);
                $newProcessedFile = $processedFileRepository->createNewProcessedFileObject($event->getFile(), $event->getTaskType(), $configuration);
                $event->setProcessedFile($newProcessedFile);
            }  
        }
    }
}
1

Might be a bit late but I found the following workaround when I want TYPO3 to respect the extension. Of course this is not suitable if your input file is not a proper image for the web, therefore use with care:

<f:image image="{file}" fileExtension="{file.properties.extension}" />

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.