‪TYPO3CMS  11.5
SvgImageProcessor.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
22 
27 {
28  public function ‪canProcessTask(‪TaskInterface $task): bool
29  {
30  return $task->‪getType() === 'Image'
31  && in_array($task->‪getName(), ['Preview', 'CropScaleMask'], true)
32  && empty($task->‪getConfiguration()['crop'])
33  && $task->‪getTargetFileExtension() === 'svg';
34  }
35 
42  public function ‪processTask(‪TaskInterface $task): void
43  {
44  $task->‪setExecuted(true);
46  try {
47  $imageDimension = ‪ImageDimension::fromProcessingTask($task);
48  } catch (‪ZeroImageDimensionException $e) {
49  // To not fail image processing, we just assume an SVG image dimension here
50  $imageDimension = new ‪ImageDimension(64, 64);
51  }
53  [
54  'width' => $imageDimension->getWidth(),
55  'height' => $imageDimension->getHeight(),
56  'size' => $task->‪getSourceFile()->‪getSize(),
57  'checksum' => $task->‪getConfigurationChecksum(),
58  ]
59  );
60  }
61 }
‪TYPO3\CMS\Core\Resource\Processing\TaskInterface\getType
‪string getType()
‪TYPO3\CMS\Core\Imaging\Exception\ZeroImageDimensionException
Definition: ZeroImageDimensionException.php:26
‪TYPO3\CMS\Core\Resource\Processing\TaskInterface
Definition: TaskInterface.php:33
‪TYPO3\CMS\Core\Resource\Processing\SvgImageProcessor
Definition: SvgImageProcessor.php:27
‪TYPO3\CMS\Core\Resource\Processing\TaskInterface\getSourceFile
‪Resource File getSourceFile()
‪TYPO3\CMS\Core\Resource\Processing\SvgImageProcessor\canProcessTask
‪canProcessTask(TaskInterface $task)
Definition: SvgImageProcessor.php:28
‪TYPO3\CMS\Core\Resource\ProcessedFile\setUsesOriginalFile
‪setUsesOriginalFile()
Definition: ProcessedFile.php:421
‪TYPO3\CMS\Core\Resource\Processing
Definition: AbstractGraphicalTask.php:16
‪TYPO3\CMS\Core\Imaging\ImageDimension\fromProcessingTask
‪static fromProcessingTask(TaskInterface $task)
Definition: ImageDimension.php:57
‪TYPO3\CMS\Core\Resource\Processing\SvgImageProcessor\processTask
‪processTask(TaskInterface $task)
Definition: SvgImageProcessor.php:42
‪TYPO3\CMS\Core\Resource\Processing\TaskInterface\getTargetFile
‪Resource ProcessedFile getTargetFile()
‪TYPO3\CMS\Core\Resource\Processing\TaskInterface\getName
‪string getName()
‪TYPO3\CMS\Core\Resource\Processing\TaskInterface\getConfiguration
‪array getConfiguration()
‪TYPO3\CMS\Core\Resource\AbstractFile\getSize
‪int null getSize()
Definition: AbstractFile.php:184
‪TYPO3\CMS\Core\Resource\ProcessedFile\updateProperties
‪updateProperties(array $properties)
Definition: ProcessedFile.php:347
‪TYPO3\CMS\Core\Resource\Processing\ProcessorInterface
Definition: ProcessorInterface.php:22
‪TYPO3\CMS\Core\Resource\Processing\TaskInterface\setExecuted
‪setExecuted($successful)
‪TYPO3\CMS\Core\Resource\Processing\TaskInterface\getConfigurationChecksum
‪string getConfigurationChecksum()
‪TYPO3\CMS\Core\Resource\Processing\TaskInterface\getTargetFileExtension
‪string getTargetFileExtension()
‪TYPO3\CMS\Core\Imaging\ImageDimension
Definition: ImageDimension.php:32