Updates mainly to import/export extension. Many smaller changes / additions. See...
[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 $combinedTextStrings = array(); // Contains all text strings used on this image
112 var $combinedFileNames = array(); // Contains all filenames (basename without extension) used on this image
113 var $data = Array(); // This is the array from which data->field: [key] is fetched. So this is the current record!
114 var $objBB = Array();
115 var $myClassName = 'gifbuilder';
116 var $charRangeMap=array();
117
118 /**
119 * 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.
120 * Modifies the ->setup, ->objBB internal arrays
121 * Should be called after the ->init() function which initializes the parent class functions/variables in general.
122 * 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.
123 *
124 * @param array TypoScript properties for the GIFBUILDER session. Stored internally in the variable ->setup
125 * @param array The current data record from tslib_cObj. Stored internally in the variable ->data
126 * @return void
127 * @see tslib_cObj::getImgResource(), tslib_gmenu::makeGifs(), tslib_gmenu::findLargestDims()
128 */
129 function start($conf,$data) {
130
131 if (is_array($conf)) {
132 $this->setup = $conf;
133 $this->data = $data;
134
135 // Initializing global Char Range Map
136 $this->charRangeMap = array();
137 if (is_array($GLOBALS['TSFE']->tmpl->setup['_GIFBUILDER.']['charRangeMap.'])) {
138 foreach($GLOBALS['TSFE']->tmpl->setup['_GIFBUILDER.']['charRangeMap.'] as $cRMcfgkey => $cRMcfg) {
139 if (is_array($cRMcfg)) {
140
141 // Initializing:
142 $cRMkey = $GLOBALS['TSFE']->tmpl->setup['_GIFBUILDER.']['charRangeMap.'][substr($cRMcfgkey,0,-1)];
143 $this->charRangeMap[$cRMkey] = array();
144 $this->charRangeMap[$cRMkey]['charMapConfig'] = $cRMcfg['charMapConfig.'];
145 $this->charRangeMap[$cRMkey]['cfgKey'] = substr($cRMcfgkey,0,-1);
146 $this->charRangeMap[$cRMkey]['multiplicator'] = (double)$cRMcfg['fontSizeMultiplicator'];
147 $this->charRangeMap[$cRMkey]['pixelSpace'] = intval($cRMcfg['pixelSpaceFontSizeRef']);
148 }
149 }
150 }
151
152 // Getting sorted list of TypoScript keys from setup.
153 $sKeyArray=t3lib_TStemplate::sortedKeyList($this->setup);
154
155 // Setting the background color, passing it through stdWrap
156 if ($conf['backColor.'] || $conf['backColor']) {
157 $cObj =t3lib_div::makeInstance('tslib_cObj');
158 $cObj->start($this->data);
159 $this->setup['backColor'] = trim($cObj->stdWrap($this->setup['backColor'], $this->setup['backColor.']));
160 }
161 if (!$this->setup['backColor']) {$this->setup['backColor']='white';}
162
163 // Transparent GIFs
164 // not working with reduceColors
165 // there's an option for IM: -transparent colors
166 if ($conf['transparentColor.'] || $conf['transparentColor']) {
167 $cObj =t3lib_div::makeInstance('tslib_cObj');
168 $cObj->start($this->data);
169 $this->setup['transparentColor_array'] = explode('|', trim($cObj->stdWrap($this->setup['transparentColor'], $this->setup['transparentColor.'])));
170 }
171
172 // Set default dimensions
173 if (!$this->setup['XY']) {$this->setup['XY']='120,50';}
174
175
176 // Checking TEXT and IMAGE objects for files. If any errors the objects are cleared.
177 // The Bounding Box for the objects is stored in an array
178 foreach($sKeyArray as $theKey) {
179 $theValue = $this->setup[$theKey];
180
181 if (intval($theKey) && $conf=$this->setup[$theKey.'.']) {
182 // Swipes through TEXT and IMAGE-objects
183 switch($theValue) {
184 case 'TEXT':
185 if ($this->setup[$theKey.'.'] = $this->checkTextObj($conf)) {
186
187 // Adjust font width if max size is set:
188 if ($this->setup[$theKey.'.']['maxWidth']) {
189 $this->setup[$theKey.'.']['fontSize'] = $this->fontResize($this->setup[$theKey.'.']); //RTF - this has to be done before calcBBox
190 }
191
192 // Calculate bounding box:
193 $txtInfo=$this->calcBBox($this->setup[$theKey.'.']);
194 $this->setup[$theKey.'.']['BBOX'] = $txtInfo;
195 $this->objBB[$theKey] = $txtInfo;
196 $this->setup[$theKey.'.']['imgMap'] = 0;
197 }
198 break;
199 case 'IMAGE':
200 $fileInfo = $this->getResource($conf['file'],$conf['file.']);
201 if ($fileInfo) {
202 $this->combinedFileNames[] = ereg_replace('\.[[:alnum:]]+$','',basename($fileInfo[3]));
203 $this->setup[$theKey.'.']['file'] = $fileInfo[3];
204 $this->setup[$theKey.'.']['BBOX'] = $fileInfo;
205 $this->objBB[$theKey] = $fileInfo;
206 if ($conf['mask']) {
207 $maskInfo = $this->getResource($conf['mask'],$conf['mask.']);
208 if ($maskInfo) {
209 $this->setup[$theKey.'.']['mask'] = $maskInfo[3];
210 } else {
211 $this->setup[$theKey.'.']['mask'] = '';
212 }
213 }
214 } else {
215 unset($this->setup[$theKey.'.']);
216 }
217 break;
218 }
219 // Checks if disabled is set... (this is also done in menu.php / imgmenu!!)
220 if ($conf['if.']) {
221 $cObj =t3lib_div::makeInstance('tslib_cObj');
222 $cObj->start($this->data);
223
224 if (!$cObj->checkIf($conf['if.'])) {
225 unset($this->setup[$theKey]);
226 unset($this->setup[$theKey.'.']);
227 }
228 }
229 }
230 }
231
232 // Calculate offsets on elements
233 $this->setup['XY'] = $this->calcOffset($this->setup['XY']);
234 $this->setup['offset'] = $this->calcOffset($this->setup['offset']);
235 $this->setup['workArea'] = $this->calcOffset($this->setup['workArea']);
236
237 foreach ($sKeyArray as $theKey) {
238 $theValue=$this->setup[$theKey];
239
240 if (intval($theKey) && $conf=$this->setup[$theKey.'.']) {
241 switch($theValue) {
242 case 'TEXT':
243 case 'IMAGE':
244 if ($this->setup[$theKey.'.']['offset']) {
245 $this->setup[$theKey.'.']['offset'] = $this->calcOffset($this->setup[$theKey.'.']['offset']);
246 }
247 break;
248 case 'BOX':
249 if ($this->setup[$theKey.'.']['dimensions']) {
250 $this->setup[$theKey.'.']['dimensions'] = $this->calcOffset($this->setup[$theKey.'.']['dimensions']);
251 }
252 break;
253 case 'WORKAREA':
254 if ($this->setup[$theKey.'.']['set']) {
255 $this->setup[$theKey.'.']['set'] = $this->calcOffset($this->setup[$theKey.'.']['set']);
256 }
257 break;
258 case 'CROP':
259 if ($this->setup[$theKey.'.']['crop']) {
260 $this->setup[$theKey.'.']['crop'] = $this->calcOffset($this->setup[$theKey.'.']['crop']);
261 }
262 break;
263 case 'SCALE':
264 if ($this->setup[$theKey.'.']['width']) {
265 $this->setup[$theKey.'.']['width'] = $this->calcOffset($this->setup[$theKey.'.']['width']);
266 }
267 if ($this->setup[$theKey.'.']['height']) {
268 $this->setup[$theKey.'.']['height'] = $this->calcOffset($this->setup[$theKey.'.']['height']);
269 }
270 break;
271 }
272 }
273 }
274 // Get trivial data
275 $XY = t3lib_div::intExplode(',',$this->setup['XY']);
276 $maxWidth = intval($this->setup['maxWidth']);
277 $maxHeight = intval($this->setup['maxHeight']);
278
279 $XY[0] = t3lib_div::intInRange($XY[0],1, $maxWidth?$maxWidth:2000);
280 $XY[1] = t3lib_div::intInRange($XY[1],1, $maxHeight?$maxHeight:2000);
281 $this->XY = $XY;
282 $this->w = $XY[0];
283 $this->h = $XY[1];
284 $this->OFFSET = t3lib_div::intExplode(',',$this->setup['offset']);
285
286 $this->setWorkArea($this->setup['workArea']); // this sets the workArea
287 $this->defaultWorkArea = $this->workArea; // this sets the default to the current;
288 }
289 }
290
291 /**
292 * Initiates the image file generation if ->setup is true and if the file did not exist already.
293 * Gets filename from fileName() and if file exists in typo3temp/ dir it will - of course - not be rendered again.
294 * Otherwise rendering means calling ->make(), then ->output(), then ->destroy()
295 *
296 * @return string The filename for the created GIF/PNG file. The filename will be prefixed "GB_"
297 * @see make(), fileName()
298 */
299 function gifBuild() {
300 if ($this->setup) {
301 $gifFileName = $this->fileName('GB/'); // Relative to PATH_site
302 if (!@file_exists($gifFileName)) { // File exists
303
304 // Create temporary directory if not done:
305 $this->createTempSubDir('GB/');
306
307 // Create file:
308 $this->make();
309 $this->output($gifFileName);
310 $this->destroy();
311 }
312 return $gifFileName;
313 }
314 }
315
316 /**
317 * The actual rendering of the image file.
318 * Basically sets the dimensions, the background color, the traverses the array of GIFBUILDER objects and finally setting the transparent color if defined.
319 * Creates a GDlib resource in $this->im and works on that
320 * Called by gifBuild()
321 *
322 * @return void
323 * @access private
324 * @see gifBuild()
325 * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=378&cHash=3c2ae4a1ab
326 */
327 function make() {
328 // Get trivial data
329 $XY = $this->XY;
330
331 // Gif-start
332 $this->im = imagecreate($XY[0],$XY[1]);
333 $this->w = $XY[0];
334 $this->h = $XY[1];
335
336 // backColor is set
337 $cols=$this->convertColor($this->setup['backColor']);
338 ImageColorAllocate($this->im, $cols[0],$cols[1],$cols[2]);
339
340 // Traverse the GIFBUILDER objects an render each one:
341 if (is_array($this->setup)) {
342 $sKeyArray=t3lib_TStemplate::sortedKeyList($this->setup);
343 foreach($sKeyArray as $theKey) {
344 $theValue=$this->setup[$theKey];
345
346 if (intval($theKey) && $conf=$this->setup[$theKey.'.']) {
347 switch($theValue) {
348 // Images
349 case 'IMAGE':
350 if ($conf['mask']) {
351 $this->maskImageOntoImage($this->im,$conf,$this->workArea);
352 } else {
353 $this->copyImageOntoImage($this->im,$conf,$this->workArea);
354 }
355 break;
356
357 // Text
358 case 'TEXT':
359 if (!$conf['hide']) {
360 if (is_array($conf['shadow.'])) {
361 $this->makeShadow($this->im,$conf['shadow.'],$this->workArea,$conf);
362 }
363 if (is_array($conf['emboss.'])) {
364 $this->makeEmboss($this->im,$conf['emboss.'],$this->workArea,$conf);
365 }
366 if (is_array($conf['outline.'])) {
367 $this->makeOutline($this->im,$conf['outline.'],$this->workArea,$conf);
368 }
369 $conf['imgMap']=1;
370 $this->makeText($this->im,$conf,$this->workArea);
371 }
372 break;
373
374 // Text effects:
375 case 'OUTLINE':
376 if ($this->setup[$conf['textObjNum']]=='TEXT' && $txtConf=$this->checkTextObj($this->setup[$conf['textObjNum'].'.'])) {
377 $this->makeOutline($this->im,$conf,$this->workArea,$txtConf);
378 }
379 break;
380 case 'EMBOSS':
381 if ($this->setup[$conf['textObjNum']]=='TEXT' && $txtConf=$this->checkTextObj($this->setup[$conf['textObjNum'].'.'])) {
382 $this->makeEmboss($this->im,$conf,$this->workArea,$txtConf);
383 }
384 break;
385 case 'SHADOW':
386 if ($this->setup[$conf['textObjNum']]=='TEXT' && $txtConf=$this->checkTextObj($this->setup[$conf['textObjNum'].'.'])) {
387 $this->makeShadow($this->im,$conf,$this->workArea,$txtConf);
388 }
389 break;
390
391 // Other
392 case 'BOX':
393 $this->makeBox($this->im,$conf,$this->workArea);
394 break;
395 case 'EFFECT':
396 $this->makeEffect($this->im,$conf);
397 break;
398 case 'ADJUST':
399 $this->adjust($this->im,$conf);
400 break;
401 case 'CROP':
402 $this->crop($this->im,$conf);
403 break;
404 case 'SCALE':
405 $this->scale($this->im,$conf);
406 break;
407 case 'WORKAREA':
408 if ($conf['set']) {
409 $this->setWorkArea($conf['set']); // this sets the workArea
410 }
411 if (isset($conf['clear'])) {
412 $this->workArea = $this->defaultWorkArea; // this sets the current to the default;
413 }
414 break;
415 }
416 }
417 }
418 }
419 // Auto transparent background is set
420 if ($this->setup['transparentBackground']) {
421 imagecolortransparent($this->im, imagecolorat($this->im, 0, 0));
422 }
423 // TransparentColors are set
424 if (is_array($this->setup['transparentColor_array'])) {
425 reset($this->setup['transparentColor_array']);
426 while(list(,$transparentColor)=each($this->setup['transparentColor_array'])) {
427 $cols=$this->convertColor($transparentColor);
428 if ($this->setup['transparentColor.']['closest']) {
429 $colIndex = ImageColorClosest ($this->im, $cols[0],$cols[1],$cols[2]);
430 } else {
431 $colIndex = ImageColorExact ($this->im, $cols[0],$cols[1],$cols[2]);
432 }
433 if ($colIndex > -1) {
434 ImageColorTransparent($this->im, $colIndex);
435 } else {
436 ImageColorTransparent($this->im, ImageColorAllocate($this->im, $cols[0],$cols[1],$cols[2]));
437 }
438 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.
439 }
440 }
441 }
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460 /*********************************************
461 *
462 * Various helper functions
463 *
464 ********************************************/
465
466
467 /**
468 * Initializing/Cleaning of TypoScript properties for TEXT GIFBUILDER objects
469 *
470 * 'cleans' TEXT-object; Checks fontfile and other vital setup
471 * Finds the title if its a 'variable' (instantiates a cObj and loads it with the ->data record)
472 * Performs caseshift if any.
473 *
474 * @param array GIFBUILDER object TypoScript properties
475 * @return array Modified $conf array IF the "text" property is not blank
476 * @access private
477 */
478 function checkTextObj($conf) {
479 $conf['fontFile']=$this->checkFile($conf['fontFile']);
480 if (!$conf['fontFile']){$conf['fontFile']='t3lib/fonts/arial.ttf';}
481 if (!$conf['iterations']){$conf['iterations'] = 1;}
482 if (!$conf['fontSize']){$conf['fontSize']=12;}
483 if ($conf['spacing'] || $conf['wordSpacing']) { // If any kind of spacing applys, we cannot use angles!!
484 $conf['angle']=0;
485 }
486 if (!isset($conf['antiAlias'])){$conf['antiAlias']=1;}
487 $cObj =t3lib_div::makeInstance('tslib_cObj');
488 $cObj->start($this->data);
489
490 $conf['text']=$cObj->stdWrap($conf['text'],$conf['text.']);
491 // Strip HTML
492 if (!$conf['doNotStripHTML']) {
493 $conf['text'] = strip_tags($conf['text']);
494 }
495 $this->combinedTextStrings[] = strip_tags($conf['text']);
496
497 // Max length = 100
498 $tlen = intval($conf['textMaxLength']) ? intval($conf['textMaxLength']) : 100;
499 $conf['text'] = substr($conf['text'],0,$tlen);
500 if ((string)$conf['text']!='') {
501
502 // Char range map thingie:
503 $fontBaseName = basename($conf['fontFile']);
504 if (is_array($this->charRangeMap[$fontBaseName])) {
505
506 // Initialize splitRendering array:
507 if (!is_array($conf['splitRendering.'])) {
508 $conf['splitRendering.'] = array();
509 }
510
511 $cfgK = $this->charRangeMap[$fontBaseName]['cfgKey'];
512 if (!isset($conf['splitRendering.'][$cfgK])) { // Do not impose settings if a splitRendering object already exists:
513 // Set configuration:
514 $conf['splitRendering.'][$cfgK] = 'charRange';
515 $conf['splitRendering.'][$cfgK.'.'] = $this->charRangeMap[$fontBaseName]['charMapConfig'];
516
517 // multiplicator of fontsize:
518 if ($this->charRangeMap[$fontBaseName]['multiplicator']) {
519 $conf['splitRendering.'][$cfgK.'.']['fontSize'] = round($conf['fontSize'] * $this->charRangeMap[$fontBaseName]['multiplicator']);
520 }
521 // multiplicator of pixelSpace:
522 if ($this->charRangeMap[$fontBaseName]['pixelSpace']) {
523 $travKeys = array('xSpaceBefore','xSpaceAfter','ySpaceBefore','ySpaceAfter');
524 foreach($travKeys as $pxKey) {
525 if (isset($conf['splitRendering.'][$cfgK.'.'][$pxKey])) {
526 $conf['splitRendering.'][$cfgK.'.'][$pxKey] = round($conf['splitRendering.'][$cfgK.'.'][$pxKey] * ($conf['fontSize'] / $this->charRangeMap[$fontBaseName]['pixelSpace']));
527 }
528 }
529 }
530 }
531 }
532 if (is_array($conf['splitRendering.'])) {
533 foreach($conf['splitRendering.'] as $key => $value) {
534 if (is_array($conf['splitRendering.'][$key])) {
535 if (isset($conf['splitRendering.'][$key]['fontFile'])) {
536 $conf['splitRendering.'][$key]['fontFile'] = $this->checkFile($conf['splitRendering.'][$key]['fontFile']);
537 }
538 }
539 }
540 }
541
542 return $conf;
543 }
544 }
545
546 /**
547 * Calculation of offset using "splitCalc" and insertion of dimensions from other GIFBUILDER objects.
548 *
549 * Example:
550 * Input: 2+2, 2*3, 123, [10.w]
551 * Output: 4,6,123,45 (provided that the width of object in position 10 was 45 pixels wide)
552 *
553 * @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.
554 * @return string The resolved string with each part (separated by comma) returned separated by comma
555 * @access private
556 */
557 function calcOffset($string) {
558 $numbers=explode(',',$string);
559 while(list($key,$val)=each($numbers)) {
560 $val = trim($val);
561 if ((string)$val==(string)intval($val)) {
562 $value[$key]=intval($val);
563 } else {
564 $parts= t3lib_div::splitCalc($val,'+-*/%');
565 $value[$key]=0;
566 reset($parts);
567 while(list(,$part)=each($parts)) {
568 $theVal = $part[1];
569 $sign = $part[0];
570 if ((string)intval($theVal)==(string)$theVal) {
571 $theVal = intval($theVal);
572 } elseif ('['.substr($theVal,1,-1).']'==$theVal) {
573 $objParts=explode('.',substr($theVal,1,-1));
574 $theVal=0;
575 if (isset($this->objBB[$objParts[0]])) {
576 if ($objParts[1]=='w') {$theVal=intval($this->objBB[$objParts[0]][0]);}
577 if ($objParts[1]=='h') {$theVal=intval($this->objBB[$objParts[0]][1]);}
578 }
579 } else {
580 $theVal =0;
581 }
582 if ($sign=='-') {$value[$key]-=$theVal;}
583 if ($sign=='+') {$value[$key]+=$theVal;}
584 if ($sign=='/') {if (intval($theVal)) $value[$key]/=intval($theVal);}
585 if ($sign=='*') {$value[$key]*=$theVal;}
586 if ($sign=='%') {if (intval($theVal)) $value[$key]%=intval($theVal);}
587 }
588 $value[$key]=intval($value[$key]);
589 }
590 }
591 $string = implode(',',$value);
592 return $string;
593 }
594
595 /**
596 * Returns an "imgResource" creating an instance of the tslib_cObj class and calling tslib_cObj::getImgResource
597 *
598 * @param string Filename value OR the string "GIFBUILDER", see documentation in TSref for the "datatype" called "imgResource"
599 * @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)
600 * @return array Returns an array with file information if an image was returned. Otherwise false.
601 * @access private
602 * @see tslib_cObj::getImgResource()
603 * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=315&cHash=63b593a934
604 * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=282&cHash=831a95115d
605 */
606 function getResource($file,$fileArray) {
607 $fileArray['ext']= $this->gifExtension;
608 $cObj =t3lib_div::makeInstance('tslib_cObj');
609 $cObj->start($this->data);
610 return $cObj->getImgResource($file,$fileArray);
611 }
612
613 /**
614 * Returns the reference to a "resource" in TypoScript.
615 *
616 * @param string The resource value.
617 * @return string Returns the relative filepath
618 * @access private
619 * @see t3lib_TStemplate::getFileName()
620 */
621 function checkFile($file) {
622 return $GLOBALS['TSFE']->tmpl->getFileName($file);
623 }
624
625 /**
626 * Calculates the GIFBUILDER output filename/path based on a serialized, hashed value of this->setup
627 *
628 * @param string Filename prefix, eg. "GB_"
629 * @return string The relative filepath (relative to PATH_site)
630 * @access private
631 */
632 function fileName($pre) {
633
634 // WARNING: In PHP5 I discovered that rendering with freetype of Japanese letters was totally corrupt. Not only the wrong glyphs are printed but also some memory stack overflow resulted in strange additional chars - and finally the reason for this investigation: The Bounding box data was changing all the time resulting in new images being generated all the time. With PHP4 it works fine.
635 return $this->tempPath.
636 $pre.
637 ($GLOBALS['TSFE']->config['config']['meaningfulTempFilePrefix'] ? $GLOBALS['TSFE']->fileNameASCIIPrefix(implode('_',array_merge($this->combinedTextStrings,$this->combinedFileNames)),intval($GLOBALS['TSFE']->config['config']['meaningfulTempFilePrefix']),'_') : '').
638 t3lib_div::shortMD5(serialize($this->setup)).
639 '.'.$this->extension();
640 }
641
642 /**
643 * Returns the file extension used in the filename
644 *
645 * @return string Extension; "jpg" or "gif"/"png"
646 * @access private
647 */
648 function extension() {
649 switch(strtolower($this->setup['format'])) {
650 case 'jpg':
651 case 'jpeg':
652 return 'jpg';
653 break;
654 default:
655 return $this->gifExtension;
656 break;
657 }
658 }
659 }
660
661
662 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/class.tslib_gifbuilder.php']) {
663 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/class.tslib_gifbuilder.php']);
664 }
665
666 ?>