tldr:如何在CommandController中使用GIFBUILDER图像渲染TypoScript COA对象?在CommandController中呈现TypoScript对象
我目前正在开发一个电子商务平台,我需要定期导入一个包含产品目录的Excel文件。从excel文件中的一行数据创建产品后,将搜索目录以查找与该项目相关的产品图像,并将它们作为FileReferences链接到产品。我写了一个ImportCommandController来处理这个问题。
这一切都像一个魅力,唯一突出的问题是图像处理的性能。对产品列表页面的第一次调用需要30秒,这是单个视图的第一个请求。我需要从头开始重新创建整个目录,并且源产品图像是大文件,我对此没有任何影响。
该目录的产品图像由TypoScript生成,负责在正方形白色背景中放置这些图像,并返回IMG_RESOURCE网址。我使用cObject ViewHelper从Fluid模板中调用TypoScript。
我一直在试图从ImportCommandController-> importAction调用TypoScript的这一点,以便导入cronjob会照顾事先创建这些缩放图像,使用相同的文件名散列,所以它们已经被处理他们被单一视图调用。但我无法做到这一点。
Typo脚本问题IST这样的:
plugin.tx_productfinder_products {
// Productfinder-Produktbilder
// Bilder quadratisch auf weissen Hintergrund einpassen
productimage = COA
productimage {
// Daten der FileReference im Regsiter ablegen
10 = FILES
10 {
references.data = current
renderObj = COA
renderObj {
10 = LOAD_REGISTER
10 {
param = TEXT
param.data = file:current.uid
}
}
}
20 = IMG_RESOURCE
20 {
file = GIFBUILDER
file {
XY = 960,960
format = jpg
quality = 95
backColor = #ffffff
20 = IMAGE
20 {
offset = 960-[20.w]/2,960-[20.h]/2
file {
import.data = current
treatIdAsReference = 1
maxW = 960
maxH = 960
}
}
// // Text aus Daten der FileReference als Wasserzeichen ins Bild rendern
// 30 = TEXT
// 30 {
// //text.data = register:param
// text.data = current
// fontColor= #dddddd
// fontSize = 12
// offset = 20,[20.h]-20
// align = left
// antiAlias = 1
// }
}
}
}
}
而且我把这些从流体模板中像这样:
<img class="img-responsive" src="{f:cObject(typoscriptObjectPath:'plugin.tx_productfinder_products.productpreviewimage', data:'{image.uid}')}">
有什么我想这么远?几乎所有的东西。
我第一次尝试直接调用ContentObjectRenderer,
/** @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $cObj */
$contentObject = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
$contentObject->setCurrentVal($image->getUid());
$content = $contentObject->cObjGetSingle($this->settings['productimagetest'], $this->settings['productimagetest.']);
导致这些奇怪的错误。
Oops, an error occurred: PHP Warning: imagejpeg(typo3temp/GB/csm_8000424600_cbbd127be3_9cb1d3c8cc.jpg): failed to open stream: No such file or directory in /html/typo3/typo3_src-7.6.16/typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php line 2912
看来,关于Grapics处理TYPO3配置没有以同样的方式初始化,因为它是针对前端。
接下来,我尝试使用Instanciate StandaloneFluidView为每个项目呈现整个SingleItem模板,但我无法弄清楚,因为Request和Context都缺失,因此模板中引用的部分未呈现。
然后,我累了,只是每次创建单个项目的FrontendUrls,并从命令控制器请求他们,
/** @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $cObj */
$contentObject = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
$test = $contentObject->typolink_URL(array(
'parameter' => 671,
'additionalParams' =>
'&tx_productfinder_products[product]='.$product->getUid().
'&tx_productfinder_products[action]=show'.
'&tx_productfinder_products[controller]=Product',
'returnLast' => 'url'
));
$this->outputLine(print_r($test,true));
,但以这种方式生成的URL缺少cHash。
任何人都可以提供帮助或不同的方法吗?
我目前没有时间把它弄出来,但是你是否尝试过使用你的'FileReference'对象来做这样的事情? '$ fileReference-> getOriginalFile() - > process('Image',['width'=> 960,'height'=> 960,'offset'=>'960- [20.w]/2,960- [20 .h]/2']);' 我不知道偏移量部分,但是这应该在没有前端上下文的情况下工作。 看看'typo3/sysext/core/Resource/Processing' –
问题是,我不知道如何应用其余的GIFBBUILDER配置。无论源图像的高宽比如何,图像都需要适合白色方形。因此,渲染图像与TypoScript不同将导致不同的进程哈希。不过,谢谢你的方法,我会绕过这个。 – j4k3