* Updated my email address from "kasper@typo3.com" (which is closed and will stay...
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / class.tslib_gifbuilder.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2004 Kasper Skaarhoj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Generating gif/png-files from TypoScript
29 * Used by the menu-objects and imgResource in TypoScript.
30 *
31 * $Id$
32 * Revised for TYPO3 3.6 June/2003 by Kasper Skaarhoj
33 *
34 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
35 */
36 /**
37 * [CLASS/FUNCTION INDEX of SCRIPT]
38 *
39 *
40 *
41 * 102: class tslib_gifBuilder extends t3lib_stdGraphic
42 * 127: function start($conf,$data)
43 * 296: function gifBuild()
44 * 324: function make()
45 *
46 * SECTION: Various helper functions
47 * 475: function checkTextObj($conf)
48 * 552: function calcOffset($string)
49 * 601: function getResource($file,$fileArray)
50 * 616: function checkFile($file)
51 * 627: function fileName($pre)
52 * 637: function extension()
53 *
54 * TOTAL FUNCTIONS: 9
55 * (This index is automatically created/updated by the extension "extdeveval")
56 *
57 */
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79 /**
80 * GIFBUILDER extension class.
81 * This class allows for advanced rendering of images with various layers of images, text and graphical primitives.
82 * The concept is known from TypoScript as "GIFBUILDER" where you can define a "numerical array" (TypoScript term as well) of "GIFBUILDER OBJECTS" (like "TEXT", "IMAGE", etc.) and they will be rendered onto an image one by one.
83 * The name "GIFBUILDER" comes from the time where GIF was the only file format supported. PNG is just as well to create today (configured with TYPO3_CONF_VARS[GFX])
84 * Not all instances of this class is truely building gif/png files by layers; You may also see the class instantiated for the purpose of using the scaling functions in the parent class, t3lib_stdGraphic.
85 *
86 * Here is an example of how to use this class (from tslib_content.php, function getImgResource):
87 *
88 * $gifCreator = t3lib_div::makeInstance('tslib_gifbuilder');
89 * $gifCreator->init();
90 * $theImage='';
91 * if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib']) {
92 * $gifCreator->start($fileArray,$this->data);
93 * $theImage = $gifCreator->gifBuild();
94 * }
95 * return $gifCreator->getImageDimensions($theImage);
96 *
97 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
98 * @package TYPO3
99 * @subpackage tslib
100 * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=377&cHash=e00ac666f3
101 */
102 class tslib_gifBuilder extends t3lib_stdGraphic {
103
104 // Internal
105 var $im = ''; // the main image
106 var $w = 0; // the image-width
107 var $h = 0; // the image-height
108 var $map; // map-data
109 var $workArea;
110 var $setup = Array (); // This holds the operational setup for gifbuilder. Basically this is a TypoScript array with properties.
111 var $data = Array(); // This is the array from which data->field: [key] is fetched. So this is the current record!
112 var $objBB = Array();
113 var $myClassName = 'gifbuilder';
114 var $charRangeMap=array();
115
116 /**
117 * Initialization of the GIFBUILDER objects, in particular TEXT and IMAGE. This includes finding the bounding box, setting dimensions and offset values before the actual rendering is started.
118 * Modifies the ->setup, ->objBB internal arrays
119 * Should be called after the ->init() function which initializes the parent class functions/variables in general.
120 * The class tslib_gmenu also uses gifbuilder and here there is an interesting use since the function findLargestDims() from that class calls the init() and start() functions to find the total dimensions before starting the rendering of the images.
121 *
122 * @param array TypoScript properties for the GIFBUILDER session. Stored internally in the variable ->setup
123 * @param array The current data record from tslib_cObj. Stored internally in the variable ->data
124 * @return void
125 * @see tslib_cObj::getImgResource(), tslib_gmenu::makeGifs(), tslib_gmenu::findLargestDims()
126 */
127 function start($conf,$data) {
128
129 if (is_array($conf)) {
130 $this->setup = $conf;
131 $this->data = $data;
132
133 // Initializing global Char Range Map
134 $this->charRangeMap = array();
135 if (is_array($GLOBALS['TSFE']->tmpl->setup['_GIFBUILDER.']['charRangeMap.'])) {
136 foreach($GLOBALS['TSFE']->tmpl->setup['_GIFBUILDER.']['charRangeMap.'] as $cRMcfgkey => $cRMcfg) {
137 if (is_array($cRMcfg)) {
138
139 // Initializing:
140 $cRMkey = $GLOBALS['TSFE']->tmpl->setup['_GIFBUILDER.']['charRangeMap.'][substr($cRMcfgkey,0,-1)];
141 $this->charRangeMap[$cRMkey] = array();
142 $this->charRangeMap[$cRMkey]['charMapConfig'] = $cRMcfg['charMapConfig.'];
143 $this->charRangeMap[$cRMkey]['cfgKey'] = substr($cRMcfgkey,0,-1);
144 $this->charRangeMap[$cRMkey]['multiplicator'] = (double)$cRMcfg['fontSizeMultiplicator'];
145 $this->charRangeMap[$cRMkey]['pixelSpace'] = intval($cRMcfg['pixelSpaceFontSizeRef']);
146 }
147 }
148 }
149
150 // Getting sorted list of TypoScript keys from setup.
151 $sKeyArray=t3lib_TStemplate::sortedKeyList($this->setup);
152
153 // Setting the background color, passing it through stdWrap
154 if ($conf['backColor.'] || $conf['backColor']) {
155 $cObj =t3lib_div::makeInstance('tslib_cObj');
156 $cObj->start($this->data);
157 $this->setup['backColor'] = trim($cObj->stdWrap($this->setup['backColor'], $this->setup['backColor.']));
158 }
159 if (!$this->setup['backColor']) {$this->setup['backColor']='white';}
160
161 // Transparent GIFs
162 // not working with reduceColors
163 // there's an option for IM: -transparent colors
164 if ($conf['transparentColor.'] || $conf['transparentColor']) {
165 $cObj =t3lib_div::makeInstance('tslib_cObj');
166 $cObj->start($this->data);
167 $this->setup['transparentColor_array'] = explode('|', trim($cObj->stdWrap($this->setup['transparentColor'], $this->setup['transparentColor.'])));
168 }
169
170 // Set default dimensions
171 if (!$this->setup['XY']) {$this->setup['XY']='120,50';}
172
173
174 // Checking TEXT and IMAGE objects for files. If any errors the objects are cleared.
175 // The Bounding Box for the objects is stored in an array
176 foreach($sKeyArray as $theKey) {
177 $theValue=$this->setup[$theKey];
178
179 if (intval($theKey) && $conf=$this->setup[$theKey.'.']) {
180 // Swipes through TEXT and IMAGE-objects
181 switch($theValue) {
182 case 'TEXT':
183 if ($this->setup[$theKey.'.'] = $this->checkTextObj($conf)) {
184
185 // Adjust font width if max size is set:
186 if ($this->setup[$theKey.'.']['maxWidth']) {
187 $this->setup[$theKey.'.']['fontSize'] = $this->fontResize($this->setup[$theKey.'.']); //RTF - this has to be done before calcBBox
188 }
189
190 // Calculate bounding box:
191 $txtInfo=$this->calcBBox($this->setup[$theKey.'.']);
192 $this->setup[$theKey.'.']['BBOX']=$txtInfo;
193 $this->objBB[$theKey]=$txtInfo;
194 $this->setup[$theKey.'.']['imgMap']=0;
195 }
196 break;
197 case 'IMAGE':
198 $fileInfo = $this->getResource($conf['file'],$conf['file.']);
199 if ($fileInfo) {
200 $this->setup[$theKey.'.']['file']=$fileInfo[3];
201 $this->setup[$theKey.'.']['BBOX']=$fileInfo;
202 $this->objBB[$theKey]=$fileInfo;
203 if ($conf['mask']) {
204 $maskInfo = $this->getResource($conf['mask'],$conf['mask.']);
205 if ($maskInfo) {
206 $this->setup[$theKey.'.']['mask']=$maskInfo[3];
207 } else {
208 $this->setup[$theKey.'.']['mask'] = '';
209 }
210 }
211 } else {
212 unset($this->setup[$theKey.'.']);
213 }
214 break;
215 }
216 // Checks if disabled is set... (this is also done in menu.php / imgmenu!!)
217 if ($conf['if.']) {
218 $cObj =t3lib_div::makeInstance('tslib_cObj');
219 $cObj->start($this->data);
220
221 if (!$cObj->checkIf($conf['if.'])) {
222 unset($this->setup[$theKey]);
223 unset($this->setup[$theKey.'.']);
224 }
225 }
226 }
227 }
228
229 // Calculate offsets on elements
230 $this->setup['XY'] = $this->calcOffset($this->setup['XY']);
231 $this->setup['offset'] = $this->calcOffset($this->setup['offset']);
232 $this->setup['workArea'] = $this->calcOffset($this->setup['workArea']);
233
234 foreach ($sKeyArray as $theKey) {
235 $theValue=$this->setup[$theKey];
236
237 if (intval($theKey) && $conf=$this->setup[$theKey.'.']) {
238 switch($theValue) {
239 case 'TEXT':
240 case 'IMAGE':
241 if ($this->setup[$theKey.'.']['offset']) {
242 $this->setup[$theKey.'.']['offset'] = $this->calcOffset($this->setup[$theKey.'.']['offset']);
243 }
244 break;
245 case 'BOX':
246 if ($this->setup[$theKey.'.']['dimensions']) {
247 $this->setup[$theKey.'.']['dimensions'] = $this->calcOffset($this->setup[$theKey.'.']['dimensions']);
248 }
249 break;
250 case 'WORKAREA':
251 if ($this->setup[$theKey.'.']['set']) {
252 $this->setup[$theKey.'.']['set'] = $this->calcOffset($this->setup[$theKey.'.']['set']);
253 }
254 break;
255 case 'CROP':
256 if ($this->setup[$theKey.'.']['crop']) {
257 $this->setup[$theKey.'.']['crop'] = $this->calcOffset($this->setup[$theKey.'.']['crop']);
258 }
259 break;
260 case 'SCALE':
261 if ($this->setup[$theKey.'.']['width']) {
262 $this->setup[$theKey.'.']['width'] = $this->calcOffset($this->setup[$theKey.'.']['width']);
263 }
264 if ($this->setup[$theKey.'.']['height']) {
265 $this->setup[$theKey.'.']['height'] = $this->calcOffset($this->setup[$theKey.'.']['height']);
266 }
267 break;
268 }
269 }
270 }
271 // Get trivial data
272 $XY = t3lib_div::intExplode(',',$this->setup['XY']);
273 $maxWidth = intval($this->setup['maxWidth']);
274 $maxHeight = intval($this->setup['maxHeight']);
275
276 $XY[0] = t3lib_div::intInRange($XY[0],1, $maxWidth?$maxWidth:2000);
277 $XY[1] = t3lib_div::intInRange($XY[1],1, $maxHeight?$maxHeight:2000);
278 $this->XY = $XY;
279 $this->w = $XY[0];
280 $this->h = $XY[1];
281 $this->OFFSET = t3lib_div::intExplode(',',$this->setup['offset']);
282
283 $this->setWorkArea($this->setup['workArea']); // this sets the workArea
284 $this->defaultWorkArea = $this->workArea; // this sets the default to the current;
285 }
286 }
287
288 /**
289 * Initiates the image file generation if ->setup is true and if the file did not exist already.
290 * Gets filename from fileName() and if file exists in typo3temp/ dir it will - of course - not be rendered again.
291 * Otherwise rendering means calling ->make(), then ->output(), then ->destroy()
292 *
293 * @return string The filename for the created GIF/PNG file. The filename will be prefixed "GB_"
294 * @see make(), fileName()
295 */
296 function gifBuild() {
297 if ($this->setup) {
298 $gifFileName = $this->fileName('GB/'); // Relative to PATH_site
299 if (!@file_exists($gifFileName)) { // File exists
300
301 // Create temporary directory if not done:
302 $this->createTempSubDir('GB/');
303
304 // Create file:
305 $this->make();
306 $this->output($gifFileName);
307 $this->destroy();
308 }
309 return $gifFileName;
310 }
311 }
312
313 /**
314 * The actual rendering of the image file.
315 * Basically sets the dimensions, the background color, the traverses the array of GIFBUILDER objects and finally setting the transparent color if defined.
316 * Creates a GDlib resource in $this->im and works on that
317 * Called by gifBuild()
318 *
319 * @return void
320 * @access private
321 * @see gifBuild()
322 * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=378&cHash=3c2ae4a1ab
323 */
324 function make() {
325 // Get trivial data
326 $XY = $this->XY;
327
328 // Gif-start
329 $this->im = imagecreate($XY[0],$XY[1]);
330 $this->w = $XY[0];
331 $this->h = $XY[1];
332
333 // backColor is set
334 $cols=$this->convertColor($this->setup['backColor']);
335 ImageColorAllocate($this->im, $cols[0],$cols[1],$cols[2]);
336
337 // Traverse the GIFBUILDER objects an render each one:
338 if (is_array($this->setup)) {
339 $sKeyArray=t3lib_TStemplate::sortedKeyList($this->setup);
340 foreach($sKeyArray as $theKey) {
341 $theValue=$this->setup[$theKey];
342
343 if (intval($theKey) && $conf=$this->setup[$theKey.'.']) {
344 switch($theValue) {
345 // Images
346 case 'IMAGE':
347 if ($conf['mask']) {
348 $this->maskImageOntoImage($this->im,$conf,$this->workArea);
349 } else {
350 $this->copyImageOntoImage($this->im,$conf,$this->workArea);
351 }
352 break;
353
354 // Text
355 case 'TEXT':
356 if (!$conf['hide']) {
357 if (is_array($conf['shadow.'])) {
358 $this->makeShadow($this->im,$conf['shadow.'],$this->workArea,$conf);
359 }
360 if (is_array($conf['emboss.'])) {
361 $this->makeEmboss($this->im,$conf['emboss.'],$this->workArea,$conf);
362 }
363 if (is_array($conf['outline.'])) {
364 $this->makeOutline($this->im,$conf['outline.'],$this->workArea,$conf);
365 }
366 $conf['imgMap']=1;
367 $this->makeText($this->im,$conf,$this->workArea);
368 }
369 break;
370
371 // Text effects:
372 case 'OUTLINE':
373 if ($this->setup[$conf['textObjNum']]=='TEXT' && $txtConf=$this->checkTextObj($this->setup[$conf['textObjNum'].'.'])) {
374 $this->makeOutline($this->im,$conf,$this->workArea,$txtConf);
375 }
376 break;
377 case 'EMBOSS':
378 if ($this->setup[$conf['textObjNum']]=='TEXT' && $txtConf=$this->checkTextObj($this->setup[$conf['textObjNum'].'.'])) {
379 $this->makeEmboss($this->im,$conf,$this->workArea,$txtConf);
380 }
381 break;
382 case 'SHADOW':
383 if ($this->setup[$conf['textObjNum']]=='TEXT' && $txtConf=$this->checkTextObj($this->setup[$conf['textObjNum'].'.'])) {
384 $this->makeShadow($this->im,$conf,$this->workArea,$txtConf);
385 }
386 break;
387
388 // Other
389 case 'BOX':
390 $this->makeBox($this->im,$conf,$this->workArea);
391 break;
392 case 'EFFECT':
393 $this->makeEffect($this->im,$conf);
394 break;
395 case 'ADJUST':
396 $this->adjust($this->im,$conf);
397 break;
398 case 'CROP':
399 $this->crop($this->im,$conf);
400 break;
401 case 'SCALE':
402 $this->scale($this->im,$conf);
403 break;
404 case 'WORKAREA':
405 if ($conf['set']) {
406 $this->setWorkArea($conf['set']); // this sets the workArea
407 }
408 if (isset($conf['clear'])) {
409 $this->workArea = $this->defaultWorkArea; // this sets the current to the default;
410 }
411 break;
412 }
413 }
414 }
415 }
416 // Auto transparent background is set
417 if ($this->setup['transparentBackground']) {
418 imagecolortransparent($this->im, imagecolorat($this->im, 0, 0));
419 }
420 // TransparentColors are set
421 if (is_array($this->setup['transparentColor_array'])) {
422 reset($this->setup['transparentColor_array']);
423 while(list(,$transparentColor)=each($this->setup['transparentColor_array'])) {
424 $cols=$this->convertColor($transparentColor);
425 if ($this->setup['transparentColor.']['closest']) {
426 $colIndex = ImageColorClosest ($this->im, $cols[0],$cols[1],$cols[2]);
427 } else {
428 $colIndex = ImageColorExact ($this->im, $cols[0],$cols[1],$cols[2]);
429 }
430 if ($colIndex > -1) {
431 ImageColorTransparent($this->im, $colIndex);
432 } else {
433 ImageColorTransparent($this->im, ImageColorAllocate($this->im, $cols[0],$cols[1],$cols[2]));
434 }
435 break; // Originally we thought of letting many colors be defined as transparent, but GDlib seems to accept only one definition. Therefore we break here. Maybe in the future this 'break' will be cancelled if a method of truly defining many transparent colors could be found.
436 }
437 }
438 }
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457 /*********************************************
458 *
459 * Various helper functions
460 *
461 ********************************************/
462
463
464 /**
465 * Initializing/Cleaning of TypoScript properties for TEXT GIFBUILDER objects
466 *
467 * 'cleans' TEXT-object; Checks fontfile and other vital setup
468 * Finds the title if its a 'variable' (instantiates a cObj and loads it with the ->data record)
469 * Performs caseshift if any.
470 *
471 * @param array GIFBUILDER object TypoScript properties
472 * @return array Modified $conf array IF the "text" property is not blank
473 * @access private
474 */
475 function checkTextObj($conf) {
476 $conf['fontFile']=$this->checkFile($conf['fontFile']);
477 if (!$conf['fontFile']){$conf['fontFile']='t3lib/fonts/arial.ttf';}
478 if (!$conf['iterations']){$conf['iterations'] = 1;}
479 if (!$conf['fontSize']){$conf['fontSize']=12;}
480 if ($conf['spacing'] || $conf['wordSpacing']) { // If any kind of spacing applys, we cannot use angles!!
481 $conf['angle']=0;
482 }
483 if (!isset($conf['antiAlias'])){$conf['antiAlias']=1;}
484 $cObj =t3lib_div::makeInstance('tslib_cObj');
485 $cObj->start($this->data);
486
487 $conf['text']=$cObj->stdWrap($conf['text'],$conf['text.']);
488 // Strip HTML
489 if (!$conf['doNotStripHTML']) {
490 $conf['text'] = strip_tags($conf['text']);
491 }
492 // Max length = 100
493 $tlen = intval($conf['textMaxLength']) ? intval($conf['textMaxLength']) : 100;
494 $conf['text'] = substr($conf['text'],0,$tlen);
495 if ((string)$conf['text']!='') {
496
497 // Char range map thingie:
498 $fontBaseName = basename($conf['fontFile']);
499 if (is_array($this->charRangeMap[$fontBaseName])) {
500
501 // Initialize splitRendering array:
502 if (!is_array($conf['splitRendering.'])) {
503 $conf['splitRendering.'] = array();
504 }
505
506 $cfgK = $this->charRangeMap[$fontBaseName]['cfgKey'];
507 if (!isset($conf['splitRendering.'][$cfgK])) { // Do not impose settings if a splitRendering object already exists:
508 // Set configuration:
509 $conf['splitRendering.'][$cfgK] = 'charRange';
510 $conf['splitRendering.'][$cfgK.'.'] = $this->charRangeMap[$fontBaseName]['charMapConfig'];
511
512 // multiplicator of fontsize:
513 if ($this->charRangeMap[$fontBaseName]['multiplicator']) {
514 $conf['splitRendering.'][$cfgK.'.']['fontSize'] = round($conf['fontSize'] * $this->charRangeMap[$fontBaseName]['multiplicator']);
515 }
516 // multiplicator of pixelSpace:
517 if ($this->charRangeMap[$fontBaseName]['pixelSpace']) {
518 $travKeys = array('xSpaceBefore','xSpaceAfter','ySpaceBefore','ySpaceAfter');
519 foreach($travKeys as $pxKey) {
520 if (isset($conf['splitRendering.'][$cfgK.'.'][$pxKey])) {
521 $conf['splitRendering.'][$cfgK.'.'][$pxKey] = round($conf['splitRendering.'][$cfgK.'.'][$pxKey] * ($conf['fontSize'] / $this->charRangeMap[$fontBaseName]['pixelSpace']));
522 }
523 }
524 }
525 }
526 }
527 if (is_array($conf['splitRendering.'])) {
528 foreach($conf['splitRendering.'] as $key => $value) {
529 if (is_array($conf['splitRendering.'][$key])) {
530 if (isset($conf['splitRendering.'][$key]['fontFile'])) {
531 $conf['splitRendering.'][$key]['fontFile'] = $this->checkFile($conf['splitRendering.'][$key]['fontFile']);
532 }
533 }
534 }
535 }
536
537 return $conf;
538 }
539 }
540
541 /**
542 * Calculation of offset using "splitCalc" and insertion of dimensions from other GIFBUILDER objects.
543 *
544 * Example:
545 * Input: 2+2, 2*3, 123, [10.w]
546 * Output: 4,6,123,45 (provided that the width of object in position 10 was 45 pixels wide)
547 *
548 * @param string The string to resolve/calculate the result of. The string is divided by a comma first and each resulting part is calculated into an integer.
549 * @return string The resolved string with each part (separated by comma) returned separated by comma
550 * @access private
551 */
552 function calcOffset($string) {
553 $numbers=explode(',',$string);
554 while(list($key,$val)=each($numbers)) {
555 $val = trim($val);
556 if ((string)$val==(string)intval($val)) {
557 $value[$key]=intval($val);
558 } else {
559 $parts= t3lib_div::splitCalc($val,'+-*/%');
560 $value[$key]=0;
561 reset($parts);
562 while(list(,$part)=each($parts)) {
563 $theVal = $part[1];
564 $sign = $part[0];
565 if ((string)intval($theVal)==(string)$theVal) {
566 $theVal = intval($theVal);
567 } elseif ('['.substr($theVal,1,-1).']'==$theVal) {
568 $objParts=explode('.',substr($theVal,1,-1));
569 $theVal=0;
570 if (isset($this->objBB[$objParts[0]])) {
571 if ($objParts[1]=='w') {$theVal=intval($this->objBB[$objParts[0]][0]);}
572 if ($objParts[1]=='h') {$theVal=intval($this->objBB[$objParts[0]][1]);}
573 }
574 } else {
575 $theVal =0;
576 }
577 if ($sign=='-') {$value[$key]-=$theVal;}
578 if ($sign=='+') {$value[$key]+=$theVal;}
579 if ($sign=='/') {if (intval($theVal)) $value[$key]/=intval($theVal);}
580 if ($sign=='*') {$value[$key]*=$theVal;}
581 if ($sign=='%') {if (intval($theVal)) $value[$key]%=intval($theVal);}
582 }
583 $value[$key]=intval($value[$key]);
584 }
585 }
586 $string = implode(',',$value);
587 return $string;
588 }
589
590 /**
591 * Returns an "imgResource" creating an instance of the tslib_cObj class and calling tslib_cObj::getImgResource
592 *
593 * @param string Filename value OR the string "GIFBUILDER", see documentation in TSref for the "datatype" called "imgResource"
594 * @param array TypoScript properties passed to the function. Either GIFBUILDER properties or imgResource properties, depending on the value of $file (whether that is "GIFBUILDER" or a file reference)
595 * @return array Returns an array with file information if an image was returned. Otherwise false.
596 * @access private
597 * @see tslib_cObj::getImgResource()
598 * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=315&cHash=63b593a934
599 * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=282&cHash=831a95115d
600 */
601 function getResource($file,$fileArray) {
602 $fileArray['ext']= $this->gifExtension;
603 $cObj =t3lib_div::makeInstance('tslib_cObj');
604 $cObj->start($this->data);
605 return $cObj->getImgResource($file,$fileArray);
606 }
607
608 /**
609 * Returns the reference to a "resource" in TypoScript.
610 *
611 * @param string The resource value.
612 * @return string Returns the relative filepath
613 * @access private
614 * @see t3lib_TStemplate::getFileName()
615 */
616 function checkFile($file) {
617 return $GLOBALS['TSFE']->tmpl->getFileName($file);
618 }
619
620 /**
621 * Calculates the GIFBUILDER output filename/path based on a serialized, hashed value of this->setup
622 *
623 * @param string Filename prefix, eg. "GB_"
624 * @return string The relative filepath (relative to PATH_site)
625 * @access private
626 */
627 function fileName($pre) {
628 return $this->tempPath.$pre.t3lib_div::shortMD5(serialize($this->setup)).'.'.$this->extension();
629 }
630
631 /**
632 * Returns the file extension used in the filename
633 *
634 * @return string Extension; "jpg" or "gif"/"png"
635 * @access private
636 */
637 function extension() {
638 switch(strtolower($this->setup['format'])) {
639 case 'jpg':
640 case 'jpeg':
641 return 'jpg';
642 break;
643 default:
644 return $this->gifExtension;
645 break;
646 }
647 }
648 }
649
650
651 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/class.tslib_gifbuilder.php']) {
652 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/class.tslib_gifbuilder.php']);
653 }
654
655 ?>