Feature #16452
closedLoad $GLOBALS['TSFE'] with image dimensions when IMG_RESOURCE is used (feature request!)
0%
Description
As documented in the TSref, the IMAGE cObject loads $GLOBALS['TSFE']->lastImageInfo with the height, width and url of the image. This would be a very useful addition to the IMG_RESOURCE object as well--especially for dynamically generating CSS--specifically for generating background properties.
At the moment, for example, if we want to generate this:
#something {
width:456px;
height:56px;
background-image:url(typo3temp/GB/fubar.png);
}
...we can easily achieve all we need with TS, except the image dimensions. But these dimensions are ALREADY calculated when the IMG_RESOURCE cObject calls getImgResource(), so it seems foolish to re-calculate them with a userFunc, extension etc.
All that is required is the addition of a single line to the IMG_RESOURCE() function in class.tslib_content.php:
ORIGINAL:
00724 function IMG_RESOURCE($conf) {
00725 $imgArray = $this->getImgResource($conf['file'],$conf['file.']);
00726 return $this->stdWrap($imgArray3,$conf['stdWrap.']);
00727 }
MODIFIED:
00724 function IMG_RESOURCE($conf) {
00725 $imgArray = $this->getImgResource($conf['file'],$conf['file.']);
NEW LINE: $GLOBALS['TSFE']->lastImgResourceInfo=$imgArray;
00726 return $this->stdWrap($imgArray3,$conf['stdWrap.']);
00727 }
Possible Problems:
The only problem I was able to conceive of as a result of this change would arise only in a highly specific situation in a TS template:
1. An IMAGE object is created
2. An IMG_RESOURCE object is created
3. Some object is created that uses the contents of TSFE:lastImageInfo, expecting to retrieve the dimensions loaded into it by the IMAGE object created in (1).
In this situation, the TS object in 3 would receive an unexpected value; consequently, I suggest--as is shown in the code above--that a new entry be added to $GLOBALS['TSFE'] by IMG_RESOURCE(). Instead of using $GLOBALS['TSFE']->lastImageInfo as in IMAGE, $GLOBALS['TSFE']->lastImgResourceInfo (or similar) should be used instead.
(issue imported from #M4006)
Files