fadcd6025b9c44c17a57a4d79e3cf3ffb11b8f8d
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / ViewHelpers / ImageViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\ViewHelpers;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012-2013 Susanne Moog <susanne.moog@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the text file GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 /**
31 * Resizes a given image (if required) and renders the respective img tag
32 * In general just calls the parent image view helper but catches
33 * the "file does not exist" exception thrown by the file abstraction layer
34 *
35 * = Examples =
36 *
37 * <code title="Default">
38 * <f:image src="EXT:myext/Resources/Public/typo3_logo.png" alt="alt text" />
39 * </code>
40 * <output>
41 * <img alt="alt text" src="typo3conf/ext/myext/Resources/Public/typo3_logo.png" width="396" height="375" />
42 * or (in BE mode):
43 * <img alt="alt text" src="../typo3conf/ext/viewhelpertest/Resources/Public/typo3_logo.png" width="396" height="375" />
44 * </output>
45 *
46 * <code title="Inline notation">
47 * {f:image(src: 'EXT:viewhelpertest/Resources/Public/typo3_logo.png', alt: 'alt text', minWidth: 30, maxWidth: 40)}
48 * </code>
49 * <output>
50 * <img alt="alt text" src="../typo3temp/pics/f13d79a526.png" width="40" height="38" />
51 * (depending on your TYPO3s encryption key)
52 * </output>
53 *
54 * <code title="non existing image">
55 * <f:image src="NonExistingImage.png" alt="foo" />
56 * </code>
57 * <output>
58 * Could not get image resource for "NonExistingImage.png".
59 * </output>
60 */
61 class ImageViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\ImageViewHelper {
62
63 /**
64 * Resizes a given image (if required) and renders the respective img tag
65 *
66 * @param string $src
67 * @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.
68 * @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.
69 * @param integer $minWidth minimum width of the image
70 * @param integer $minHeight minimum height of the image
71 * @param integer $maxWidth maximum width of the image
72 * @param integer $maxHeight maximum height of the image
73 * @param string $fallbackImage an optional fallback image if the $src image cannot be loaded
74 * @return string rendered tag.
75 */
76 public function render($src, $width = NULL, $height = NULL, $minWidth = NULL, $minHeight = NULL, $maxWidth = NULL, $maxHeight = NULL, $fallbackImage = '') {
77 $image = '';
78 try {
79 $image = parent::render($src, $width, $height, $minWidth, $minHeight, $maxWidth, $maxHeight);
80 } catch (\Exception $e) {
81 if ($fallbackImage !== '') {
82 $image = static::render($fallbackImage, $width, $height, $minWidth, $minHeight, $maxWidth, $maxHeight);
83 }
84 /** @var \TYPO3\CMS\Core\Log\Logger $logger */
85 $logger = $this->objectManager->get('TYPO3\\CMS\\Core\\Log\\LogManager')->getLogger(__CLASS__);
86 $logger->log(\TYPO3\CMS\Core\Log\LogLevel::WARNING, $e->getMessage());
87 }
88 return $image;
89 }
90
91 }