TYPO3 CMS  TYPO3_7-6
MagicImageService.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
19 
24 {
31  protected $magicImageMaximumWidth = 300;
32 
37  protected $magicImageMaximumHeight = 1000;
38 
46  public function createMagicImage(Resource\File $imageFileObject, array $fileConfiguration)
47  {
48  // Process dimensions
49  $maxWidth = MathUtility::forceIntegerInRange($fileConfiguration['width'], 0, $this->magicImageMaximumWidth);
50  $maxHeight = MathUtility::forceIntegerInRange($fileConfiguration['height'], 0, $this->magicImageMaximumHeight);
51  if (!$maxWidth) {
53  }
54  if (!$maxHeight) {
55  $maxHeight = $this->magicImageMaximumHeight;
56  }
57  // Create the magic image
58  $magicImage = $imageFileObject->process(
60  [
61  'width' => $maxWidth . 'm',
62  'height' => $maxHeight . 'm'
63  ]
64  );
65  return $magicImage;
66  }
67 
74  public function setMagicImageMaximumDimensions(array $rteConfiguration)
75  {
76  // Get maximum dimensions from the configuration of the RTE image button
77  $imageButtonConfiguration = (is_array($rteConfiguration['buttons.']) && is_array($rteConfiguration['buttons.']['image.'])) ? $rteConfiguration['buttons.']['image.'] : [];
78  if (is_array($imageButtonConfiguration['options.']) && is_array($imageButtonConfiguration['options.']['magic.'])) {
79  if ((int)$imageButtonConfiguration['options.']['magic.']['maxWidth'] > 0) {
80  $this->magicImageMaximumWidth = (int)$imageButtonConfiguration['options.']['magic.']['maxWidth'];
81  }
82  if ((int)$imageButtonConfiguration['options.']['magic.']['maxHeight'] > 0) {
83  $this->magicImageMaximumHeight = (int)$imageButtonConfiguration['options.']['magic.']['maxHeight'];
84  }
85  }
86  }
87 }
static forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:31
createMagicImage(Resource\File $imageFileObject, array $fileConfiguration)