[BUGFIX] Added missing use statement in Uri/ImageViewHelper
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Uri / ImageViewHelper.php
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
17 use TYPO3\CMS\Core\Resource\FileInterface;
18 use TYPO3\CMS\Core\Resource\FileReference;
19 use TYPO3\CMS\Extbase\Domain\Model\AbstractFileFolder;
20
21 /**
22 * Resizes a given image (if required) and returns its relative path.
23 *
24 * = Examples =
25 *
26 * <code title="Default">
27 * <f:uri.image src="EXT:myext/Resources/Public/typo3_logo.png" />
28 * </code>
29 * <output>
30 * typo3conf/ext/myext/Resources/Public/typo3_logo.png
31 * or (in BE mode):
32 * ../typo3conf/ext/myext/Resources/Public/typo3_logo.png
33 * </output>
34 *
35 * <code title="Image Object">
36 * <f:uri.image image="{imageObject}" />
37 * </code>
38 * <output>
39 * fileadmin/images/image.png
40 * or (in BE mode):
41 * fileadmin/images/image.png
42 * </output>
43 *
44 * <code title="Inline notation">
45 * {f:uri.image(src: 'EXT:myext/Resources/Public/typo3_logo.png', minWidth: 30, maxWidth: 40)}
46 * </code>
47 * <output>
48 * typo3temp/pics/[b4c0e7ed5c].png
49 * (depending on your TYPO3s encryption key)
50 * </output>
51 *
52 * <code title="non existing image">
53 * <f:uri.image src="NonExistingImage.png" />
54 * </code>
55 * <output>
56 * Could not get image resource for "NonExistingImage.png".
57 * </output>
58 */
59 class ImageViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
60 /**
61 * @var \TYPO3\CMS\Extbase\Service\ImageService
62 * @inject
63 */
64 protected $imageService;
65
66 /**
67 * Resizes the image (if required) and returns its path. If the image was not resized, the path will be equal to $src
68 *
69 * @see http://typo3.org/documentation/document-library/references/doc_core_tsref/4.2.0/view/1/5/#id4164427
70 * @param string $src
71 * @param FileInterface|AbstractFileFolder $image
72 * @param string $width width of the image. This can be a numeric value representing the fixed width of the image in pixels. But you can also perform simple calculations by adding "m" or "c" to the value. See imgResource.width for possible options.
73 * @param string $height height of the image. This can be a numeric value representing the fixed height of the image in pixels. But you can also perform simple calculations by adding "m" or "c" to the value. See imgResource.width for possible options.
74 * @param int $minWidth minimum width of the image
75 * @param int $minHeight minimum height of the image
76 * @param int $maxWidth maximum width of the image
77 * @param int $maxHeight maximum height of the image
78 * @param bool $treatIdAsReference given src argument is a sys_file_reference record
79 * @param string|bool $crop overrule cropping of image (setting to FALSE disables the cropping set in FileReference)
80 * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception
81 * @return string path to the image
82 */
83 public function render($src = NULL, $image = NULL, $width = NULL, $height = NULL, $minWidth = NULL, $minHeight = NULL, $maxWidth = NULL, $maxHeight = NULL, $treatIdAsReference = FALSE, $crop = NULL) {
84 if (is_null($src) && is_null($image) || !is_null($src) && !is_null($image)) {
85 throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception('You must either specify a string src or a File object.', 1382284105);
86 }
87 if ($crop === NULL) {
88 $crop = $image instanceof FileReference ? $image->getProperty('crop') : NULL;
89 }
90 $image = $this->imageService->getImage($src, $image, $treatIdAsReference);
91 $processingInstructions = array(
92 'width' => $width,
93 'height' => $height,
94 'minWidth' => $minWidth,
95 'minHeight' => $minHeight,
96 'maxWidth' => $maxWidth,
97 'maxHeight' => $maxHeight,
98 'crop' => $crop,
99 );
100 $processedImage = $this->imageService->applyProcessingInstructions($image, $processingInstructions);
101 return $this->imageService->getImageUri($processedImage);
102 }
103
104 }