‪TYPO3CMS  ‪main
ImagePreviewTask.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  protected string|null ‪$targetFileExtension;
29 
30  public function ‪getType(): string
31  {
32  return 'Image';
33  }
34 
35  public function ‪getName(): string
36  {
37  return 'Preview';
38  }
39 
44  public function ‪getTargetFilename(): string
45  {
46  return 'preview_'
47  . $this->‪getSourceFile()->getNameWithoutExtension()
48  . '_' . $this->‪getConfigurationChecksum()
49  . '.' . $this->‪getTargetFileExtension();
50  }
51 
56  public function ‪getTargetFileExtension(): string
57  {
58  if (!isset($this->targetFileExtension)) {
59  $this->targetFileExtension = $this->‪determineTargetFileExtension();
60  }
62  }
63 
69  protected function ‪determineTargetFileExtension(): string
70  {
71  if (!empty($this->configuration['fileExtension'])) {
72  ‪$targetFileExtension = $this->configuration['fileExtension'];
73  } elseif (in_array($this->‪getSourceFile()->getExtension(), ['jpg', 'jpeg', 'png', 'gif'], true)) {
74  ‪$targetFileExtension = $this->‪getSourceFile()->getExtension();
75  } elseif ($this->‪getSourceFile()->getExtension() === 'webp' && ‪GeneralUtility::inList(‪$GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'] ?? '', 'webp')) {
76  ‪$targetFileExtension = $this->‪getSourceFile()->getExtension();
77  } elseif (empty($this->configuration['crop']) && $this->‪getSourceFile()->getExtension() === 'svg') {
79  } else {
80  // Thumbnails from non-processable files will be converted to 'png'
82  }
84  }
85 
91  public function ‪sanitizeConfiguration(): void
92  {
93  $configuration = array_replace(
94  [
95  'width' => 64,
96  'height' => 64,
97  ],
98  $this->configuration
99  );
100  $configuration['width'] = ‪MathUtility::forceIntegerInRange($configuration['width'], 1, 1000);
101  $configuration['height'] = ‪MathUtility::forceIntegerInRange($configuration['height'], 1, 1000);
102 
103  $this->configuration = array_filter(
104  $configuration,
105  static function (string|int|bool|array|null $value, string $name): bool {
106  return !empty($value) && in_array($name, ['width', 'height'], true);
107  },
108  ARRAY_FILTER_USE_BOTH
109  );
110  parent::sanitizeConfiguration();
111  }
112 }
‪TYPO3\CMS\Core\Resource\Processing\AbstractTask\getConfigurationChecksum
‪getConfigurationChecksum()
Definition: AbstractTask.php:58
‪TYPO3\CMS\Core\Resource\Processing\AbstractTask\getSourceFile
‪getSourceFile()
Definition: AbstractTask.php:97
‪TYPO3\CMS\Core\Resource\Processing\ImagePreviewTask\getTargetFilename
‪getTargetFilename()
Definition: ImagePreviewTask.php:44
‪TYPO3\CMS\Core\Resource\Processing
Definition: AbstractTask.php:18
‪TYPO3\CMS\Core\Resource\Processing\ImagePreviewTask
Definition: ImagePreviewTask.php:27
‪TYPO3\CMS\Core\Resource\Processing\ImagePreviewTask\$targetFileExtension
‪string null $targetFileExtension
Definition: ImagePreviewTask.php:28
‪TYPO3\CMS\Core\Resource\Processing\ImagePreviewTask\getName
‪getName()
Definition: ImagePreviewTask.php:35
‪TYPO3\CMS\Core\Resource\Processing\ImagePreviewTask\sanitizeConfiguration
‪sanitizeConfiguration()
Definition: ImagePreviewTask.php:91
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Resource\Processing\AbstractTask
Definition: AbstractTask.php:29
‪TYPO3\CMS\Core\Resource\Processing\ImagePreviewTask\getTargetFileExtension
‪getTargetFileExtension()
Definition: ImagePreviewTask.php:56
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:24
‪TYPO3\CMS\Core\Utility\GeneralUtility\inList
‪static bool inList($list, $item)
Definition: GeneralUtility.php:422
‪TYPO3\CMS\Core\Resource\Processing\ImagePreviewTask\getType
‪getType()
Definition: ImagePreviewTask.php:30
‪TYPO3\CMS\Core\Utility\MathUtility\forceIntegerInRange
‪static int forceIntegerInRange(mixed $theInt, int $min, int $max=2000000000, int $defaultValue=0)
Definition: MathUtility.php:34
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Resource\Processing\ImagePreviewTask\determineTargetFileExtension
‪determineTargetFileExtension()
Definition: ImagePreviewTask.php:69