Created
October 26, 2011 12:21
-
-
Save bwaidelich/1316189 to your computer and use it in GitHub Desktop.
ImageViewHelper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Your\Package\ViewHelpers; | |
use TYPO3\FLOW3\Annotations as FLOW3; | |
class ImageViewHelper extends \TYPO3\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper { | |
/** | |
* @FLOW3\Inject | |
* @var \TYPO3\FLOW3\Resource\Publishing\ResourcePublisher | |
*/ | |
protected $resourcePublisher; | |
/** | |
* @var string | |
*/ | |
protected $tagName = 'img'; | |
/** | |
* Render the link. | |
* | |
* @param \TYPO3\Media\Domain\Model\Image $image | |
* @param integer $maximumWidth | |
* @param integer $maximumHeight | |
* @return string The rendered image tag | |
*/ | |
public function render(\TYPO3\Media\Domain\Model\Image $image, $maximumWidth = NULL, $maximumHeight = NULL) { | |
$thumbnailImage = $image->getThumbnail($maximumWidth, $maximumHeight); | |
$thumbnailUri = $this->resourcePublisher->getPersistentResourceWebUri($thumbnailImage->getResource()); | |
$this->tag->addAttribute('src', $thumbnailUri); | |
$this->tag->addAttribute('width', $thumbnailImage->getWidth()); | |
$this->tag->addAttribute('height', $thumbnailImage->getHeight()); | |
return $this->tag->render(); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
untested!