TYPO3 CMS  TYPO3_6-2
ImageViewHelper.php
Go to the documentation of this file.
1 <?php
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 
20 
64  protected $imageService;
65 
82  public function render($src = NULL, $image = NULL, $width = NULL, $height = NULL, $minWidth = NULL, $minHeight = NULL, $maxWidth = NULL, $maxHeight = NULL, $treatIdAsReference = FALSE) {
83  if (is_null($src) && is_null($image) || !is_null($src) && !is_null($image)) {
84  throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception('You must either specify a string src or a File object.', 1382284105);
85  }
86  try {
87  $image = $this->imageService->getImage($src, $image, $treatIdAsReference);
88  $processingInstructions = array(
89  'width' => $width,
90  'height' => $height,
91  'minWidth' => $minWidth,
92  'minHeight' => $minHeight,
93  'maxWidth' => $maxWidth,
94  'maxHeight' => $maxHeight,
95  );
96  $processedImage = $this->imageService->applyProcessingInstructions($image, $processingInstructions);
97  return $this->imageService->getImageUri($processedImage);
98  } catch (ResourceDoesNotExistException $e) {
99  // thrown if file does not exist
100  } catch (\UnexpectedValueException $e) {
101  // thrown if a file has been replaced with a folder
102  } catch (\RuntimeException $e) {
103  // RuntimeException thrown if a file is outside of a storage
104  } catch (\InvalidArgumentException $e) {
105  // thrown if file storage does not exist
106  }
107  return '';
108  }
109 }
render($src=NULL, $image=NULL, $width=NULL, $height=NULL, $minWidth=NULL, $minHeight=NULL, $maxWidth=NULL, $maxHeight=NULL, $treatIdAsReference=FALSE)