‪TYPO3CMS  ‪main
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 
21 use TYPO3\CMS\Core\Imaging\ImageDimension;
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 
41  public function ‪processTask(‪TaskInterface $task): void
42  {
43  $task->‪setExecuted(true);
44  $task->‪getTargetFile()->setUsesOriginalFile();
45  try {
46  $imageDimension = ImageDimension::fromProcessingTask($task);
47  } catch (‪ZeroImageDimensionException $e) {
48  // To not fail image processing, we just assume an SVG image dimension here
49  $imageDimension = new ImageDimension(64, 64);
50  }
51  $task->‪getTargetFile()->updateProperties(
52  [
53  'width' => $imageDimension->getWidth(),
54  'height' => $imageDimension->getHeight(),
55  'size' => $task->‪getSourceFile()->getSize(),
56  'checksum' => $task->‪getConfigurationChecksum(),
57  ]
58  );
59  }
60 }
‪TYPO3\CMS\Core\Resource\Processing\TaskInterface\getType
‪getType()
‪TYPO3\CMS\Core\Resource\Processing\TaskInterface\getTargetFileExtension
‪getTargetFileExtension()
‪TYPO3\CMS\Core\Imaging\Exception\ZeroImageDimensionException
Definition: ZeroImageDimensionException.php:26
‪TYPO3\CMS\Core\Resource\Processing\TaskInterface
Definition: TaskInterface.php:34
‪TYPO3\CMS\Core\Resource\Processing\TaskInterface\getConfiguration
‪getConfiguration()
‪TYPO3\CMS\Core\Resource\Processing\SvgImageProcessor
Definition: SvgImageProcessor.php:27
‪TYPO3\CMS\Core\Resource\Processing\SvgImageProcessor\canProcessTask
‪canProcessTask(TaskInterface $task)
Definition: SvgImageProcessor.php:28
‪TYPO3\CMS\Core\Resource\Processing
Definition: AbstractTask.php:18
‪TYPO3\CMS\Core\Resource\Processing\TaskInterface\getTargetFile
‪getTargetFile()
‪TYPO3\CMS\Core\Resource\Processing\SvgImageProcessor\processTask
‪processTask(TaskInterface $task)
Definition: SvgImageProcessor.php:41
‪TYPO3\CMS\Core\Resource\Processing\TaskInterface\getConfigurationChecksum
‪getConfigurationChecksum()
‪TYPO3\CMS\Core\Resource\Processing\TaskInterface\setExecuted
‪setExecuted(bool $successful)
‪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()