TYPO3 CMS  TYPO3_6-2
ImageViewHelper.php
Go to the documentation of this file.
1 <?php
3 
19 
42 
46  protected $tagName = 'img';
47 
53  public function initializeArguments() {
54  parent::initializeArguments();
56  $this->registerTagAttribute('alt', 'string', 'Specifies an alternate text for an image', FALSE);
57  }
58 
68  public function render($src, $width = NULL, $height = NULL, $fallbackImage = '') {
69  $content = '';
70  $uri = $this->getImageUri($src);
71 
72  if (empty($uri) && $fallbackImage !== '') {
73  $uri = $this->getImageUri($fallbackImage);
74  }
75 
76  if (!empty($uri)) {
77  if ($width) {
78  $this->tag->addAttribute('width', (int)$width);
79  }
80  if ($height) {
81  $this->tag->addAttribute('height', (int)$height);
82  }
83  $this->tag->addAttribute('src', $uri);
84  $content = $this->tag->render();
85  }
86 
87  return $content;
88  }
89 
96  protected function getImageUri($src) {
98  if ($uri !== '' && !file_exists($uri)) {
99  $uri = '';
100  }
101  if ($uri !== '') {
102  $uri = '../' . PathUtility::stripPathSitePrefix($uri);
103  }
104  return $uri;
105  }
106 }
registerTagAttribute($name, $type, $description, $required=FALSE, $default=NULL)
static getFileAbsFileName($filename, $onlyRelative=TRUE, $relToTYPO3_mainDir=FALSE)
render($src, $width=NULL, $height=NULL, $fallbackImage='')