2016-10-11 44 views
1

在我的菜单中,我使用脚本来检索加载在页面资源中的图像。Typoscript菜单图像大小

现在我需要做到这一点,所以图像调整大小/裁剪到正确的大小。我可以在哪里添加宽度和高度以使其工作?

NO { 
    wrapItemAndSub = <li>|</li> 
    stdWrap.cObject = COA 
    stdWrap.cObject { 
    10 = TEXT 
    10.field = title 
    10.wrap = <span>|</span> 
    20 = FILES 
    20 { 
     # Get the images related to the current page 
     references { 
     table = pages 
     fieldName = media 
     } 
     # Render each image and wrap it as appropriate 
     renderObj = TEXT 
     renderObj { 
     typolink { 
     parameter.data = file:current:publicUrl 
     forceAbsoluteUrl = 1 
     returnLast = url 
     } 
     wrap = |, 
    } 
    stdWrap { 
     # Take only the first image if several are defined 
     listNum = 0 
     # Use default image if none is available 
     ifEmpty.cObject = TEXT 
     ifEmpty.cObject.typolink { 
     parameter = fileadmin/templates/example/images/placeholder.png 
     forceAbsoluteUrl = 1 
     returnLast = url 
     } 
     wrap = <div><img src="|" /></div> 
     } 
    } 
    } 
} 

回答

2

如果要调整图像替换renderObj = TEXT通过renderObj = IMG_RESOURCE

例子:

NO { 
    wrapItemAndSub = <li>|</li> 
    stdWrap.cObject = COA 
    stdWrap.cObject { 
    10 = TEXT 
    10.field = title 
    10.wrap = <span>|</span> 
    20 = FILES 
    20 { 
     # Get the images related to the current page 
     references { 
     table = pages 
     fieldName = media 
     } 
     # Render each image and wrap it as appropriate 
     renderObj = IMG_RESOURCE 
     renderObj { 
     file.import.data = file:current:uid 
     file.treatIdAsReference = 1 
     file.width = 250c 
     file.height = 250c 
     wrap = |, 
     } 
     stdWrap { 
     # Take only the first image if several are defined 
     listNum = 0 
     # Use default image if none is available 
     ifEmpty.cObject = TEXT 
     ifEmpty.cObject.typolink { 
      parameter = fileadmin/templates/example/images/placeholder.png 
      forceAbsoluteUrl = 1 
      returnLast = url 
     } 
     wrap = <div><img src="|" /></div> 
     } 
    } 
    } 

要仅渲染一个图像,您不应首先创建所有图像的列表。使用maxItems设置FILES并从stdWrap中删除listNum

20 = FILES 
20 { 
    ... 
    maxItems = 1 
    ... 
} 
+0

这是完美的谢谢! – user500665

0

我认为你需要使用GIFBUILDER。 GIFBUILDER会将Image传递给ImageMagick,并帮助您根据需要剪切/缩放/缩放图像。

喜欢的东西

lib.image = IMAGE 
lib.image { 
    file = GIFBUILDER 
    file { 
    #use the c in XY to crop 
    XY = 1024c,768c 
    format = jpg 
    10 = IMAGE 
    10.file = fileadmin/image.jpg 

    } 
} 

你可以阅读更多关于Gifbuilder这里:

https://docs.typo3.org/typo3cms/TyposcriptReference/Gifbuilder/Index.html

+0

您不需要运行''''GIFBUILDER'''来缩放图像。内容元素IMAGE和IMG_RESOURCE可以做到这一点,并且不需要像GIFBUILDER这样的内存和处理时间。 –