[TYPO3-english] Resizing the images dynamically by TypoScript
Xavier Perseguers
xavier.perseguers at typo3.org
Thu Oct 1 09:04:57 CEST 2015
On 30/09/15 14:24, Rozita Pourashraf wrote:
> Hi everybody,
> I want to resize the images dynamically by TypoScript in Typo3.
> For that I get the width and height from WURFL extension. My code is:
>
> 10 = IMAGE
> 10.file = USER_INT
> 10.file.userFunc {
> width = user_get_screen_width
> height = user_get_screen_height
> import = /fileadmin/templates/images/content/
> import.field = image }
>
> But nothing happens. Do you have any idea?
Your TS is fully wrong! If you read what is the type of "file" (line 2):
https://docs.typo3.org/typo3cms/TyposcriptReference/ContentObjects/Image/Index.html
it's an "imgResource", so to use a userFunc, you should write
10.file.cObject = USER_INT
then, when you have a USER_INT, you need to define the userFunc, but not
the way you did, but by respecting what it expects:
https://docs.typo3.org/typo3cms/TyposcriptReference/ContentObjects/UserAndUserInt/Index.html
so as a first step, the method in your code that should be called,
something like
10.file.cObject = USER_INT
10.file.cObject {
userFunc = YourVendorName\SomeExtension\SomeClass->yourMethod
// any other "variable" you want to get in your method
}
Now, I don't really see the point of trying to create a method that
populates fields of an IMAGE content object, so I would suggest to use
your USER_INT in the first place:
10 = USER_INT
10.userFunc = Pourashraf\DynamicImages\Resizer->processImage
10.foo = 124
file typo3conf/ext/dynamic_images/Classes/Resizer.php:
<?php
namespace Pourashraf\DynamicImages;
class Resizer extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin
{
public function processImage($content, array $conf)
{
// Retrieve config from TS:
$fooValue = $conf['foo'];
// Create a dynamic image
$imageConfiguration = array(
'file' => 'fileadmin/whatever.jpg', // old way of
referencing an image but you get the point
// Any other TypoScript option you want (resize, ...)
);
$html = $this->cObj->cObjGetSingle('IMAGE', $imageConfiguration);
return $html;
}
}
HTH
--
Xavier Perseguers
TYPO3 CMS Team
TYPO3 .... inspiring people to share!
Get involved: http://typo3.org
More information about the TYPO3-english
mailing list