Skip to content

Instantly share code, notes, and snippets.

@bwaidelich
Created October 26, 2011 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bwaidelich/1316189 to your computer and use it in GitHub Desktop.
Save bwaidelich/1316189 to your computer and use it in GitHub Desktop.
ImageViewHelper
<?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();
}
}
?>
@bwaidelich
Copy link
Author

untested!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment