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?
For TYPO3 v13, some issues with Webp (including the above) should now be resolved by:
For versions below TYPO3 v13 you could try
$configuration['fileExtension'] = 'webp'
as Julian Hofmann
suggestedFor 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);
}
}
}
}