Typoscript 菜单图像大小

Typoscript menu image size

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

现在我需要制作它,使图像 resized/cropped 的尺寸完全正确。我在哪里可以添加宽度和高度以使其工作?

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>
      }
    }
  }
}

我认为您需要使用 GIFBUILDER。 GIFBUILDER 会将图像传递给例如 ImageMagick,并会帮助您 cut/scrop/scale 图像满足您的需要。

类似

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

如果要调整图像大小,请将 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>
      }
    }
  }

要只渲染一张图像,您不应该首先列出所有图像。使用 FILESmaxItems 设置并从 stdWrap.

中删除 listNum
20 = FILES
20 {
  ...
  maxItems = 1
  ...
}