List of images as subpart in Typo3 - typo3

At current I'm making a list of images for a banner slider using code as follows:
page.10.marks.topimage = IMAGE
page.10.marks.topimage {
file.import.data = levelmedia: -1, "slide"
file.import = fileadmin/user_upload/
file.import.override.field = media
file.import.current = 1
file.import.listNum = 0
border = 0
file.height = 670
file.width = 1800
altText = Banner
titleText = Banner
wrap = <div id="slides">|
}
page.10.marks.topimage1 = IMAGE
page.10.marks.topimage1 {
file.import.data = levelmedia: -1, "slide"
file.import = fileadmin/user_upload/
file.import.override.field = media
file.import.current = 1
file.import.listNum = 1
border = 0
file.height = 670
file.width = 1800
altText = Banner
titleText = Banner
}
etc...
However, this means, every time the other admins want to add a new slide or remove one from the total count, I have to change this code. Adding the content of the slides is not a problem, they simply upload to user_upload and it pulls 0 to 3 at current. However, they want to be able to upload 5 images and have it show 5 or just 3 and have it show 3 and I need a more dynamic way to implement this. I'm still new to Typo3 (i really don't understand it, php is 10,000X easier!), so if anyone could, please explain to me better than the docs, how subparts work or what my solution might be.
And no I can't just write an extension to do it. Been there and tried that and still can't figure out how to get extensions in without breaking it.
FYI, if you could break it down and help me "like" it, that would be great, because at current, I'd rather they use wordpress or joomla or ANYTHING but this. If you've seen my other questions, then you'll realize, i've had 0 fun working with this cms and mostly because the documentation and/or "help" i've received has been almost completely useless to me. I only mention this so that maybe someone will break this down for me like i break down jquery/php/.net questions for others. It doesn't hurt to be polite and show a nub "step-by-step" instructions!

page.10.marks.topimage = TEXT
page.10.marks.topimage {
# retrieve data
data = levelmedia: -1, "slide"
override.field = media
# we have some filenames in a list, let us split the list
# and create images one by one
# if there are five images selected, the CARRAY "1" will be executed
# five times where current is loaded with only one filename
split {
# the images are separated via ","
token = ,
# you can do funny stuff with options split, f.e. if you want to give first
# and last image a different class... but thats another topic;)
# we just say, render every splitted object via CARRAY "1"
cObjNum = 1
1 {
# just render the single image,
# now there should be one filename in current only
10 = IMAGE
10 {
file.import.wrap = fileadmin/user_upload/|
file.import.current = 1
border = 0
file.height = 670
file.width = 1800
altText = Banner
titleText = Banner
}
}
}
}

Related

TYPO3 GIFBUILDER with image from FLUID

I want to use the GIFBUILDER to make an image with an overlay. The image should therefore be delivered via FLUID.
This is what I have so far:
FLUID
<f:for each="{product.images}" as="image">
<f:cObject typoscriptObjectPath="lib.overlay" data="{image: image.uid}" />
</f:for>
TypoScript
lib.overlay = IMAGE
lib.overlay {
file = GIFBUILDER
file {
XY = 300,500
format = jpg
quality = 80
10 = IMAGE
10 {
file.import = {field:image}
file.import.insertData = 1
file.import.treatReferenceAsId = 1
}
20 = TEXT
20 {
text = Copyright
fontColor= #dddddd
fontSize = 30
offset = 100,100
align = left
antiAlias = 1
}
}
}
At the moment, I only get a white Background with the label Copyright on it. However if I do somethinge like
10 = IMAGE
10.file = fileadmin/path/to/file
all works just fine.
So my question is: How do I pass the Image from FLUID correctly to TypoScript?
And as addition to this, how do I pass a value from the Contentelement via FLUID to make the overlay text dynamic too?
Best regards and Thanks in advance
UPDATE:
output of {image} (one image):
Replace
10 = IMAGE
10 {
file.import = {field:image}
file.import.insertData = 1
file.import.treatReferenceAsId = 1
}
with
10 = IMAGE
10 {
file.import.field = image
file.treatIdAsReference = 1
}
treatReferenceAsId should be treatIdAsReference. It's also a property of file, not of file.import. I'm not sure why file.import = {field:image} and insertData = 1 doesn't work, but file.import.field = image does. It's cleaner anyway, which is why I tried it.
You might also want to add a width and height or maxW and maxH to the image, unless you're 100% sure they're always 300x500 pixels.

Macro for multiple images analysis in the calculator plus

I have a set of images in a folder which their names are: 2 days.bmp 3 days.bmp ..... 28 days.bmp. Also, I have a folder with the background images exactly with the same names. I want to use the calculator plus and divide each image to its relevant background. I want to save time and do that at the same time instead of doing it for each image one by one. Is there any idea how can I do that? I have written a macro but it didn't work for me.
macro "Batch calculate images [1]" {
LocationOfFiles = getDirectory("Select Folder");
LocationOfbackgrounds = getDirectory("Select Folder of backgrounds");
LocationOfSave = getDirectory("Select Save Location");
setBatchMode(true);
FileList = getFileList(LocationOfFiles);
NumberOfFiles = FileList.length;
for (i=0; i<NumberOfFiles; i+=1) {
FileName = FileList[i];
pathtofile1 = LocationOfFiles+FileName;
open(pathtofile1);
name1 = getTitle();
pathtofile2 = LocationOfbackgrounds+FileName;
open(pathtofile2);
name2 = getTitle();
run("Calculator Plus", "i1="+name1+" i2="+name2+" operation=[Divide: i2 = (i1/i2) x k1 + k2] k1=255 k2=0 create");
selectWindow("Result");
SaveName = replace(name, ".bmp", "_backgroud subtracted.jpg");
saveAs("BMP", LocationOfSave+SaveName);
selectWindow(BackgroundImage);
close("\\Others");

How can I reliably set the backroundimage of a picturebox to be a random color?

I have a fairly simple color randomization snippet that I am using so I can accurately see the bounds of an image matrix I am making on screen. Problem is that I can not get it to work 100% of the time.
$listingImage = [System.Windows.Forms.PictureBox]::new()
...
# Temp color code to help with visual
$listingImage.BackColor = ([System.Drawing.Color](Get-Random -Minimum 1 -Maximum 999999))
The rest of the code follows in the question but that is the heart of what I am trying to do. I have seen it working several times but repeated executions show what seem like, empty, blank or otherwise invisible picture boxes. If I hard code a colour like $listingImage.BackColor = [System.Drawing.Color]::DarkCyan I can see that working fine every time. I want different colours though so I can see how to boxes are lining up with each other.
The code you can use for testing is as follows:
Add-Type -AssemblyName System.Windows.Forms
$imageContainerSize = [Drawing.Size]::new(100,100) # Width, Height
$numberOfImages = [pscustomobject]#{
Horizontal = 5
Vertical = 4
}
$formOverallSize = [Drawing.Size]::new(
$imageContainerSize.Width * $numberOfImages.Horizontal,
$imageContainerSize.Height * $numberOfImages.Vertical
)
$listingImageForm = New-Object System.Windows.Forms.Form
$listingImageForm.Text = $listing.URL
$listingImageForm.Size = $formOverallSize
$listingImageForm.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedSingle
$listingImageForm.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen
$imageMatrixXOffset = 0
$imageMatrixYOffset = 0
# Load the image place holder image.
$placeholderImagePath = "m:\scripts\test.png"
# $placeholderImage = [system.drawing.image]::FromStream([IO.MemoryStream]::new([System.IO.File]::ReadAllBytes($placeholderImagePath)))
# Create an image matrix from the images provided in a listing group
for ($verticalImageIndex = 0; $verticalImageIndex -lt $numberOfImages.Vertical; $verticalImageIndex++){
for ($horizonalImageIndex = 0; $horizonalImageIndex -lt $numberOfImages.Horizontal; $horizonalImageIndex++){
$listingImage = [System.Windows.Forms.PictureBox]::new()
$listingImage.Size = $imageContainerSize
$listingImage.BorderStyle = [System.Windows.Forms.BorderStyle]::None
$listingImage.SizeMode = [System.Windows.Forms.PictureBoxSizeMode]::CenterImage
$listingImage.Location = [System.Drawing.Point]::new($horizonalImageIndex * $listingImage.Size.Width + $imageMatrixXOffset,
$verticalImageIndex * $listingImage.Size.Height + $imageMatrixYOffset )
# Temp color code to help with visual
$listingImage.BackColor = ([System.Drawing.Color](Get-Random -Minimum 1 -Maximum 999999))
# Place the image based
# $listingImage.Image = $placeholderImage
$listingImage.Tag = "h:$horizonalImageIndex v:$verticalImageIndex"
# Download the image as a memory stream to bypass saving the file
$listingImageForm.Controls.Add($listingImage)
}
}
# Adjust the size of the form to account for the title bar and the width of the form.
$formBorderWidth = ($listingImageForm.Width - $listingImageForm.ClientSize.Width) / 2
$formTitleBarHeight = $listingImageForm.Height – $listingImageForm.ClientSize.Height – 2 * $formBorderWidth
# Adjust for based on previosly calculated values
$listingImageForm.Size.Height = $listingImageForm.Size.Height + $formTitleBarHeight + ($formBorderWidth * 2)
$listingImageForm.Size.Width = $listingImageForm.Size.Width + ($formBorderWidth * 2)
$listingImageForm.Add_Shown({$listingImageForm.Activate()})
[void]$listingImageForm.ShowDialog()
"Form Height : $($listingImageForm.Size.Height)"
"Form Width : $($listingImageForm.Size.Width)"
"Image Height: $($imageContainerSize.Height)"
"Image Width : $($imageContainerSize.Width)"
$listingImageForm.Dispose()
Why is my randomization not working correctly? I really don't think it is the randomization itself since I can run
The problem is with the randomization upperbound.
[System.Drawing.Color](Get-Random -Minimum 1 -Maximum 999999)
So this will only generate values of a maximum 999999. The number will never get high enough to change the alpha channel / opacity value of the 'random' colour. If you kept trying that code in the command line you will see the A value is always zero.
([System.Drawing.Color](Get-Random -Minimum 1 -Maximum 999999))
R : 10
G : 177
B : 51
A : 0
IsKnownColor : False
IsEmpty : False
IsNamedColor : False
IsSystemColor : False
Name : ab133
A larger testing set to prove the point.
1..1000 | ForEach-Object {
([system.Drawing.Color](Get-Random -Minimum 1 -Maximum 999999))} |
Group-Object -Property A -NoElement
Count Name
----- ----
1000 0
This is why it did not appear to work as the opacity was always zero. I suspect it was periodically working as you might have been changing the randomization code between tests and not correlating the changes.
RGBA Values can be represented as int32 integers values. Setting your randomization to use that as your upper bound will prove more fruitful.
[System.Drawing.Color](Get-Random ([int32]::MaxValue))
Yes, it is possible you could randomize all 0 alpha again but for simple testing that should work just fine.
Click image to embiggen
Or, as Ansgar Wiechers mentions in comments, this might be a friendlier solution to the issue
[Drawing.Color]::FromArgb((Random 256),(Random 256),(Random 256),(Random 256))

hide page & subpages from menu

I have the following page structure in TYPO3:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
Now I want to have 1/* + 4/* included in the header menu and 4/* + 7/* in the footer menu. Since the header and footer menus are different, I cannot just use the "hide in menu" feature and need to do it in TypoScript instead.
Here's what I have so far:
HEADERMENU = HMENU
HEADERMENU {
1 = TMENU
1.expAll = 1
1.NO = 1
1.NO {
stdWrap.if.value.field = uid
stdWrap.if.equals = 7
stdWrap.if.negate = 1
}
2 < .1
}
FOOTERMENU < HEADERMENU
FOOTERMENU.1.NO.stdWrap.if.equals = 1
The problem with this is, that it still displays the pages 8+9 in the header and 2+3 in the footer, even if it does not display page 1/7 anymore. I know that I could use if.isInList and the provide all subpage IDs, but then I'd have to change the TypoScript everytime I add a new page. If possible, I'd like to dynamically exclude a page and all its subpages.
How can I do that?
As Daniel mentioned in his answer there is a way to display all subpages of the selected pages. special = directory displays however only the subpages. So you could see only 2/3 and 5/6 and 8/9 in your menus.
special = directory
"This will generate a menu of all pages with pid = 35 and pid = 56."
I would suggest the excludeUidList property.
HEADERMENU = HMENU
HEADERMENU {
excludeUidList = 7
1 = TMENU
1.expAll = 1
2 < .1
}
FOOTERMENU < HEADERMENU
FOOTERMENU.excludeUidList = 1
It is working as a WHERE condition in a db SELECT query, so you won't get those pages on the first level and neither will it find their subpages then.
You could go for the special=directory approach to render a Menu of one or more pages and their subpages.
HEADERMENU.special = directory
HEADERMENU.special.value = 1, 4
More information in the documentation.

Typoscript - Splitting "media" and "imagecaption" simultaneously

I have made a plugin where I store many images in the "media" field and jsut as many captions in the field "imagecaption".
Now my wish is to display it like this:
image1.png
caption 1
image2.png
caption 2
image3.png
caption 3
This is how ive been trying to do it, but its not working:
plugin.tx_myplugin_pi1 = COA
plugin.tx_myplugin_pi1{
10 = TEXT
10.field = header
10.wrap = <h1>|</h1>
20 = COA
20{
10 = TEXT
10{
field = media
split{
token = ,
cObjNum = 1
1.current = 1
}
}
20 = TEXT
20{
field = imagecaption
split{
token.char = 10
cObjNum = 1
1.current = 1
}
}
}
}
But its not really working, as it shows first all the filenames and then the caption.
How could I do it?
Split is a function which returns all elements. Within 20.10 you get the content of field image, splitted by an newline f.e. and after that, you get the content of 20.20 which has the imagecaption.
What you need to do (untested):
10 = TEXT
10{
field = media
split{
token = ,
cObjNum = 1
1.current = 1
# for each image, add the imagecaption
1.append = TEXT
1.append {
field = imagecaption
# split saves the index in REGISTER:SPLIT_COUNT
listNum.stdWrap.data = REGISTER:SPLIT_COUNT
listNum.splitChar = 10
}
}
}
I do not think that token = \n is correct. You properly need to use .char = 10.
Also you will need to nest your TS somehow, because the current solution does handle the fields one by one.
I can't remember at the moment but I've wrote an extension that adds a frame to a picture and caption. It can solve your problem with the captions: http://typo3.org/extensions/repository/view/ch_imgtext_renderengine/current/.