[TASK] Re-work/simplify copyright header in PHP files - Part 9
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / ViewHelpers / ImageViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\ViewHelpers;
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
17 /**
18 * Resizes a given image (if required) and renders the respective img tag
19 * In general just calls the parent image view helper but catches
20 * the "file does not exist" exception thrown by the file abstraction layer
21 *
22 * = Examples =
23 *
24 * <code title="Default">
25 * <f:image src="EXT:myext/Resources/Public/typo3_logo.png" alt="alt text" />
26 * </code>
27 * <output>
28 * <img alt="alt text" src="typo3conf/ext/myext/Resources/Public/typo3_logo.png" width="396" height="375" />
29 * or (in BE mode):
30 * <img alt="alt text" src="../typo3conf/ext/viewhelpertest/Resources/Public/typo3_logo.png" width="396" height="375" />
31 * </output>
32 *
33 * <code title="Inline notation">
34 * {f:image(src: 'EXT:viewhelpertest/Resources/Public/typo3_logo.png', alt: 'alt text', minWidth: 30, maxWidth: 40)}
35 * </code>
36 * <output>
37 * <img alt="alt text" src="../typo3temp/pics/f13d79a526.png" width="40" height="38" />
38 * (depending on your TYPO3s encryption key)
39 * </output>
40 *
41 * <code title="non existing image">
42 * <f:image src="NonExistingImage.png" alt="foo" />
43 * </code>
44 * <output>
45 * Could not get image resource for "NonExistingImage.png".
46 * </output>
47 */
48 class ImageViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\ImageViewHelper {
49
50 /**
51 * Resizes a given image (if required) and renders the respective img tag
52 *
53 * @param string $src
54 * @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.
55 * @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.
56 * @param integer $minWidth minimum width of the image
57 * @param integer $minHeight minimum height of the image
58 * @param integer $maxWidth maximum width of the image
59 * @param integer $maxHeight maximum height of the image
60 * @param string $fallbackImage an optional fallback image if the $src image cannot be loaded
61 * @return string rendered tag.
62 */
63 public function render($src, $width = NULL, $height = NULL, $minWidth = NULL, $minHeight = NULL, $maxWidth = NULL, $maxHeight = NULL, $fallbackImage = '') {
64 $image = '';
65 try {
66 $image = parent::render($src, $width, $height, $minWidth, $minHeight, $maxWidth, $maxHeight);
67 } catch (\Exception $e) {
68 if ($fallbackImage !== '') {
69 $image = static::render($fallbackImage, $width, $height, $minWidth, $minHeight, $maxWidth, $maxHeight);
70 }
71 /** @var \TYPO3\CMS\Core\Log\Logger $logger */
72 $logger = $this->objectManager->get('TYPO3\\CMS\\Core\\Log\\LogManager')->getLogger(__CLASS__);
73 $logger->log(\TYPO3\CMS\Core\Log\LogLevel::WARNING, $e->getMessage());
74 }
75 return $image;
76 }
77
78 }