isBackend() && $task->getType() === 'Image' && in_array($task->getName(), ['Preview', 'CropScaleMask'], true) && (!$context->hasAspect('fileProcessing') || $context->getPropertyFromAspect('fileProcessing', 'deferProcessing')) && $task->getSourceFile()->getProperty('width') > 0 && $task->getSourceFile()->getProperty('height') > 0 // Let the local image processor update the properties in case the target file exists already && !$task->getSourceFile()->getStorage()->getProcessingFolder($task->getSourceFile())->hasFile($task->getTargetFileName()); } public function processTask(TaskInterface $task): void { try { $imageDimension = ImageDimension::fromProcessingTask($task); } catch (ZeroImageDimensionException $e) { // To not fail image processing, we just assume an image dimension here $imageDimension = new ImageDimension(64, 64); } $processedFile = $task->getTargetFile(); if (!$processedFile->isPersisted()) { // For now, we need to persist the processed file in the repository to be able to reference its uid // We could instead introduce a processing queue and persist the information there $processedFileRepository = GeneralUtility::makeInstance(ProcessedFileRepository::class); $processedFileRepository->add($processedFile, $task); } $processedFile->setName($task->getTargetFileName()); $processingUrl = (string)GeneralUtility::makeInstance(UriBuilder::class) ->buildUriFromRoute( 'image_processing', [ 'id' => $processedFile->getUid(), ] ); // We know $GLOBALS['TYPO3_REQUEST'] exists and is BE because of canProcessTask() $processedFile->updateProcessingUrl(GeneralUtility::locationHeaderUrl($processingUrl, $GLOBALS['TYPO3_REQUEST'])); $processedFile->updateProperties( [ 'width' => $imageDimension->getWidth(), 'height' => $imageDimension->getHeight(), 'size' => 0, 'checksum' => $task->getConfigurationChecksum(), ] ); $task->setExecuted(true); } }