Samstag, 5. März 2011 / 15:53
Bilderserien mit gleicher Höhe und Breite
Abgelegt unter
TypoScript-Schnipsel
—
von
P. Arentzen
Hier eine Methode, wie man mit reinem TypoScript eine Serie mit Bildern erzeugen kann, die immer die gleiche Höhe und Breite haben. Dabei werden die Bilder nur beschnitten, wenn es sein muss - und nur so viel, wie es sein muss. Verwendung: z.B. in Slideshows, Gallerien etc.
Die Bilder werden in diesem Beispiel aus dem Resourcen-Feld einer bestimmten Seite ausgelesen.
#################################
### lib.specialImages
#################################
lib.specialImages = COA
lib.specialImages {
10 = LOAD_REGISTER
10.width = 160
10.height = 120
20 = CONTENT
20 {
table = pages
select {
pidInList = 71
andWhere = 97
andWhere.intval = 1
andWhere.wrap = uid = '|'
}
renderObj = TEXT
renderObj {
field = media
split {
token = ,
cObjNum = 10
10.cObject = COA
10.cObject {
10 = LOAD_REGISTER
# fix width
10.imgRaw1.cObject = IMG_RESOURCE
10.imgRaw1.cObject {
file.import = uploads/media/
file.import.current = 1
file.width.data = register:width
}
10.imgW1.data = TSFE:lastImgResourceInfo|0
10.imgH1.data = TSFE:lastImgResourceInfo|1
# fix height if needed
10.imgRaw2.data = register:imgRaw1
10.imgRaw2.override {
# wrap image rendering by COA because in COA if is evalated before creation of content
cObject = COA
cObject {
10 = IMG_RESOURCE
10 {
file.import = uploads/media/
file.import.current = 1
file.height.data = register:height
}
}
cObject.if {
value.data = register:height
isLessThan.data = register:imgH1
}
}
10.imgW2.data = TSFE:lastImgResourceInfo|0
10.imgH2.data = TSFE:lastImgResourceInfo|1
# now we an image that has the needed height and the needed width
# condition whether cropping is needed
cropif {
isPositive.cObject = COA
isPositive.cObject {
10 = TEXT
10.value = 0
20 = TEXT
20.value = +1
20.if {
value.data = register:width
equals.data = register:imgW2
negate = 1
}
30 = TEXT
30.value = +1
30.if {
value.data = register:height
equals.data = register:imgH2
negate = 1
}
stdWrap.prioriCalc = 1
}
}
# create a small template image for later use in GIFBUILDER (if needed)
10.imgTempl.cObject = COA
10.imgTempl.cObject {
10 = IMG_RESOURCE
10 {
file = GIFBUILDER
file {
XY = 10,10
backColor = green
}
}
}
10.imgTempl.cObject.if < .cropif
# crop image by using GIFBUILDER (if needed)
10.image.data = register:imgRaw2
10.image.override.cObject = COA
10.image.override.cObject {
10 = IMG_RESOURCE
10 {
file = GIFBUILDER
file {
XY = 2000,2000
format = jpg
backColor = red
10 = IMAGE
10 {
file {
import.data = register:imgTempl
width.data = register:width
height.data = register:height
}
}
20 = IMAGE
20 {
file.import.data = register:imgRaw2
}
30 = CROP
30 {
crop = [20.w]-[10.w]/2,[20.h]-[10.h]/2,[10.w],[10.h]
}
}
}
}
10.image.override.cObject.if < .cropif
50 = IMAGE
50.file.import.data = register:image
60 = TEXT
60.value =width: {TSFE:lastImgResourceInfo|0} - height: {TSFE:lastImgResourceInfo|1}
60.insertData = 1
90 = RESTORE_REGISTER
}
}
}
}
90 = RESTORE_REGISTER
}