How to perform crop settings in TypoScript? - typo3

I'm using TYPO3 7 and want to apply the crop settings of the media field in this TypoScript snippet:
lib.backgroundimage = FILES
lib.backgroundimage {
references.data = levelmedia:-1, slide
references.listNum = 0
renderObj = IMG_RESOURCE
renderObj.altText.data = file:current:description
renderObj.file {
import.data = file:current:publicUrl
width = 1920
height = 600c
}
}
How can I do this?

crop.data = file:current:crop is the key
your complete code:
lib.backgroundimage = FILES
lib.backgroundimage {
references.data = levelmedia:-1, slide
references.listNum = 0
renderObj = IMG_RESOURCE
renderObj.altText.data = file:current:description
renderObj.file {
import.data = file:current:publicUrl
crop.data = file:current:crop
width = 1920
height = 600c
}
}

try file.import.data = file:current:uid as used in CSS Styled content.
Also see the documentation about this which states that the crop setting is automatically imported: https://docs.typo3.org/typo3cms/extensions/core/latest/Changelog/7.2/Feature-65584-AddImageCropping.html

Related

Get meta data of a file in FILES-Object

I'm trying to get file metadata in a FILES-Object:
I have a CONTENT-Object to build Teaser of subpages of a Page. Because Inheritance of Levelmedia did not work for me in the CONTENT-Object I have build a Fallback with ifEmpty. Here is my TS:
lib.subpages = COA
lib.subpages {
10 = CONTENT
10 {
table = pages
select.where = nav_hide != 1 AND doktype IN (1,3,4)
renderObj = COA
renderObj {
stdWrap.wrap = <div class="grid-elem teaser"><div>|</div</div>
stdWrap.wrap.insertData = 1
stdWrap.innerWrap = |
10 = COA
10 {
10 = FILES
10{
references {
field = media
}
begin = 0
maxItems = 1
renderObj = COA
renderObj {
10 = IMAGE
10 {
file.import.data = file:current:publicUrl
file.crop.data = file:current:crop
file.cropVariant = subpages
altText.data = file:current:alternative
titleText.data = file:current:title
}
}
stdWrap.ifEmpty.cObject = COA
stdWrap.ifEmpty.cObject.10 = FILES
stdWrap.ifEmpty.cObject.10 {
references {
data = levelmedia:-1,slide
}
begin = 0
maxItems = 1
renderObj = COA
renderObj {
10 = IMAGE
10 {
file.import.data = file:current:publicUrl
file.crop.data = file:current:crop
file.cropVariant = subpages
altText.data = file:current:alternative
titleText.data = file:current:title
}
}
}
stdWrap.wrap.typolink.parameter.field = uid
stdWrap.wrap = <figure>|</figure>
}
}
20 = COA
20 {
10 = TEXT
10.wrap =<div class="category">|</div>
10.data = levelfield:1, title
20 = TEXT
20.wrap = <h3 class="teaser-title">|</h3>
20.stdWrap.wrap.typolink.parameter.field = uid
30 = TEXT
30.wrap = <p>|</p>
30.field = abstract
30.crop=150 | ... |1
}
20.wrap = <div class="teaser-content">|</div>
}
}
}
The first FILES gets an image from media-field of the page, and if there is no image, in the ifEmpty-Tree I search for an image in the rootline. That solution gives me the images in the page tree as I expected. But only die FILES in ifEmpty, which is referencing to levelmedia also delivers the metadata of the specific file. The FILES which referencing to "media" gives me only the file without any meta data.
Does anyone have a hint for me for what I'm doing wrong?
Solved: Instead of field = media in the references clause of the FILES-Object it has to be fieldName = media
With this modification the crop variant works and I get the title- and alt-texts as well.

Use cropped image with fallback in TypoScript in TYPO3 8

This TS code always produces a 600x400px image:
10 = FILES
10 {
required = 1
references {
table = tt_content
fieldName = image
}
renderObj = IMAGE
renderObj {
wrap = <div class="teaser-image">|</div>
file.import.data = file:current:originalUid // file:current:uid
file.crop.data = file:current:crop
file.width=600c
file.height=400c
}
}
If I remove
file.width=600c
file.height=400c
then the cropped image from the crop wizard will be used.
But I need both (it's an upgrade of an existing site): if available, the cropped image is used, but if not, the given height and width are used.
How do I use the "file:current:crop" part to override width & height only if given? Or how do I set a fallback? something like...
file.crop.data = file:current:crop // fallback...
I've moved to FLUIDTEMPLATE in the renderObj:
renderObj = FLUIDTEMPLATE
renderObj {
file = path/to/templates/content/teaser.html
dataProcessing {
10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
10 {
references.fieldName = image
references.table = tt_content
as = teaserimages
}
}
}
(The FilesProcessor is required)
And then in the template
<img src="<f:uri.image image="{teaserimages.0}" width="600c" height="400c" />
Behaves as expected

Typoscript menu image size

In my menu I am using a script to retrieve the image loaded in the page's resources.
Now I need to make it so the image is resized/cropped to exactly the right size. Where can I add the width and height to make it work?
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>
}
}
}
}
If you want to resize the image replace the renderObj = TEXT through renderObj = IMG_RESOURCE
Example:
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>
}
}
}
To render only one image, you shouldn't make first an list of all images. Use the maxItems setting of FILES and remove the listNum from stdWrap.
20 = FILES
20 {
...
maxItems = 1
...
}
I think you need to use GIFBUILDER.
The GIFBUILDER will pass the Image to for example ImageMagick and will help you to cut/scrop/scale the image to your needs.
Something like
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
}
}
You can read more about Gifbuilder here:
https://docs.typo3.org/typo3cms/TyposcriptReference/Gifbuilder/Index.html

TYPO3 File Abstraction Layer FILES listNum

I have a menu and want to access on media files from the page configurations. This works quite well, but it gives all the images of the media files. ListNum it does not work. Do you have an idea or an alternative solution? Important I want to use file:current:description and file:current:title
after.cObject = FILES
after.cObject {
references {
table = pages
fieldName = media
# listNum = 1 not working
}
renderObj = IMAGE
renderObj {
file.import.data = file:current:originalUid
file.width = 250
file.import.listNum = 1
altText.data = file:current:description
}
}
The code of the OP and of maholtz's answer does not work in current TYPO3 versions any more. Here is the correct TypoScript for 6.2 and beyond:
1 = TMENU
1 {
wrap = <ul>|</ul>
NO = 1
NO {
wrapItemAndSub = <li>|</li>
stdWrap.override.cObject = FILES
stdWrap.override.cObject {
references {
table = pages
fieldName = media
}
renderObj = IMAGE
renderObj {
file.import.data = file:current:uid
file.treatIdAsReference = 1
titleText.data = file:current:title // field:nav_title // field:title
altText.data = file:current:alternative // field:nav_title // field:title
}
# start with second image
begin = 1
# show only one image
maxItems = 1
}
}
}
The parameter begin defines which of multiple images should be used (e.g. if you need one image as a headline background for the page and another one as an icon in the menus).
If you increase the maxItems parameter, multiple images will be returned (if multiple images are defined in the resources tab).
If you want to append/prepend the image to the menu text instead of replacing it, you have to change stdWrap.override.cObject to after.cObject or before.cObject in the above code.
after.cObject = FILES
after.cObject {
references {
table = pages
fieldName = media
# listNum = 1 not working
}
renderObj = IMAGE
renderObj {
file.import.data = file:current:originalUid
file.width = 250
file.import.listNum = 1
altText.data = file:current:description
}
# start with first image
begin = 0
# show only two images
maxItems = 2
}
There are two registered filled:
REGISTER:FILES_COUNT
and
REGISTER:FILE_NUM_CURRENT
Implemented in typo3/sysext/frontend/Classes/ContentObject/FilesContentObject.php
Here comes another example with stacked image references. This code can be used with jquerypicture.
lib.headerImg = COA
lib.headerImg.wrap = <picture alt="some alttext">|</picture>
lib.headerImg {
// <source>
10 = FILES
10 {
references {
table = pages
uid.data = tsfe:id
fieldName = media
}
renderObj = IMG_RESOURCE
renderObj {
file.import.data = file:current:uid
file.treatIdAsReference = 1
stdWrap.dataWrap = <source src="|">
# the 2nd pic gets another attribute
stdWrap.dataWrap.override = <source src="|" media="(min-width:600px)">
stdWrap.dataWrap.override.if.value = 1
stdWrap.dataWrap.override.if.equals.data = register:FILE_NUM_CURRENT
# altText.data = file:current:title
}
begin = 0
maxItems = 2
}
// <noscript>
20 < .10
20.begin = 1
20.maxItems = 1
20.renderObj.stdWrap.dataWrap = <noscript><img src="|" alt="{file:current:title}"></noscript>
}

typoscript renderObj image problem

i dont figure out how i can render an image into my renderObj COA.
Here my code:
renderObj = COA
renderObj {
10 = TEXT
10.field = header
10.parseFunc < lib.parseFunc_RTE
10.wrap = <h2>|</h2>
20 = TEXT
20.field = bodytext
20.parseFunc < lib.parseFunc_RTE
30 = IMAGE
???
30.parseFunc < lib.parseFunc_RTE
}
As you can see i typed only three questionmarks as placeholder.
Please help me :(
Depending on where you get the image from, here are some examples.
renderObj = COA
renderObj {
# Static image
10 = IMAGE
10.file = fileadmin/user_upload/images/myPicture.jpg
# From a database field
20 = IMAGE
20.file.import = uploads/pics/
20.file.import {
field = image
listNum = 0
}
}
There is no need to assign lib.parseFunc_RTE to the image, since that's only valid for RTE content.
See the official documentation, TSref, for more details on IMAGE ande imgResource.
IMAGE: http://typo3.org/documentation/document-library/references/doc_core_tsref/4.4.0/view/1/7/#id2632631
imgResource: http://typo3.org/documentation/document-library/references/doc_core_tsref/4.4.0/view/1/5/#id2619917