[FLOW3-general] Package TYPO3.Image - How to differ between the different image variants?

Matthias Habegger theis_mh at gmx.ch
Fri Dec 9 11:52:12 CET 2011


Because I only need to reduce my images, the getThumbnail-method solved 
my problem, this one also caches the images by itself, pretty cool I 
think :-)

So I created a ViewHelper
--
<?php
namespace Habex\Library\ViewHelpers;

/*                                                                        *
  * This script belongs to the FLOW3 package "Habex.Library".              *
  *                                                                        *
  * 
    */

/**
  * This view helper creates an image
  */
class ImageViewHelper extends 
\TYPO3\Fluid\Core\ViewHelper\AbstractViewHelper {
	
	/**
	 * @var \TYPO3\FLOW3\Resource\Publishing\ResourcePublisher
	 */
	protected $resourcePublisher;

	/**
	 * Inject the FLOW3 resource publisher.
	 *
	 * @param \TYPO3\FLOW3\Resource\Publishing\ResourcePublisher 
$resourcePublisher
	 * @return void
	 */
	public function 
injectResourcePublisher(\TYPO3\FLOW3\Resource\Publishing\ResourcePublisher 
$resourcePublisher) {
		$this->resourcePublisher = $resourcePublisher;
	}
	
	/**
	 * Render the URI to the resource. The filename is used from child content.
	 *
	 * @return \TYPO3\Media\Domain\Model\Image $image
	 * @param integer $maximumWidth
	 * @param integer $maximumHeight
	 *
	 * @return string The absolute URI to the image-resource
	 */
	public function render(\TYPO3\Media\Domain\Model\Image $image = NULL, 
$maximumWidth = NULL, $maximumHeight = NULL) {
		$uri = NULL;
		if($image !== NULL) {
			$thumbnail = $image->getThumbnail($maximumWidth, $maximumHeight);
			$uri = 
$this->resourcePublisher->getPersistentResourceWebUri($thumbnail->getResource());
			if ($uri === FALSE) {
				$uri = $this->resourcePublisher->getStaticResourcesWebBaseUri() . 
'BrokenResource';
			}
		}
		return $uri;
	}
}
?>
--

Now I can use it in my fluid like that:
--
{namespace hl=Habex\Library\ViewHelpers}
<f:if condition="{image}">
   <img src="{hl:image(image: image, maximumWidth: 60, maximumHeight: 
60)}" class="thumbnail" />
</f:if>
--

Thanks to afoeder in the IRC-Channel.

-
Matthias


Am 09.12.2011 09:26, schrieb Matthias Habegger:
> Hi Christian,
>
> I'm thinking more of a solution, which I can use directly in my fluid
> template.
>
> -
> Matthias
>
> Am 08.12.2011 19:11, schrieb "Christian Müller (Kitsunet)":
>> Hi,
>>
>> as far as I see there is no method right now to find a specific variant.
>> Maybe Bastian can comment too when he is back next week. You could use
>> the hash that is assigned to a variant to recover it from the array. All
>> needed components to generate the hash should be there.
>>
>> For me there are two possible ways to go further with that:
>>
>> 1) provide something like getVariantByProcessingInstruction() in the
>> Image Model
>>
>> 2) Allow tagging of variants and provide methods to get variants by tag
>>
>> Both could be nice to have, so if you want to go either way, would be
>> great if you would share the code. :)
>>
>> Cheers,
>> Christian
>>
>>
>>
>> On 08/12/11 18:25, Matthias Habegger wrote:
>>> Hello there,
>>>
>>> With the Package TYPO3.Image can I create different ImageVariants of a
>>> single image (Very nice :-) ).
>>>
>>> So I created a thumbnail (60px width and 60px height) and a larger image
>>> (600px width and 600px height). Both are saved correctly.
>>>
>>> Now I wonna show the thumbnail.
>>> I could get all variants with the method getImageVariants.
>>>
>>> But how can I differ between the different variants, how can I get the
>>> thumbnail?
>>>
>>> Thanks,
>>> Matthias
>>
>



More information about the FLOW3-general mailing list