2016-10-11 41 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這樣的內存和處理時間。 –