TYPO3  7.6
fluid/Classes/ViewHelpers/Uri/ImageViewHelper.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Uri;
3 
4 /* *
5  * This script is part of the TYPO3 project - inspiring people to share! *
6  * *
7  * TYPO3 is free software; you can redistribute it and/or modify it under *
8  * the terms of the GNU General Public License version 2 as published by *
9  * the Free Software Foundation. *
10  * *
11  * This script is distributed in the hope that it will be useful, but *
12  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
13  * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
14  * Public License for more details. *
15  * */
16 
27 
67 {
86  public function render($src = null, $image = null, $width = null, $height = null, $minWidth = null, $minHeight = null, $maxWidth = null, $maxHeight = null, $treatIdAsReference = false, $crop = null, $absolute = false)
87  {
88  return self::renderStatic(
89  array(
90  'src' => $src,
91  'image' => $image,
92  'width' => $width,
93  'height' => $height,
94  'minWidth' => $minWidth,
95  'minHeight' => $minHeight,
96  'maxWidth' => $maxWidth,
97  'maxHeight' => $maxHeight,
98  'treatIdAsReference' => $treatIdAsReference,
99  'crop' => $crop,
100  'absolute' => $absolute,
101  ),
103  $this->renderingContext
104  );
105  }
106 
115  {
116  $src = $arguments['src'];
117  $image = $arguments['image'];
118  $treatIdAsReference = $arguments['treatIdAsReference'];
119  $crop = $arguments['crop'];
120  $absolute = $arguments['absolute'];
121 
122  if (is_null($src) && is_null($image) || !is_null($src) && !is_null($image)) {
123  throw new Exception('You must either specify a string src or a File object.', 1382284105);
124  }
125 
126  $imageService = self::getImageService();
127  $image = $imageService->getImage($src, $image, $treatIdAsReference);
128 
129  if ($crop === null) {
130  $crop = $image instanceof FileReference ? $image->getProperty('crop') : null;
131  }
132 
133  $processingInstructions = array(
134  'width' => $arguments['width'],
135  'height' => $arguments['height'],
136  'minWidth' => $arguments['minWidth'],
137  'minHeight' => $arguments['minHeight'],
138  'maxWidth' => $arguments['maxWidth'],
139  'maxHeight' => $arguments['maxHeight'],
140  'crop' => $crop,
141  );
142  $processedImage = $imageService->applyProcessingInstructions($image, $processingInstructions);
143  return $imageService->getImageUri($processedImage, $absolute);
144  }
145 
151  protected static function getImageService()
152  {
154  $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
155  return $objectManager->get(ImageService::class);
156  }
157 }