‪TYPO3CMS  ‪main
PreviewProcessing.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use Psr\EventDispatcher\EventDispatcherInterface;
25 
30 {
31  public function ‪__construct(
32  protected readonly ‪OnlineMediaHelperRegistry $onlineMediaHelperRegistry,
33  protected readonly EventDispatcherInterface $eventDispatcher,
34  protected readonly ‪LocalImageProcessor $localImageProcessor,
35  ) {}
36 
37  public function ‪canProcessTask(‪TaskInterface $task): bool
38  {
39  if ($task->‪getType() !== 'Image') {
40  return false;
41  }
42  if (!in_array($task->‪getName(), ['Preview', 'CropScaleMask'], true)) {
43  return false;
44  }
45  $sourceFile = $task->‪getSourceFile();
46  if (!$this->onlineMediaHelperRegistry->hasOnlineMediaHelper($sourceFile->getExtension())) {
47  return false;
48  }
49  $previewImageFile = $this->‪getPreviewImageFromOnlineMedia($sourceFile);
50  return !empty($previewImageFile) && file_exists($previewImageFile);
51  }
52 
53  public function ‪processTask(‪TaskInterface $task): void
54  {
55  $this->localImageProcessor->processTaskWithLocalFile(
56  $task,
58  );
59  }
60 
61  protected function ‪getPreviewImageFromOnlineMedia(‪File $file): string
62  {
63  $onlineMediaHelper = $this->onlineMediaHelperRegistry->getOnlineMediaHelper($file);
64  $previewImage = $onlineMediaHelper->getPreviewImage($file);
65 
66  $videoPreviewEvent = new ‪AfterVideoPreviewFetchedEvent($file, $onlineMediaHelper, $previewImage);
67  $this->eventDispatcher->dispatch($videoPreviewEvent);
68 
69  return $videoPreviewEvent->getPreviewImageFilename();
70  }
71 }
‪TYPO3\CMS\Core\Resource\OnlineMedia\Processing
Definition: PreviewProcessing.php:16
‪TYPO3\CMS\Core\Resource\OnlineMedia\Processing\PreviewProcessing
Definition: PreviewProcessing.php:30
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\OnlineMediaHelperRegistry
Definition: OnlineMediaHelperRegistry.php:27
‪TYPO3\CMS\Core\Resource\Processing\TaskInterface\getType
‪getType()
‪TYPO3\CMS\Core\Resource\OnlineMedia\Processing\PreviewProcessing\__construct
‪__construct(protected readonly OnlineMediaHelperRegistry $onlineMediaHelperRegistry, protected readonly EventDispatcherInterface $eventDispatcher, protected readonly LocalImageProcessor $localImageProcessor,)
Definition: PreviewProcessing.php:31
‪TYPO3\CMS\Core\Resource\Processing\TaskInterface
Definition: TaskInterface.php:34
‪TYPO3\CMS\Core\Resource\OnlineMedia\Event\AfterVideoPreviewFetchedEvent
Definition: AfterVideoPreviewFetchedEvent.php:27
‪TYPO3\CMS\Core\Resource\OnlineMedia\Processing\PreviewProcessing\getPreviewImageFromOnlineMedia
‪getPreviewImageFromOnlineMedia(File $file)
Definition: PreviewProcessing.php:61
‪TYPO3\CMS\Core\Resource\Processing\LocalImageProcessor
Definition: LocalImageProcessor.php:27
‪TYPO3\CMS\Core\Resource\OnlineMedia\Processing\PreviewProcessing\canProcessTask
‪canProcessTask(TaskInterface $task)
Definition: PreviewProcessing.php:37
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:26
‪TYPO3\CMS\Core\Resource\OnlineMedia\Processing\PreviewProcessing\processTask
‪processTask(TaskInterface $task)
Definition: PreviewProcessing.php:53
‪TYPO3\CMS\Core\Resource\Processing\ProcessorInterface
Definition: ProcessorInterface.php:22
‪TYPO3\CMS\Core\Resource\Processing\TaskInterface\getSourceFile
‪getSourceFile()
‪TYPO3\CMS\Core\Resource\Processing\TaskInterface\getName
‪getName()