‪TYPO3CMS  10.4
MagicImageService.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 
22 
27 {
34  protected ‪$magicImageMaximumWidth = 300;
35 
40  protected ‪$magicImageMaximumHeight = 1000;
41 
49  public function ‪createMagicImage(‪File $imageFileObject, array $fileConfiguration)
50  {
51  // Process dimensions
52  $maxWidth = ‪MathUtility::forceIntegerInRange($fileConfiguration['width'], 0, $this->magicImageMaximumWidth);
53  $maxHeight = ‪MathUtility::forceIntegerInRange($fileConfiguration['height'], 0, $this->magicImageMaximumHeight);
54  if (!$maxWidth) {
56  }
57  if (!$maxHeight) {
59  }
60  // Create the magic image
61  $magicImage = $imageFileObject->‪process(
63  [
64  'width' => $maxWidth . 'm',
65  'height' => $maxHeight . 'm'
66  ]
67  );
68  return $magicImage;
69  }
70 
76  public function ‪setMagicImageMaximumDimensions(array $rteConfiguration)
77  {
78  // Get maximum dimensions from the configuration of the RTE image button
79  $imageButtonConfiguration = (is_array($rteConfiguration['buttons.']) && is_array($rteConfiguration['buttons.']['image.'])) ? $rteConfiguration['buttons.']['image.'] : [];
80  if (is_array($imageButtonConfiguration['options.']) && is_array($imageButtonConfiguration['options.']['magic.'])) {
81  if ((int)$imageButtonConfiguration['options.']['magic.']['maxWidth'] > 0) {
82  $this->magicImageMaximumWidth = (int)$imageButtonConfiguration['options.']['magic.']['maxWidth'];
83  }
84  if ((int)$imageButtonConfiguration['options.']['magic.']['maxHeight'] > 0) {
85  $this->magicImageMaximumHeight = (int)$imageButtonConfiguration['options.']['magic.']['maxHeight'];
86  }
87  }
88  }
89 }
‪TYPO3\CMS\Core\Resource\ProcessedFile\CONTEXT_IMAGECROPSCALEMASK
‪const CONTEXT_IMAGECROPSCALEMASK
Definition: ProcessedFile.php:58
‪TYPO3\CMS\Core\Utility\MathUtility\forceIntegerInRange
‪static int forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:32
‪TYPO3\CMS\Core\Resource\Service\MagicImageService\$magicImageMaximumWidth
‪int $magicImageMaximumWidth
Definition: MagicImageService.php:33
‪TYPO3\CMS\Core\Resource\File\process
‪ProcessedFile process($taskType, array $configuration)
Definition: File.php:266
‪TYPO3\CMS\Core\Resource\Service\MagicImageService
Definition: MagicImageService.php:27
‪TYPO3\CMS\Core\Resource\Service
Definition: ExtractorService.php:18
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:24
‪TYPO3\CMS\Core\Resource
Definition: generateMimeTypes.php:52
‪TYPO3\CMS\Core\Resource\ProcessedFile
Definition: ProcessedFile.php:44
‪TYPO3\CMS\Core\Resource\Service\MagicImageService\createMagicImage
‪Resource ProcessedFile createMagicImage(File $imageFileObject, array $fileConfiguration)
Definition: MagicImageService.php:47
‪TYPO3\CMS\Core\Resource\Service\MagicImageService\setMagicImageMaximumDimensions
‪setMagicImageMaximumDimensions(array $rteConfiguration)
Definition: MagicImageService.php:74
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:22
‪TYPO3\CMS\Core\Resource\Service\MagicImageService\$magicImageMaximumHeight
‪int $magicImageMaximumHeight
Definition: MagicImageService.php:38