See my changelog comment from 2004-06-28 + locallang-XML changes (done to german...
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_stdgraphic.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2004 Kasper Skaarhoj (kasper@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 * Standard graphical functions
29 *
30 * $Id$
31 * Revised for TYPO3 3.6 July/2003 by Kasper Skaarhoj
32 *
33 * @author Kasper Skaarhoj <kasper@typo3.com>
34 */
35 /**
36 * [CLASS/FUNCTION INDEX of SCRIPT]
37 *
38 *
39 *
40 * 143: class t3lib_stdGraphic
41 * 218: function init()
42 *
43 * SECTION: Layering images / "IMAGE" GIFBUILDER object
44 * 317: function maskImageOntoImage(&$im,$conf,$workArea)
45 * 377: function copyImageOntoImage(&$im,$conf,$workArea)
46 * 399: function copyGifOntoGif(&$im,$cpImg,$conf,$workArea)
47 * 478: function imagecopyresized(&$im, $cpImg, $Xstart, $Ystart, $cpImgCutX, $cpImgCutY, $w, $h, $w, $h)
48 *
49 * SECTION: Text / "TEXT" GIFBUILDER object
50 * 527: function makeText(&$im,$conf,$workArea)
51 * 643: function txtPosition($conf,$workArea,$BB)
52 * 697: function calcBBox($conf)
53 * 766: function addToMap($cords,$conf)
54 * 787: function calcTextCordsForMap($cords,$offset, $conf)
55 * 820: function SpacedImageTTFText(&$im, $fontSize, $angle, $x, $y, $Fcolor, $fontFile, $text, $spacing, $wordSpacing)
56 * 853: function fontResize($conf)
57 *
58 * SECTION: Other GIFBUILDER objects related to TEXT
59 * 915: function makeOutline(&$im,$conf,$workArea,$txtConf)
60 * 944: function circleOffset($distance, $iterations)
61 * 968: function makeEmboss(&$im,$conf,$workArea,$txtConf)
62 * 990: function makeShadow(&$im,$conf,$workArea,$txtConf)
63 *
64 * SECTION: Other GIFBUILDER objects
65 * 1120: function makeBox(&$im,$conf,$workArea)
66 * 1139: function makeEffect(&$im, $conf)
67 * 1154: function IMparams($setup)
68 * 1237: function adjust(&$im, $conf)
69 * 1269: function crop(&$im,$conf)
70 * 1299: function scale(&$im,$conf)
71 * 1331: function setWorkArea($workArea)
72 *
73 * SECTION: Adjustment functions
74 * 1372: function autolevels(&$im)
75 * 1403: function outputLevels(&$im,$low,$high,$swap='')
76 * 1435: function inputLevels(&$im,$low,$high,$swap='')
77 * 1466: function reduceColors(&$im,$limit, $cols)
78 *
79 * SECTION: GIFBUILDER Helper functions
80 * 1504: function prependAbsolutePath($fontFile)
81 * 1518: function v5_sharpen($factor)
82 * 1537: function v5_blur($factor)
83 * 1554: function randomName()
84 * 1566: function applyOffset($cords,$OFFSET)
85 * 1579: function convertColor($string)
86 * 1629: function recodeString($string)
87 * 1650: function singleChars($theText)
88 * 1673: function objPosition($conf,$workArea,$BB)
89 *
90 * SECTION: Scaling, Dimensions of images
91 * 1752: function imageMagickConvert($imagefile,$newExt='',$w='',$h='',$params='',$frame='',$options='',$mustCreate=0)
92 * 1835: function getImageDimensions($imageFile)
93 * 1863: function cacheImageDimensions($identifyResult)
94 * 1895: function getCachedImageDimensions($imageFile)
95 * 1930: function getImageScale($info,$w,$h,$options)
96 * 2018: function file_exists_typo3temp_file($output,$orig='')
97 *
98 * SECTION: ImageMagick API functions
99 * 2079: function imageMagickIdentify($imagefile)
100 * 2112: function imageMagickExec($input,$output,$params)
101 * 2130: function combineExec($input,$overlay,$mask,$output)
102 * 2145: function wrapFileName($inputName)
103 *
104 * SECTION: Various IO functions
105 * 2186: function checkFile($file)
106 * 2201: function applyImageMagickToPHPGif(&$im, $command)
107 * 2227: function gif_or_jpg($type,$w,$h)
108 * 2244: function output($file)
109 * 2288: function destroy()
110 * 2298: function imgTag ($imgInfo)
111 * 2310: function ImageGif($destImg, $theImage)
112 * 2327: function imageCreateFromGif($sourceImg)
113 *
114 * TOTAL FUNCTIONS: 54
115 * (This index is automatically created/updated by the extension "extdeveval")
116 *
117 */
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134 /**
135 * Class contains a bunch of cool functions for manipulating graphics with GDlib/Freetype and ImageMagick
136 * VERY OFTEN used with gifbuilder that extends this class and provides a TypoScript API to using these functions
137 *
138 * @author Kasper Skaarhoj <kasper@typo3.com>
139 * @package TYPO3
140 * @subpackage t3lib
141 * @see tslib_gifBuilder
142 */
143 class t3lib_stdGraphic {
144
145 // Internal configuration, set in init()
146 var $combineScript = 'combine'; // The ImageMagick filename used for combining two images. This name changed during the versions.
147 var $noFramePrepended=0; // If set, there is no frame pointer prepended to the filenames.
148 var $GD2=0; // Set, if the GDlib used is version 2.
149 var $imagecopyresized_fix=0; // If set, imagecopyresized will not be called directly. For GD2 (some PHP installs?)
150 var $gifExtension = 'gif'; // This should be changed to 'png' if you want this class to read/make PNG-files instead!
151 var $TTFLocaleConv = ''; // Used to recode input to TTF-functions for other charsets.
152 var $enable_typo3temp_db_tracking = 0; // If set, then all files in typo3temp will be logged in a database table. In addition to being a log of the files with original filenames, it also serves to secure that the same image is not rendered simultaneously by two different processes.
153 var $imageMagickPath = ''; // path to imageMagick, eg: /usr/lib/
154 var $imageFileExt = 'gif,jpg,jpeg,png,tif,bmp,tga,pcx,ai,pdf'; // Commalist of file extensions perceived as images by TYPO3. List should be set to 'gif,png,jpeg,jpg' if IM is not available. Lowercase and no spaces between!
155 var $webImageExt = 'gif,jpg,jpeg,png'; // Commalist of web image extensions (can be shown by a webbrowser)
156 var $maskNegate = ''; // Will be ' -negate' if ImageMagick ver 5.2+. See init();
157 var $NO_IM_EFFECTS = '';
158 var $cmds = Array (
159 'jpg' => '-colorspace RGB -sharpen 50 -quality 60',
160 'jpeg' => '-colorspace RGB -sharpen 50 -quality 60',
161 'gif' => '-colors 64',
162 'png' => '-colors 64'
163 );
164 var $NO_IMAGE_MAGICK = '';
165 var $V5_EFFECTS = 0;
166 var $mayScaleUp = 1;
167
168 // Variables for testing, alternative usage etc.
169 var $filenamePrefix=''; // Filename prefix for images scaled in imageMagickConvert()
170 var $imageMagickConvert_forceFileNameBody=''; // Forcing the output filename of imageMagickConvert() to this value. However after calling imageMagickConvert() it will be set blank again.
171 var $dontCheckForExistingTempFile = 0; // This flag should always be false. If set true, imageMagickConvert will always write a new file to the tempdir! Used for debugging.
172 var $dontCompress=0; // Prevents imageMagickConvert() from compressing the gif-files with t3lib_div::gif_compress()
173 var $dontUnlinkTempFiles=0; // For debugging ONLY!
174 var $alternativeOutputKey=''; // For debugging only. Filenames will not be based on mtime and only filename (not path) will be used. This key is also included in the hash of the filename...
175
176 // Internal:
177 var $IM_commands = Array(); // All ImageMagick commands executed is stored in this array for tracking. Used by the Install Tools Image section
178 var $workArea = Array();
179
180 // Constants:
181 var $tempPath = 'typo3temp/'; // The temp-directory where to store the files. Relative to PATH_site.
182 var $scalecmd = '-geometry'; // ImageMagick scaling command; "-geometry" eller "-sample". Used in makeText() and imageMagickConvert()
183 var $im5fx_blurSteps='1x2,2x2,3x2,4x3,5x3,5x4,6x4,7x5,8x5,9x5'; // Used by v5_blur() to simulate 10 continuous steps of blurring
184 var $im5fx_sharpenSteps='1x2,2x2,3x2,2x3,3x3,4x3,3x4,4x4,4x5,5x5'; // Used by v5_sharpen() to simulate 10 continuous steps of sharpening.
185 var $pixelLimitGif = 10000; // This is the limit for the number of pixels in an image before it will be rendered as JPG instead of GIF/PNG
186 var $colMap = Array ( // Array mapping HTML color names to RGB values.
187 'aqua' => Array(0,255,255),
188 'black' => Array(0,0,0),
189 'blue' => Array(0,0,255),
190 'fuchsia' => Array(255,0,255),
191 'gray' => Array(128,128,128),
192 'green' => Array(0,128,0),
193 'lime' => Array(0,255,0),
194 'maroon' => Array(128,0,0),
195 'navy' => Array(0,0,128),
196 'olive' => Array(128,128,0),
197 'purple' => Array(128,0,128),
198 'red' => Array(255,0,0),
199 'silver' => Array(192,192,192),
200 'teal' => Array(0,128,128),
201 'yellow' => Array(255,255,0),
202 'white' => Array(255,255,255)
203 );
204
205 // Charset conversion object:
206 var $csConvObj;
207 var $nativeCharset=''; // Is set to the native character set of the input strings.
208
209
210
211
212
213 /**
214 * Init function. Must always call this when using the class.
215 * This function will read the configuration information from $GLOBALS['TYPO3_CONF_VARS']['GFX'] can set some values in internal variables.
216 *
217 * @return void
218 */
219 function init() {
220 $gfxConf = $GLOBALS['TYPO3_CONF_VARS']['GFX'];
221
222 if ($gfxConf['im_combine_filename']) $this->combineScript=$gfxConf['im_combine_filename'];
223 if ($gfxConf['im_noFramePrepended']) $this->noFramePrepended=1;
224
225 if ($gfxConf['gdlib_2']) {
226 $this->GD2 = 1;
227 $this->imagecopyresized_fix = $gfxConf['gdlib_2']==='no_imagecopyresized_fix' ? 0 : 1;
228 }
229 if ($gfxConf['gdlib_png']) {
230 $this->gifExtension='png';
231 }
232 if ($gfxConf['TTFLocaleConv']) {
233 $this->TTFLocaleConv = $gfxConf['TTFLocaleConv'];
234 }
235 if ($gfxConf['enable_typo3temp_db_tracking']) {
236 $this->enable_typo3temp_db_tracking = $gfxConf['enable_typo3temp_db_tracking'];
237 }
238
239 $this->imageMagickPath = $gfxConf['im_path'];
240 $this->imageFileExt = $gfxConf['imagefile_ext'];
241
242 // This should be set if ImageMagick ver. 5+ is used.
243 if ($gfxConf['im_negate_mask']) {
244 // Boolean. Indicates if the mask images should be inverted first.
245 // This depends of the ImageMagick version. Below ver. 5.1 this should be false.
246 // Above ImageMagick version 5.2+ it should be true.
247 // Just set the flag if the masks works opposite the intension!
248 $this->maskNegate = ' -negate';
249 }
250 if ($gfxConf['im_no_effects']) {
251 // Boolean. This is necessary if using ImageMagick 5+.
252 // Approved version for using effects is version 4.2.9.
253 // Effects in Imagemagick 5+ tends to render very slowly!!
254 // - therefore must be disabled in order not to perform sharpen, blurring and such.
255 $this->NO_IM_EFFECTS = 1;
256
257 $this->cmds['jpg'] = '-colorspace RGB -quality 60';
258 $this->cmds['jpeg'] = '-colorspace RGB -quality 60';
259 }
260 // ... but if 'im_v5effects' is set, dont care about 'im_no_effects'
261 if ($gfxConf['im_v5effects']) {
262 $this->NO_IM_EFFECTS = 0;
263 $this->V5_EFFECTS = 1;
264
265 if ($gfxConf['im_v5effects']>0) {
266 $this->cmds['jpg'] = '-colorspace RGB -quality 60'.$this->v5_sharpen(10);
267 $this->cmds['jpeg'] = '-colorspace RGB -quality 60'.$this->v5_sharpen(10);
268 }
269 }
270
271 if (!$gfxConf['im']) {
272 $this->NO_IMAGE_MAGICK = 1;
273 }
274 // Secures that images are not scaled up.
275 if ($gfxConf['im_noScaleUp']) {
276 $this->mayScaleUp=0;
277 }
278
279 if (TYPO3_MODE=='FE') {
280 $this->csConvObj = &$GLOBALS['TSFE']->csConvObj;
281 } else { // BE assumed:
282 $this->csConvObj = &$GLOBALS['LANG']->csConvObj;
283 }
284 $this->nativeCharset = $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'];
285 }
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302 /*************************************************
303 *
304 * Layering images / "IMAGE" GIFBUILDER object
305 *
306 *************************************************/
307
308 /**
309 * Implements the "IMAGE" GIFBUILDER object, when the "mask" property is true.
310 * It reads the two images defined by $conf['file'] and $conf['mask'] and copies the $conf['file'] onto the input image pointer image using the $conf['mask'] as a grayscale mask
311 * The operation involves ImageMagick for combining.
312 *
313 * @param pointer GDlib image pointer
314 * @param array TypoScript array with configuration for the GIFBUILDER object.
315 * @param array The current working area coordinates.
316 * @return void
317 * @see tslib_gifBuilder::make()
318 */
319 function maskImageOntoImage(&$im,$conf,$workArea) {
320 if ($conf['file'] && $conf['mask']) {
321 $BBimage = $this->imageMagickConvert($conf['file'],$this->gifExtension,'','','','','');
322 $BBmask = $this->imageMagickConvert($conf['mask'],$this->gifExtension,'','','','','');
323 if ($BBimage && $BBmask) {
324 $w = imagesx($im);
325 $h = imagesy($im);
326 $tmpStr = $this->randomName();
327 $theImage = $tmpStr.'_img.'.$this->gifExtension;
328 $theDest = $tmpStr.'_dest.'.$this->gifExtension;
329 $theMask = $tmpStr.'_mask.'.$this->gifExtension;
330 $theMask2 = $tmpStr.'_mask2.'.trim($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_mask_temp_ext_noloss']);
331 // prepare overlay image
332 $cpImg = $this->imageCreateFromGif($BBimage[3]);
333 $destImg = imagecreate($w,$h);
334 ImageColorAllocate($destImg, 0,0,0);
335 $this->copyGifOntoGif($destImg,$cpImg,$conf,$workArea);
336 $this->ImageGif($destImg, $theImage);
337 imageDestroy($cpImg);
338 imageDestroy($destImg);
339 // prepare mask image
340 $cpImg = $this->imageCreateFromGif($BBmask[3]);
341 $destImg = imagecreate($w,$h);
342 ImageColorAllocate($destImg, 0,0,0);
343 $this->copyGifOntoGif($destImg,$cpImg,$conf,$workArea);
344 $this->ImageGif($destImg, $theMask);
345 imageDestroy($cpImg);
346 imageDestroy($destImg);
347 // treat the mask
348 $this->imageMagickExec($theMask,$theMask2,'-colorspace GRAY'.$this->maskNegate);
349 // mask the images
350 $this->ImageGif($im, $theDest);
351
352 $this->combineExec($theDest,$theImage,$theMask2,$theDest);
353
354 $backIm = $this->imageCreateFromGif($theDest); // The main image is loaded again...
355 if ($backIm) { // ... and if nothing went wrong we load it onto the old one.
356 ImageColorTransparent($backIm,-1);
357 $im = $backIm;
358 }
359 // unlink files from process
360 if (!$this->dontUnlinkTempFiles) {
361 unlink($theDest);
362 unlink($theImage);
363 unlink($theMask);
364 unlink($theMask2);
365 }
366 }
367 }
368 }
369
370 /**
371 * Implements the "IMAGE" GIFBUILDER object, when the "mask" property is false (using only $conf['file'])
372 *
373 * @param pointer GDlib image pointer
374 * @param array TypoScript array with configuration for the GIFBUILDER object.
375 * @param array The current working area coordinates.
376 * @return void
377 * @see tslib_gifBuilder::make(), maskImageOntoImage()
378 */
379 function copyImageOntoImage(&$im,$conf,$workArea) {
380 if ($conf['file']) {
381 if ($conf['BBOX'][2]!=$this->gifExtension) {
382 $conf['BBOX']=$this->imageMagickConvert($conf['BBOX'][3],$this->gifExtension,'','','','','');
383 $conf['file']=$conf['BBOX'][3];
384 }
385 $cpImg = $this->imageCreateFromGif($conf['file']);
386 $this->copyGifOntoGif($im,$cpImg,$conf,$workArea);
387 imageDestroy($cpImg);
388 }
389 }
390
391 /**
392 * Copies two GDlib image pointers onto each other, using TypoScript configuration from $conf and the input $workArea definition.
393 *
394 * @param pointer GDlib image pointer, destination (bottom image)
395 * @param pointer GDlib image pointer, source (top image)
396 * @param array TypoScript array with the properties for the IMAGE GIFBUILDER object. Only used for the "tile" property value.
397 * @param array Work area
398 * @return void Works on the $im image pointer
399 * @access private
400 */
401 function copyGifOntoGif(&$im,$cpImg,$conf,$workArea) {
402 $cpW = imagesx($cpImg);
403 $cpH = imagesy($cpImg);
404 $tile = t3lib_div::intExplode(',',$conf['tile']);
405 $tile[0] = t3lib_div::intInRange($tile[0],1,20);
406 $tile[1] = t3lib_div::intInRange($tile[1],1,20);
407 $cpOff = $this->objPosition($conf,$workArea,Array($cpW*$tile[0],$cpH*$tile[1]));
408
409 for ($xt=0;$xt<$tile[0];$xt++) {
410 $Xstart=$cpOff[0]+$cpW*$xt;
411 if ($Xstart+$cpW > $workArea[0]) { // if this image is inside of the workArea, then go on
412 // X:
413 if ($Xstart < $workArea[0]) {
414 $cpImgCutX = $workArea[0]-$Xstart;
415 $Xstart = $workArea[0];
416 } else {
417 $cpImgCutX = 0;
418 }
419 $w = $cpW-$cpImgCutX;
420 if ($Xstart > $workArea[0]+$workArea[2]-$w) {
421 $w = $workArea[0]+$workArea[2]-$Xstart;
422 }
423 if ($Xstart < $workArea[0]+$workArea[2]) { // if this image is inside of the workArea, then go on
424 // Y:
425 for ($yt=0;$yt<$tile[1];$yt++) {
426 $Ystart=$cpOff[1]+$cpH*$yt;
427 if ($Ystart+$cpH > $workArea[1]) { // if this image is inside of the workArea, then go on
428 if ($Ystart < $workArea[1]) {
429 $cpImgCutY = $workArea[1]-$Ystart;
430 $Ystart = $workArea[1];
431 } else {
432 $cpImgCutY = 0;
433 }
434 $h = $cpH-$cpImgCutY;
435 if ($Ystart > $workArea[1]+$workArea[3]-$h) {
436 $h = $workArea[1]+$workArea[3]-$Ystart;
437 }
438 if ($Ystart < $workArea[1]+$workArea[3]) { // if this image is inside of the workArea, then go on
439 $this->imagecopyresized($im, $cpImg, $Xstart, $Ystart, $cpImgCutX, $cpImgCutY, $w, $h, $w, $h);
440 }
441 }
442 } // Y:
443 }
444 }
445 }
446 }
447
448 /**
449 * Alternative function for using the similar PHP function imagecopyresized(). Used for GD2 only.
450 *
451 * OK, the reason for this stupid fix is the following story:
452 * GD1.x was capable of copying two images together and combining their palettes! GD2 is apparently not.
453 * With GD2 only the palette of the dest-image is used which mostly results in totally black images when trying to
454 * copy a color-ful image onto the destination.
455 * The GD2-fix is to
456 * 1) Create a blank TRUE-COLOR image
457 * 2) Copy the destination image onto that one
458 * 3) Then do the actual operation; Copying the source (top image) onto that
459 * 4) ... and return the result pointer.
460 * 5) Reduce colors (if we do not, the result may become strange!)
461 * It works, but the resulting images is now a true-color PNG which may be very large.
462 * So, why not use 'imagetruecolortopalette ($im, TRUE, 256)' - well because it does NOT WORK! So simple is that.
463 *
464 * For parameters, see PHP function "imagecopyresized()"
465 *
466 * @param pointer see PHP function "imagecopyresized()"
467 * @param pointer see PHP function "imagecopyresized()"
468 * @param integer see PHP function "imagecopyresized()"
469 * @param integer see PHP function "imagecopyresized()"
470 * @param integer see PHP function "imagecopyresized()"
471 * @param integer see PHP function "imagecopyresized()"
472 * @param integer see PHP function "imagecopyresized()"
473 * @param integer see PHP function "imagecopyresized()"
474 * @param integer see PHP function "imagecopyresized()"
475 * @param integer see PHP function "imagecopyresized()"
476 * @return void
477 * @access private
478 * @see t3lib_iconWorks::imagecopyresized()
479 */
480 function imagecopyresized(&$im, $cpImg, $Xstart, $Ystart, $cpImgCutX, $cpImgCutY, $w, $h, $w, $h) {
481 if ($this->imagecopyresized_fix) {
482 $im_base = imagecreatetruecolor(imagesx($im), imagesy($im)); // Make true color image
483 imagecopyresized($im_base, $im, 0,0,0,0, imagesx($im),imagesy($im),imagesx($im),imagesy($im)); // Copy the source image onto that
484 imagecopyresized($im_base, $cpImg, $Xstart, $Ystart, $cpImgCutX, $cpImgCutY, $w, $h, $w, $h); // Then copy the $cpImg onto that (the actual operation!)
485 $im = $im_base; // Set pointer
486 $this->makeEffect($im, Array('value'=>'colors=256')); // Reduce colors to 256 - make SURE that IM is working then!
487 } else {
488 imagecopyresized($im, $cpImg, $Xstart, $Ystart, $cpImgCutX, $cpImgCutY, $w, $h, $w, $h);
489 }
490 }
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514 /********************************
515 *
516 * Text / "TEXT" GIFBUILDER object
517 *
518 ********************************/
519
520 /**
521 * Implements the "TEXT" GIFBUILDER object
522 *
523 * @param pointer GDlib image pointer
524 * @param array TypoScript array with configuration for the GIFBUILDER object.
525 * @param array The current working area coordinates.
526 * @return void
527 * @see tslib_gifBuilder::make()
528 */
529 function makeText(&$im,$conf,$workArea) {
530 // Spacing
531 $spacing = intval($conf['spacing']);
532 $wordSpacing = intval($conf['wordSpacing']);
533 $wordSpacing = $wordSpacing?$wordSpacing:$spacing*2;
534 // Position
535 $txtPos = $this->txtPosition($conf,$workArea,$conf['BBOX']);
536 $theText = $this->recodeString($conf['text']);
537
538 if ($conf['imgMap'] && is_array($conf['imgMap.'])) {
539 $this->addToMap($this->calcTextCordsForMap($conf['BBOX'][2],$txtPos, $conf['imgMap.']), $conf['imgMap.']);
540 }
541 if (!$conf['hideButCreateMap']) {
542 // Font Color:
543 $cols=$this->convertColor($conf['fontColor']);
544 // NiceText is calculated
545 if (!$conf['niceText']) {
546 // Font Color is reserved:
547 $this->reduceColors($im,256, 200);
548 $Fcolor = ImageColorAllocate($im, $cols[0],$cols[1],$cols[2]);
549 // antiAliasing is setup:
550 $Fcolor = ($conf['antiAlias']) ? $Fcolor : -$Fcolor;
551
552 for ($a=0; $a<$conf['iterations']; $a++) {
553 if ($spacing || $wordSpacing) { // If any kind of spacing applys, we use this function:
554 $this->SpacedImageTTFText($im, $conf['fontSize'], $conf['angle'], $txtPos[0], $txtPos[1], $Fcolor, t3lib_stdGraphic::prependAbsolutePath($conf['fontFile']), $theText, $spacing, $wordSpacing);
555 } else {
556 ImageTTFText($im, t3lib_div::freetypeDpiComp($conf['fontSize']), $conf['angle'], $txtPos[0], $txtPos[1], $Fcolor, t3lib_stdGraphic::prependAbsolutePath($conf['fontFile']), $theText);
557 }
558 }
559 } else { // NICETEXT::
560 // options anti_aliased and iterations is NOT available when doing this!!
561 $w = imagesx($im);
562 $h = imagesy($im);
563 $tmpStr = $this->randomName();
564
565 $fileMenu = $tmpStr.'_menuNT.'.$this->gifExtension;
566 $fileColor = $tmpStr.'_colorNT.'.$this->gifExtension;
567 $fileMask = $tmpStr.'_maskNT.'.$this->gifExtension;
568 // Scalefactor
569 $sF = t3lib_div::intInRange($conf['niceText.']['scaleFactor'],2,5);
570 $newW = ceil($sF*imagesx($im));
571 $newH = ceil($sF*imagesy($im));
572
573 // Make mask
574 $maskImg = imagecreate($newW, $newH);
575 ImageColorAllocate($maskImg, 255,255,255);
576 $Fcolor = ImageColorAllocate($maskImg, 0,0,0);
577 if ($spacing || $wordSpacing) { // If any kind of spacing applys, we use this function:
578 $this->SpacedImageTTFText($maskImg, ceil($sF*$conf['fontSize']), $conf['angle'], ceil($sF*$txtPos[0]), ceil($sF*$txtPos[1]), $Fcolor, t3lib_stdGraphic::prependAbsolutePath($conf['fontFile']), $theText, ceil($sF*$spacing), ceil($sF*$wordSpacing));
579 } else {
580 ImageTTFText($maskImg, t3lib_div::freetypeDpiComp(ceil($sF*$conf['fontSize'])), $conf['angle'], ceil($sF*$txtPos[0]), ceil($sF*$txtPos[1]), $Fcolor, t3lib_stdGraphic::prependAbsolutePath($conf['fontFile']), $theText);
581 }
582 $this->ImageGif($maskImg, $fileMask);
583 ImageDestroy($maskImg);
584
585 // Downscales the mask
586 if ($this->NO_IM_EFFECTS) {
587 if ($this->maskNegate) {
588 $command = trim($this->scalecmd.' '.$w.'x'.$h.'!'); // Negate 2 times makes no negate...
589 } else {
590 $command = trim($this->scalecmd.' '.$w.'x'.$h.'! -negate');
591 }
592 } else {
593 if ($this->maskNegate) {
594 $command = trim($conf['niceText.']['before'].' '.$this->scalecmd.' '.$w.'x'.$h.'! '.$conf['niceText.']['after']);
595 } else {
596 $command = trim($conf['niceText.']['before'].' '.$this->scalecmd.' '.$w.'x'.$h.'! '.$conf['niceText.']['after'].' -negate');
597 }
598 if ($conf['niceText.']['sharpen']) {
599 if ($this->V5_EFFECTS) {
600 $command.=$this->v5_sharpen($conf['niceText.']['sharpen']);
601 } else {
602 $command.=' -sharpen '.t3lib_div::intInRange($conf['niceText.']['sharpen'],1,99);
603 }
604 }
605 }
606 $this->imageMagickExec($fileMask,$fileMask,$command);
607
608 // Make the color-file
609 $colorImg = imagecreate($w,$h);
610 ImageColorAllocate($colorImg, $cols[0],$cols[1],$cols[2]);
611 $this->ImageGif($colorImg, $fileColor);
612 ImageDestroy($colorImg);
613
614 // The mask is applied
615 $this->ImageGif($im, $fileMenu); // The main pictures is saved temporarily
616
617 $this->combineExec($fileMenu,$fileColor,$fileMask,$fileMenu);
618
619 $backIm = $this->imageCreateFromGif($fileMenu); // The main image is loaded again...
620 if ($backIm) { // ... and if nothing went wrong we load it onto the old one.
621 ImageColorTransparent($backIm,-1);
622 $im = $backIm;
623 }
624
625 // Deleting temporary files;
626 if (!$this->dontUnlinkTempFiles) {
627 unlink($fileMenu);
628 unlink($fileColor);
629 unlink($fileMask);
630 }
631 }
632 }
633 }
634
635 /**
636 * Calculates text position for printing the text onto the image based on configuration like alignment and workarea.
637 *
638 * @param array TypoScript array for the TEXT GIFBUILDER object
639 * @param array Workarea definition
640 * @param array Bounding box information, was set in tslib_gifBuilder::start()
641 * @return array [0]=x, [1]=y, [2]=w, [3]=h
642 * @access private
643 * @see makeText()
644 */
645 function txtPosition($conf,$workArea,$BB) {
646 $bbox = $BB[2];
647 $angle=intval($conf['angle'])/180*pi();
648 $conf['angle']=0;
649 $straightBB = $this->calcBBox($conf);
650
651 // offset, align, valign, workarea
652 $result=Array(); // [0]=x, [1]=y, [2]=w, [3]=h
653 $result[2] = $BB[0];
654 $result[3] = $BB[1];
655 $w=$workArea[2];
656 $h=$workArea[3];
657
658 switch($conf['align']) {
659 case 'right':
660 case 'center':
661 $factor=abs(cos($angle));
662 $sign=(cos($angle)<0)?-1:1;
663 $len1 = $sign*$factor*$straightBB[0];
664 $len2= $sign*$BB[0];
665 $result[0] = $w-ceil($len2*$factor+(1-$factor)*$len1);
666
667 $factor=abs(sin($angle));
668 $sign=(sin($angle)<0)?-1:1;
669 $len1= $sign*$factor*$straightBB[0];
670 $len2= $sign*$BB[1];
671 $result[1]=ceil($len2*$factor+(1-$factor)*$len1);
672 break;
673 }
674 switch($conf['align']) {
675 case 'right':
676 break;
677 case 'center':
678 $result[0] = round(($result[0])/2);
679 $result[1] = round(($result[1])/2);
680 break;
681 default:
682 $result[0]=0;
683 $result[1]=0;
684 break;
685 }
686 $result = $this->applyOffset($result,t3lib_div::intExplode(',',$conf['offset']));
687 $result = $this->applyOffset($result,$workArea);
688 return $result;
689 }
690
691 /**
692 * Calculates bounding box information for the TEXT GIFBUILDER object.
693 *
694 * @param array TypoScript array for the TEXT GIFBUILDER object
695 * @return array Array with three keys [0]/[1] being x/y and [2] being the bounding box array
696 * @access private
697 * @see txtPosition(), tslib_gifBuilder::start()
698 */
699 function calcBBox($conf) {
700 if (!$conf['niceText']) {
701 $sF = 1;
702 } else { // NICETEXT::
703 $sF = t3lib_div::intInRange($conf['niceText.']['scaleFactor'],2,5);
704 }
705
706 $spacing = intval($conf['spacing']);
707 $wordSpacing = intval($conf['wordSpacing']);
708 $wordSpacing = $wordSpacing?$wordSpacing:$spacing*2;
709
710 $spacing*=$sF;
711 $wordSpacing*=$sF;
712 $theText = $this->recodeString($conf['text']);
713
714 $charInf = ImageTTFBBox(t3lib_div::freetypeDpiComp($sF*$conf['fontSize']), $conf['angle'], t3lib_stdGraphic::prependAbsolutePath($conf['fontFile']), $theText);
715 $theBBoxInfo = $charInf;
716 if ($conf['angle']) {
717 $xArr = Array($charInf[0],$charInf[2],$charInf[4],$charInf[6]);
718 $yArr = Array($charInf[1],$charInf[3],$charInf[5],$charInf[7]);
719 $x=max($xArr)-min($xArr);
720 $y=max($yArr)-min($yArr);
721 } else {
722 $x = ($charInf[2]-$charInf[0]);
723 $y = ($charInf[1]-$charInf[7]);
724 }
725 if ($spacing || $wordSpacing) { // If any kind of spacing applys, we use this function:
726 $x=0;
727 if (!$spacing && $wordSpacing) {
728 $bits = explode(' ',$theText);
729 while(list(,$word)=each($bits)) {
730 $word.=' ';
731 $wordInf = ImageTTFBBox(t3lib_div::freetypeDpiComp($sF*$conf['fontSize']), $conf['angle'], t3lib_stdGraphic::prependAbsolutePath($conf['fontFile']), $word);
732 $wordW = ($wordInf[2]-$wordInf[0]);
733 $x+=$wordW+$wordSpacing;
734 }
735 } else {
736 $utf8Chars = $this->singleChars($theText);
737 // For each UTF-8 char, do:
738 foreach($utf8Chars as $char) {
739 $charInf = ImageTTFBBox(t3lib_div::freetypeDpiComp($sF*$conf['fontSize']), $conf['angle'], t3lib_stdGraphic::prependAbsolutePath($conf['fontFile']), $char);
740 $charW = ($charInf[2]-$charInf[0]);
741 $x+=$charW+(($char==' ')?$wordSpacing:$spacing);
742 }
743 }
744 }
745
746 if ($sF>1) {
747 $x = ceil($x/$sF);
748 $y = ceil($y/$sF);
749 if (is_array($theBBoxInfo)) {
750 reset($theBBoxInfo);
751 while(list($key,$val)=each($theBBoxInfo)) {
752 $theBBoxInfo[$key]=ceil($theBBoxInfo[$key]/$sF);
753 }
754 }
755 }
756 return Array($x,$y,$theBBoxInfo);
757 }
758
759 /**
760 * Adds an <area> tag to the internal variable $this->map which is used to accumulate the content for an ImageMap
761 *
762 * @param array Coordinates for a polygon image map as created by ->calcTextCordsForMap()
763 * @param array Configuration for "imgMap." property of a TEXT GIFBUILDER object.
764 * @return void
765 * @access private
766 * @see makeText(), calcTextCordsForMap()
767 */
768 function addToMap($cords,$conf) {
769 $JS = $conf['noBlur'] ? '' : ' onfocus="blurLink(this);"';
770
771 $this->map.='<area'.
772 ' shape="poly"'.
773 ' coords="'.implode($cords,',').'"'.
774 ' href="'.htmlspecialchars($conf['url']).'"'.
775 ($conf['target'] ? ' target="'.htmlspecialchars($conf['target']).'"' : '').
776 $JS.
777 (strlen($conf['titleText']) ? ' title="'.htmlspecialchars($conf['titleText']).'"' : '').
778 ' alt="'.htmlspecialchars($conf['altText']).'" />';
779 }
780
781 /**
782 * Calculating the coordinates for a TEXT string on an image map. Used in an <area> tag
783 *
784 * @param array Coordinates (from BBOX array)
785 * @param array Offset array
786 * @param array Configuration for "imgMap." property of a TEXT GIFBUILDER object.
787 * @return array
788 * @access private
789 * @see makeText(), calcTextCordsForMap()
790 */
791 function calcTextCordsForMap($cords,$offset, $conf) {
792 $pars = t3lib_div::intExplode(',',$conf['explode'].',');
793
794 $newCords[0] = $cords[0]+$offset[0]-$pars[0];
795 $newCords[1] = $cords[1]+$offset[1]+$pars[1];
796 $newCords[2] = $cords[2]+$offset[0]+$pars[0];
797 $newCords[3] = $cords[3]+$offset[1]+$pars[1];
798 $newCords[4] = $cords[4]+$offset[0]+$pars[0];
799 $newCords[5] = $cords[5]+$offset[1]-$pars[1];
800 $newCords[6] = $cords[6]+$offset[0]-$pars[0];
801 $newCords[7] = $cords[7]+$offset[1]-$pars[1];
802
803 return $newCords;
804 }
805
806 /**
807 * Printing text onto an image like the PHP function imageTTFText does but in addition it offers options for spacing of letters and words.
808 * Spacing is done by printing one char at a time and this means that the spacing is rather uneven and probably not very nice.
809 * See
810 *
811 * @param pointer (See argument for PHP function imageTTFtext())
812 * @param integer (See argument for PHP function imageTTFtext())
813 * @param integer (See argument for PHP function imageTTFtext())
814 * @param integer (See argument for PHP function imageTTFtext())
815 * @param integer (See argument for PHP function imageTTFtext())
816 * @param integer (See argument for PHP function imageTTFtext())
817 * @param string (See argument for PHP function imageTTFtext())
818 * @param string (See argument for PHP function imageTTFtext()). UTF-8 string, possibly with entities in.
819 * @param integer The spacing of letters in pixels
820 * @param integer The spacing of words in pixels
821 * @return void
822 * @access private
823 */
824 function SpacedImageTTFText(&$im, $fontSize, $angle, $x, $y, $Fcolor, $fontFile, $text, $spacing, $wordSpacing) {
825 if (!$spacing && $wordSpacing) {
826 $bits = explode(' ',$text);
827 reset($bits);
828 while(list(,$word)=each($bits)) {
829 $word.=' ';
830 $word = $word;
831 $wordInf = ImageTTFBBox(t3lib_div::freetypeDpiComp($fontSize), $angle, t3lib_stdGraphic::prependAbsolutePath($fontFile), $word);
832 $wordW = ($wordInf[2]-$wordInf[0]);
833 ImageTTFText($im, t3lib_div::freetypeDpiComp($fontSize), $angle, $x, $y, $Fcolor, t3lib_stdGraphic::prependAbsolutePath($fontFile), $word);
834 $x+=$wordW+$wordSpacing;
835 }
836 } else {
837 $utf8Chars = $this->singleChars($text);
838 // For each UTF-8 char, do:
839 foreach($utf8Chars as $char) {
840 $charInf = ImageTTFBBox(t3lib_div::freetypeDpiComp($fontSize), $angle, t3lib_stdGraphic::prependAbsolutePath($fontFile), $char);
841 $charW = ($charInf[2]-$charInf[0]);
842 ImageTTFText($im, t3lib_div::freetypeDpiComp($fontSize), $angle, $x, $y, $Fcolor, t3lib_stdGraphic::prependAbsolutePath($fontFile), $char);
843 $x+=$charW+(($char==' ')?$wordSpacing:$spacing);
844 }
845 }
846 }
847
848 /**
849 * Function that finds the right fontsize that will render the textstring within a certain width
850 *
851 * @param array The TypoScript properties of the TEXT GIFBUILDER object
852 * @return integer The new fontSize
853 * @access private
854 * @author Rene Fritz <r.fritz@colorcube.de>
855 * @see tslib_gifBuilder::start()
856 */
857 function fontResize($conf) {
858 // you have to use +calc options like [10.h] in 'offset' to get the right position of your text-image, if you use +calc in XY height!!!!
859 $maxWidth = intval($conf['maxWidth']);
860 if ($maxWidth) {
861 if ($spacing || $wordSpacing) { // If any kind of spacing applys, we use this function:
862 return $conf['fontSize'];
863 // ################ no calc for spacing yet !!!!!!
864 } else {
865 $fontSize = $conf['fontSize'];
866 do {
867 $conf['fontSize'] = $fontSize;
868 // determine bounding box.
869 $bounds = ImageTTFBBox(t3lib_div::freetypeDpiComp($conf['fontSize']), $conf['angle'], t3lib_stdGraphic::prependAbsolutePath($conf['fontFile']), $this->recodeString($conf['text']));
870 if ($conf['angle']< 0) {
871 $pixelWidth = abs($bounds[4]-$bounds[0]);
872 } elseif ($conf['angle'] > 0) {
873 $pixelWidth = abs($bounds[2]-$bounds[6]);
874 } else {
875 $pixelWidth = abs($bounds[4]-$bounds[6]);
876 }
877 // This is a very raw calculation but it makes it in one step
878 $fontSize=(int)($maxWidth*$fontSize/$pixelWidth);
879 if ($fontSize >= $conf['fontSize']) {
880 $fontSize = $conf['fontSize']-1;
881 }
882 } while ($pixelWidth > $maxWidth);
883 }//if spacing
884 }
885 return $conf['fontSize'];
886 }
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903 /*********************************************
904 *
905 * Other GIFBUILDER objects related to TEXT
906 *
907 *********************************************/
908
909 /**
910 * Implements the "OUTLINE" GIFBUILDER object / property for the TEXT object
911 *
912 * @param pointer GDlib image pointer
913 * @param array TypoScript array with configuration for the GIFBUILDER object.
914 * @param array The current working area coordinates.
915 * @param array TypoScript array with configuration for the associated TEXT GIFBUILDER object.
916 * @return void
917 * @see tslib_gifBuilder::make(), makeText()
918 */
919 function makeOutline(&$im,$conf,$workArea,$txtConf) {
920 $thickness = intval($conf['thickness']);
921 if ($thickness) {
922 $txtConf['fontColor'] = $conf['color'];
923 $outLineDist = t3lib_div::intInRange($thickness,1,2);
924 for ($b=1;$b<=$outLineDist;$b++) {
925 if ($b==1) {
926 $it = 8;
927 } else {
928 $it = 16;
929 }
930 $outL = $this->circleOffset($b, $it);
931 for ($a=0;$a<$it;$a++) {
932 $this->makeText($im,$txtConf,$this->applyOffset($workArea,$outL[$a]));
933 }
934 }
935 }
936 }
937
938 /**
939 * Creates some offset values in an array used to simulate a circularly applied outline around TEXT
940 *
941 * access private
942 *
943 * @param integer Distance
944 * @param integer Iterations.
945 * @return array
946 * @see makeOutline()
947 */
948 function circleOffset($distance, $iterations) {
949 $res = Array();
950 if ($distance && $iterations) {
951 for ($a=0;$a<$iterations;$a++) {
952 $yOff = round(sin(2*pi()/$iterations*($a+1))*100*$distance);
953 if ($yOff) {$yOff = intval(ceil(abs($yOff/100))*($yOff/abs($yOff)));}
954 $xOff = round(cos(2*pi()/$iterations*($a+1))*100*$distance);
955 if ($xOff) {$xOff = intval(ceil(abs($xOff/100))*($xOff/abs($xOff)));}
956 $res[$a] = Array($xOff,$yOff);
957 }
958 }
959 return $res;
960 }
961
962 /**
963 * Implements the "EMBOSS" GIFBUILDER object / property for the TEXT object
964 *
965 * @param pointer GDlib image pointer
966 * @param array TypoScript array with configuration for the GIFBUILDER object.
967 * @param array The current working area coordinates.
968 * @param array TypoScript array with configuration for the associated TEXT GIFBUILDER object.
969 * @return void
970 * @see tslib_gifBuilder::make(), makeShadow()
971 */
972 function makeEmboss(&$im,$conf,$workArea,$txtConf) {
973 $conf['color']=$conf['highColor'];
974 $this->makeShadow($im,$conf,$workArea,$txtConf);
975 $newOffset = t3lib_div::intExplode(',',$conf['offset']);
976 $newOffset[0]*=-1;
977 $newOffset[1]*=-1;
978 $conf['offset']=implode($newOffset,',');
979 $conf['color']=$conf['lowColor'];
980 $this->makeShadow($im,$conf,$workArea,$txtConf);
981 }
982
983 /**
984 * Implements the "SHADOW" GIFBUILDER object / property for the TEXT object
985 * The operation involves ImageMagick for combining.
986 *
987 * @param pointer GDlib image pointer
988 * @param array TypoScript array with configuration for the GIFBUILDER object.
989 * @param array The current working area coordinates.
990 * @param array TypoScript array with configuration for the associated TEXT GIFBUILDER object.
991 * @return void
992 * @see tslib_gifBuilder::make(), makeText(), makeEmboss()
993 */
994 function makeShadow(&$im,$conf,$workArea,$txtConf) {
995 $workArea = $this->applyOffset($workArea,t3lib_div::intExplode(',',$conf['offset']));
996 $blurRate = t3lib_div::intInRange(intval($conf['blur']),0,99);
997
998 if (!$blurRate || $this->NO_IM_EFFECTS) { // No effects if ImageMagick ver. 5+
999 $txtConf['fontColor'] = $conf['color'];
1000 $this->makeText($im,$txtConf,$workArea);
1001 } else {
1002 $w = imagesx($im);
1003 $h = imagesy($im);
1004 $blurBorder= 3; // area around the blur used for cropping something
1005 $tmpStr = $this->randomName();
1006 $fileMenu = $tmpStr.'_menu.'.$this->gifExtension;
1007 $fileColor = $tmpStr.'_color.'.$this->gifExtension;
1008 $fileMask = $tmpStr.'_mask.'.$this->gifExtension;
1009
1010 // BlurColor Image laves
1011 $blurColImg = imagecreate($w,$h);
1012 $bcols=$this->convertColor($conf['color']);
1013 ImageColorAllocate($blurColImg, $bcols[0],$bcols[1],$bcols[2]);
1014 $this->ImageGif($blurColImg, $fileColor);
1015 ImageDestroy($blurColImg);
1016
1017 // The mask is made: BlurTextImage
1018 $blurTextImg = imagecreate($w+$blurBorder*2,$h+$blurBorder*2);
1019 ImageColorAllocate($blurTextImg, 0,0,0); // black background
1020 $txtConf['fontColor'] = 'white';
1021 $blurBordArr = Array($blurBorder,$blurBorder);
1022 $this->makeText($blurTextImg,$txtConf, $this->applyOffset($workArea,$blurBordArr));
1023 $this->ImageGif($blurTextImg, $fileMask); // dump to temporary file
1024 ImageDestroy($blurTextImg); // destroy
1025
1026
1027 $command='';
1028 $command.=$this->maskNegate;
1029
1030 if ($this->V5_EFFECTS) {
1031 $command.=$this->v5_blur($blurRate+1);
1032 } else {
1033 // Blurring of the mask
1034 $times = ceil($blurRate/10); // How many blur-commands that is executed. Min = 1;
1035 $newBlurRate = $blurRate*4; // Her booster vi blur-rate, s�at den allerede ved 25 er p�100. Resten op til 99 g� p�iterationer af blur-kommandoen
1036 $newBlurRate = t3lib_div::intInRange($newBlurRate,1,99);
1037 for ($a=0;$a<$times;$a++) { // Building blur-command
1038 $command.=' -blur '.$blurRate;
1039 }
1040 }
1041
1042 $this->imageMagickExec($fileMask,$fileMask,$command);
1043
1044 $blurTextImg_tmp = $this->imageCreateFromGif($fileMask); // the mask is loaded again
1045 if ($blurTextImg_tmp) { // if nothing went wrong we continue with the blurred mask
1046
1047 // cropping the border from the mask
1048 $blurTextImg = imagecreate($w,$h);
1049 $this->imagecopyresized($blurTextImg, $blurTextImg_tmp, 0, 0, $blurBorder, $blurBorder, $w, $h, $w, $h);
1050 ImageDestroy($blurTextImg_tmp); // Destroy the temporary mask
1051
1052 // adjust the mask
1053 $intensity = 40;
1054 if ($conf['intensity']) {
1055 $intensity = t3lib_div::intInRange($conf['intensity'],0,100);
1056 }
1057 $intensity = ceil(255-($intensity/100*255));
1058 $this->inputLevels($blurTextImg,0,$intensity,$this->maskNegate);
1059
1060 $opacity = t3lib_div::intInRange(intval($conf['opacity']),0,100);
1061 if ($opacity && $opacity<100) {
1062 $high = ceil(255*$opacity/100);
1063 $this->outputLevels($blurTextImg,0,$high,$this->maskNegate); // reducing levels as the opacity demands
1064 }
1065
1066 $this->ImageGif($blurTextImg, $fileMask); // Dump the mask again
1067 ImageDestroy($blurTextImg); // Destroy the mask
1068
1069 // The pictures are combined
1070 $this->ImageGif($im, $fileMenu); // The main pictures is saved temporarily
1071
1072 $this->combineExec($fileMenu,$fileColor,$fileMask,$fileMenu);
1073
1074 $backIm = $this->imageCreateFromGif($fileMenu); // The main image is loaded again...
1075 if ($backIm) { // ... and if nothing went wrong we load it onto the old one.
1076 ImageColorTransparent($backIm,-1);
1077 $im = $backIm;
1078 }
1079 }
1080 // Deleting temporary files;
1081 if (!$this->dontUnlinkTempFiles) {
1082 unlink($fileMenu);
1083 unlink($fileColor);
1084 unlink($fileMask);
1085 }
1086 }
1087 }
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109 /****************************
1110 *
1111 * Other GIFBUILDER objects
1112 *
1113 ****************************/
1114
1115 /**
1116 * Implements the "BOX" GIFBUILDER object
1117 *
1118 * @param pointer GDlib image pointer
1119 * @param array TypoScript array with configuration for the GIFBUILDER object.
1120 * @param array The current working area coordinates.
1121 * @return void
1122 * @see tslib_gifBuilder::make()
1123 */
1124 function makeBox(&$im,$conf,$workArea) {
1125 $cords = t3lib_div::intExplode(',',$conf['dimensions'].',,,');
1126 $conf['offset']=$cords[0].','.$cords[1];
1127 $cords = $this->objPosition($conf,$workArea,Array($cords[2],$cords[3]));
1128 $cols=$this->convertColor($conf['color']);
1129 $this->reduceColors($im,256, 255);
1130 $tmpColor = ImageColorAllocate($im, $cols[0],$cols[1],$cols[2]);
1131 imagefilledrectangle($im, $cords[0], $cords[1], $cords[0]+$cords[2]-1, $cords[1]+$cords[3]-1, $tmpColor);
1132 }
1133
1134 /**
1135 * Implements the "EFFECT" GIFBUILDER object
1136 * The operation involves ImageMagick for applying effects
1137 *
1138 * @param pointer GDlib image pointer
1139 * @param array TypoScript array with configuration for the GIFBUILDER object.
1140 * @return void
1141 * @see tslib_gifBuilder::make(), applyImageMagickToPHPGif()
1142 */
1143 function makeEffect(&$im, $conf) {
1144 $commands = $this->IMparams($conf['value']);
1145 if ($commands) {
1146 $this->applyImageMagickToPHPGif($im, $commands);
1147 }
1148 }
1149
1150 /**
1151 * Creating ImageMagick paramters from TypoScript property
1152 *
1153 * @param string A string with effect keywords=value pairs separated by "|"
1154 * @return string ImageMagick prepared parameters.
1155 * @access private
1156 * @see makeEffect()
1157 */
1158 function IMparams($setup) {
1159 if (!trim($setup)){return '';}
1160 $effects = explode('|', $setup);
1161 $commands = '';
1162 while(list(,$val)=each($effects)) {
1163 $pairs=explode('=',$val,2);
1164 $value = trim($pairs[1]);
1165 $effect = strtolower(trim($pairs[0]));
1166 switch($effect) {
1167 case 'gamma':
1168 $commands.=' -gamma '.doubleval($value);
1169 break;
1170 case 'blur':
1171 if (!$this->NO_IM_EFFECTS) {
1172 if ($this->V5_EFFECTS) {
1173 $commands.=$this->v5_blur($value);
1174 } else {
1175 $commands.=' -blur '.t3lib_div::intInRange($value,1,99);
1176 }
1177 }
1178 break;
1179 case 'sharpen':
1180 if (!$this->NO_IM_EFFECTS) {
1181 if ($this->V5_EFFECTS) {
1182 $commands.=$this->v5_sharpen($value);
1183 } else {
1184 $commands.=' -sharpen '.t3lib_div::intInRange($value,1,99);
1185 }
1186 }
1187 break;
1188 case 'rotate':
1189 $commands.=' -rotate '.t3lib_div::intInRange($value,0,360);
1190 break;
1191 case 'solarize':
1192 $commands.=' -solarize '.t3lib_div::intInRange($value,0,99);
1193 break;
1194 case 'swirl':
1195 $commands.=' -swirl '.t3lib_div::intInRange($value,0,1000);
1196 break;
1197 case 'wave':
1198 $params = t3lib_div::intExplode(',',$value);
1199 $commands.=' -wave '.t3lib_div::intInRange($params[0],0,99).'x'.t3lib_div::intInRange($params[1],0,99);
1200 break;
1201 case 'charcoal':
1202 $commands.=' -charcoal '.t3lib_div::intInRange($value,0,100);
1203 break;
1204 case 'gray':
1205 $commands.=' -colorspace GRAY';
1206 break;
1207 case 'edge':
1208 $commands.=' -edge '.t3lib_div::intInRange($value,0,99);
1209 break;
1210 case 'emboss':
1211 $commands.=' -emboss';
1212 break;
1213 case 'flip':
1214 $commands.=' -flip';
1215 break;
1216 case 'flop':
1217 $commands.=' -flop';
1218 break;
1219 case 'colors':
1220 $commands.=' -colors '.t3lib_div::intInRange($value,2,255);
1221 break;
1222 case 'shear':
1223 $commands.=' -shear '.t3lib_div::intInRange($value,-90,90);
1224 break;
1225 case 'invert':
1226 $commands.=' -negate';
1227 break;
1228 }
1229 }
1230 return $commands;
1231 }
1232
1233 /**
1234 * Implements the "ADJUST" GIFBUILDER object
1235 *
1236 * @param pointer GDlib image pointer
1237 * @param array TypoScript array with configuration for the GIFBUILDER object.
1238 * @return void
1239 * @see tslib_gifBuilder::make(), autoLevels(), outputLevels(), inputLevels()
1240 */
1241 function adjust(&$im, $conf) {
1242 $setup = $conf['value'];
1243 if (!trim($setup)){return '';}
1244 $effects = explode('|', $setup);
1245 while(list(,$val)=each($effects)) {
1246 $pairs=explode('=',$val,2);
1247 $value = trim($pairs[1]);
1248 $effect = strtolower(trim($pairs[0]));
1249 switch($effect) {
1250 case 'inputlevels': // low,high
1251 $params = t3lib_div::intExplode(',',$value);
1252 $this->inputLevels($im,$params[0],$params[1]);
1253 break;
1254 case 'outputlevels':
1255 $params = t3lib_div::intExplode(',',$value);
1256 $this->outputLevels($im,$params[0],$params[1]);
1257 break;
1258 case 'autolevels':
1259 $this->autoLevels($im);
1260 break;
1261 }
1262 }
1263 }
1264
1265 /**
1266 * Implements the "CROP" GIFBUILDER object
1267 *
1268 * @param pointer GDlib image pointer
1269 * @param array TypoScript array with configuration for the GIFBUILDER object.
1270 * @return void
1271 * @see tslib_gifBuilder::make()
1272 */
1273 function crop(&$im,$conf) {
1274 $this->setWorkArea(''); // clears workArea to total image
1275 $cords = t3lib_div::intExplode(',',$conf['crop'].',,,');
1276 $conf['offset']=$cords[0].','.$cords[1];
1277 $cords = $this->objPosition($conf,$this->workArea,Array($cords[2],$cords[3]));
1278
1279 $newIm = imagecreate($cords[2],$cords[3]);
1280 $cols=$this->convertColor($conf['backColor']?$conf['backColor']:$this->setup['backColor']);
1281 ImageColorAllocate($newIm, $cols[0],$cols[1],$cols[2]);
1282
1283 $newConf = Array();
1284 $workArea = Array(0,0,$cords[2],$cords[3]);
1285 if ($cords[0]<0) {$workArea[0]=abs($cords[0]);} else {$newConf['offset']=-$cords[0];}
1286 if ($cords[1]<0) {$workArea[1]=abs($cords[1]);} else {$newConf['offset'].=','.-$cords[1];}
1287
1288 $this->copyGifOntoGif($newIm,$im,$newConf,$workArea);
1289 $im = $newIm;
1290 $this->w = imagesx($im);
1291 $this->h = imagesy($im);
1292 $this->setWorkArea(''); // clears workArea to total image
1293 }
1294
1295 /**
1296 * Implements the "SCALE" GIFBUILDER object
1297 *
1298 * @param pointer GDlib image pointer
1299 * @param array TypoScript array with configuration for the GIFBUILDER object.
1300 * @return void
1301 * @see tslib_gifBuilder::make()
1302 */
1303 function scale(&$im,$conf) {
1304 if ($conf['width'] || $conf['height'] || $conf['params']) {
1305 $tmpStr = $this->randomName();
1306 $theFile = $tmpStr.'.'.$this->gifExtension;
1307 $this->ImageGif($im, $theFile);
1308 $theNewFile = $this->imageMagickConvert($theFile,$this->gifExtension,$conf['width'],$conf['height'],$conf['params'],'','');
1309 $tmpImg = $this->imageCreateFromGif($theNewFile[3]);
1310 if ($tmpImg) {
1311 ImageDestroy($im);
1312 $im = $tmpImg;
1313 $this->w = imagesx($im);
1314 $this->h = imagesy($im);
1315 $this->setWorkArea(''); // clears workArea to total image
1316 }
1317 if (!$this->dontUnlinkTempFiles) {
1318 unlink($theFile);
1319 if ($theNewFile[3] && $theNewFile[3]!=$theFile) {
1320 unlink($theNewFile[3]);
1321 }
1322 }
1323 }
1324 }
1325
1326 /**
1327 * Implements the "WORKAREA" GIFBUILDER object when setting it
1328 * Setting internal working area boundaries (->workArea)
1329 *
1330 * @param string Working area dimensions, comma separated
1331 * @return void
1332 * @access private
1333 * @see tslib_gifBuilder::make()
1334 */
1335 function setWorkArea($workArea) {
1336 $this->workArea = t3lib_div::intExplode(',',$workArea);
1337 $this->workArea = $this->applyOffset($this->workArea,$this->OFFSET);
1338 if (!$this->workArea[2]) {$this->workArea[2]=$this->w;}
1339 if (!$this->workArea[3]) {$this->workArea[3]=$this->h;}
1340 }
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364 /*************************
1365 *
1366 * Adjustment functions
1367 *
1368 ************************/
1369
1370 /**
1371 * Apply auto-levels to input image pointer
1372 *
1373 * @param integer GDlib Image Pointer
1374 * @return void
1375 */
1376 function autolevels(&$im) {
1377 $totalCols = ImageColorsTotal($im);
1378 $min=255;
1379 $max=0;
1380 for ($c=0; $c<$totalCols; $c++) {
1381 $cols = ImageColorsForIndex($im,$c);
1382 $grayArr[] = round(($cols['red']+$cols['green']+$cols['blue'])/3);
1383 }
1384 $min=min($grayArr);
1385 $max=max($grayArr);
1386 $delta = $max-$min;
1387 if ($delta) {
1388 for ($c=0; $c<$totalCols; $c++) {
1389 $cols = ImageColorsForIndex($im,$c);
1390 $cols['red'] = floor(($cols['red']-$min)/$delta*255);
1391 $cols['green'] = floor(($cols['green']-$min)/$delta*255);
1392 $cols['blue'] = floor(($cols['blue']-$min)/$delta*255);
1393 ImageColorSet($im,$c,$cols['red'],$cols['green'],$cols['blue']);
1394 }
1395 }
1396 }
1397
1398 /**
1399 * Apply output levels to input image pointer (decreasing contrast)
1400 *
1401 * @param integer GDlib Image Pointer
1402 * @param integer The "low" value (close to 0)
1403 * @param integer The "high" value (close to 255)
1404 * @param boolean If swap, then low and high are swapped. (Useful for negated masks...)
1405 * @return void
1406 */
1407 function outputLevels(&$im,$low,$high,$swap='') {
1408 if ($low<$high){
1409 $low = t3lib_div::intInRange($low,0,255);
1410 $high = t3lib_div::intInRange($high,0,255);
1411
1412 if ($swap) {
1413 $temp = $low;
1414 $low = 255-$high;
1415 $high = 255-$temp;
1416 }
1417
1418 $delta = $high-$low;
1419 $totalCols = ImageColorsTotal($im);
1420 for ($c=0; $c<$totalCols; $c++) {
1421 $cols = ImageColorsForIndex($im,$c);
1422 $cols['red'] = $low+floor($cols['red']/255*$delta);
1423 $cols['green'] = $low+floor($cols['green']/255*$delta);
1424 $cols['blue'] = $low+floor($cols['blue']/255*$delta);
1425 ImageColorSet($im,$c,$cols['red'],$cols['green'],$cols['blue']);
1426 }
1427 }
1428 }
1429
1430 /**
1431 * Apply input levels to input image pointer (increasing contrast)
1432 *
1433 * @param integer GDlib Image Pointer
1434 * @param integer The "low" value (close to 0)
1435 * @param integer The "high" value (close to 255)
1436 * @param boolean If swap, then low and high are swapped. (Useful for negated masks...)
1437 * @return void
1438 */
1439 function inputLevels(&$im,$low,$high,$swap='') {
1440 if ($low<$high){
1441 $low = t3lib_div::intInRange($low,0,255);
1442 $high = t3lib_div::intInRange($high,0,255);
1443
1444 if ($swap) {
1445 $temp = $low;
1446 $low = 255-$high;
1447 $high = 255-$temp;
1448 }
1449
1450 $delta = $high-$low;
1451 $totalCols = ImageColorsTotal($im);
1452 for ($c=0; $c<$totalCols; $c++) {
1453 $cols = ImageColorsForIndex($im,$c);
1454 $cols['red'] = t3lib_div::intInRange(($cols['red']-$low)/$delta*255, 0,255);
1455 $cols['green'] = t3lib_div::intInRange(($cols['green']-$low)/$delta*255, 0,255);
1456 $cols['blue'] = t3lib_div::intInRange(($cols['blue']-$low)/$delta*255, 0,255);
1457 ImageColorSet($im,$c,$cols['red'],$cols['green'],$cols['blue']);
1458 }
1459 }
1460 }
1461
1462 /**
1463 * Reduce colors in image
1464 *
1465 * @param integer GDlib Image Pointer
1466 * @param integer The max number of colors in the image before a reduction will happen; basically this means that IF the GD image current has the same amount or more colors than $limit define, THEN a reduction is performed.
1467 * @param integer Number of colors to reduce the image to.
1468 * @return void
1469 */
1470 function reduceColors(&$im,$limit, $cols) {
1471 if (ImageColorsTotal($im)>=$limit) {
1472 $this->makeEffect($im, Array('value'=>'colors='.$cols) );
1473 }
1474 }
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494 /*********************************
1495 *
1496 * GIFBUILDER Helper functions
1497 *
1498 *********************************/
1499
1500 /**
1501 * Checks if the $fontFile is already at an absolute path and if not, prepends the correct path.
1502 * Use PATH_site unless we are in the backend.
1503 * Call it by t3lib_stdGraphic::prependAbsolutePath()
1504 *
1505 * @param string The font file
1506 * @return string The font file with absolute path.
1507 */
1508 function prependAbsolutePath($fontFile) {
1509 $absPath = defined('PATH_typo3') ? dirname(PATH_thisScript).'/' :PATH_site;
1510 $fontFile = t3lib_div::isAbsPath($fontFile) ? $fontFile : $absPath.$fontFile;
1511 return $fontFile;
1512 }
1513
1514 /**
1515 * Returns the IM command for sharpening with ImageMagick 5 (when $this->V5_EFFECTS is set).
1516 * Uses $this->im5fx_sharpenSteps for translation of the factor to an actual command.
1517 *
1518 * @param integer The sharpening factor, 0-100 (effectively in 10 steps)
1519 * @return string The sharpening command, eg. " -sharpen 3x4"
1520 * @see makeText(), IMparams(), v5_blur()
1521 */
1522 function v5_sharpen($factor) {
1523 $factor = t3lib_div::intInRange(ceil($factor/10),0,10);
1524
1525 $sharpenArr=explode(',',','.$this->im5fx_sharpenSteps);
1526 $sharpenF= trim($sharpenArr[$factor]);
1527 if ($sharpenF) {
1528 $cmd = ' -sharpen '.$sharpenF;
1529 return $cmd;
1530 }
1531 }
1532
1533 /**
1534 * Returns the IM command for blurring with ImageMagick 5 (when $this->V5_EFFECTS is set).
1535 * Uses $this->im5fx_blurSteps for translation of the factor to an actual command.
1536 *
1537 * @param integer The blurring factor, 0-100 (effectively in 10 steps)
1538 * @return string The blurring command, eg. " -blur 3x4"
1539 * @see makeText(), IMparams(), v5_sharpen()
1540 */
1541 function v5_blur($factor) {
1542 $factor = t3lib_div::intInRange(ceil($factor/10),0,10);
1543
1544 $blurArr=explode(',',','.$this->im5fx_blurSteps);
1545 $blurF= trim($blurArr[$factor]);
1546 if ($blurF) {
1547 $cmd=' -blur '.$blurF;
1548 return $cmd;
1549 }
1550 }
1551
1552 /**
1553 * Returns a random filename prefixed with "temp_" and then 32 char md5 hash (without extension) from $this->tempPath.
1554 * Used by functions in this class to create truely temporary files for the on-the-fly processing. These files will most likely be deleted right away.
1555 *
1556 * @return string
1557 */
1558 function randomName() {
1559 $this->createTempSubDir('temp/');
1560 return $this->tempPath.'temp/'.md5(uniqid(''));
1561 }
1562
1563 /**
1564 * Applies offset value to coordinated in $cords.
1565 * Basically the value of key 0/1 of $OFFSET is added to keys 0/1 of $cords
1566 *
1567 * @param array Integer coordinates in key 0/1
1568 * @param array Offset values in key 0/1
1569 * @return array Modified $cords array
1570 */
1571 function applyOffset($cords,$OFFSET) {
1572 $cords[0] = intval($cords[0])+intval($OFFSET[0]);
1573 $cords[1] = intval($cords[1])+intval($OFFSET[1]);
1574 return $cords;
1575 }
1576
1577 /**
1578 * Converts a "HTML-color" TypoScript datatype to RGB-values.
1579 * Default is 0,0,0
1580 *
1581 * @param string "HTML-color" data type string, eg. 'red', '#ffeedd' or '255,0,255'. You can also add a modifying operator afterwards. There are two options: "255,0,255 : 20" - will add 20 to values, result is "255,20,255". Or "255,0,255 : *1.23" which will multiply all RGB values with 1.23
1582 * @return array RGB values in key 0/1/2 of the array
1583 */
1584 function convertColor($string) {
1585 $col=array();
1586 $cParts = explode(':',$string,2);
1587
1588 // Finding the RGB definitions of the color:
1589 $string=$cParts[0];
1590 if (strstr($string,'#')) {
1591 $string = ereg_replace('[^A-Fa-f0-9]*','',$string);
1592 $col[]=HexDec(substr($string,0,2));
1593 $col[]=HexDec(substr($string,2,2));
1594 $col[]=HexDec(substr($string,4,2));
1595 } elseif (strstr($string,',')) {
1596 $string = ereg_replace('[^,0-9]*','',$string);
1597 $strArr = explode(',',$string);
1598 $col[]=intval($strArr[0]);
1599 $col[]=intval($strArr[1]);
1600 $col[]=intval($strArr[2]);
1601 } else {
1602 $string = strtolower(trim($string));
1603 if ($this->colMap[$string]) {
1604 $col = $this->colMap[$string];
1605 } else {
1606 $col = Array(0,0,0);
1607 }
1608 }
1609 // ... and possibly recalculating the value
1610 if (trim($cParts[1])) {
1611 $cParts[1]=trim($cParts[1]);
1612 if (substr($cParts[1],0,1)=='*') {
1613 $val=doubleval(substr($cParts[1],1));
1614 $col[0]=t3lib_div::intInRange($col[0]*$val,0,255);
1615 $col[1]=t3lib_div::intInRange($col[1]*$val,0,255);
1616 $col[2]=t3lib_div::intInRange($col[2]*$val,0,255);
1617 } else {
1618 $val=intval($cParts[1]);
1619 $col[0]=t3lib_div::intInRange($col[0]+$val,0,255);
1620 $col[1]=t3lib_div::intInRange($col[1]+$val,0,255);
1621 $col[2]=t3lib_div::intInRange($col[2]+$val,0,255);
1622 }
1623 }
1624 return $col;
1625 }
1626
1627 /**
1628 * Recode string
1629 * Used with text strings for fonts when languages has other character sets.
1630 *
1631 * @param string The text to recode
1632 * @return string The recoded string. Should be UTF-8 output. MAY contain entities (eg. &#123; or &#quot; which should render as real chars).
1633 */
1634 function recodeString($string) {
1635 // Recode string to UTF-8 from $this->nativeCharset:
1636 if ($this->nativeCharset && $this->nativeCharset!='utf-8') {
1637 $string = $this->csConvObj->utf8_encode($string,$this->nativeCharset); // Convert to UTF-8
1638 }
1639
1640 // Recode string accoding to TTFLocaleConv. Depreciated.
1641 if ($this->TTFLocaleConv) {
1642 $string = recode_string($this->TTFLocaleConv,$string);
1643 }
1644
1645 return $string;
1646 }
1647
1648 /**
1649 * Split a string into an array of individual characters
1650 * The function will look at $this->nativeCharset and if that is set, the input string is expected to be UTF-8 encoded, possibly with entities in it. Otherwise the string is supposed to be a single-byte charset which is just splitted by a for-loop.
1651 *
1652 * @param string The text string to spli
1653 * @return array Numerical array with a char as each value.
1654 */
1655 function singleChars($theText) {
1656 if ($this->nativeCharset) {
1657 return $this->csConvObj->utf8_to_numberarray($theText,1,1); // Get an array of separated UTF-8 chars
1658 } else {
1659 $output=array();
1660 $c=strlen($theText);
1661 for($a=0;$a<$c;$a++) {
1662 $output[]=substr($theText,$a,1);
1663 }
1664 return $output;
1665 }
1666 }
1667
1668 /**
1669 * Create an array with object position/boundaries based on input TypoScript configuration (such as the "align" property is used), the work area definition and $BB array
1670 *
1671 * @param array TypoScript configuration for a GIFBUILDER object
1672 * @param array Workarea definition
1673 * @param array BB (Bounding box) array. Not just used for TEXT objects but also for others
1674 * @return array [0]=x, [1]=y, [2]=w, [3]=h
1675 * @access private
1676 * @see copyGifOntoGif(), makeBox(), crop()
1677 */
1678 function objPosition($conf,$workArea,$BB) {
1679 // offset, align, valign, workarea
1680 $result=Array();
1681 $result[2] = $BB[0];
1682 $result[3] = $BB[1];
1683 $w=$workArea[2];
1684 $h=$workArea[3];
1685
1686 $align = explode(',',$conf['align']);
1687 $align[0] = strtolower(substr(trim($align[0]),0,1));
1688 $align[1] = strtolower(substr(trim($align[1]),0,1));
1689
1690 switch($align[0]) {
1691 case 'r':
1692 $result[0]=$w-$result[2];
1693 break;
1694 case 'c':
1695 $result[0] = round(($w-$result[2])/2);
1696 break;
1697 default:
1698 $result[0] = 0;
1699 break;
1700 }
1701 switch($align[1]) {
1702 case 'b':
1703 $result[1] = $h-$result[3]; // y pos
1704 break;
1705 case 'c':
1706 $result[1] = round(($h-$result[3])/2);
1707 break;
1708 default:
1709 $result[1]=0;
1710 break;
1711 }
1712 $result = $this->applyOffset($result,t3lib_div::intExplode(',',$conf['offset']));
1713 $result = $this->applyOffset($result,$workArea);
1714 return $result;
1715 }
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737 /***********************************
1738 *
1739 * Scaling, Dimensions of images
1740 *
1741 ***********************************/
1742
1743 /**
1744 * Converts $imagefile to another file in temp-dir of type $newExt (extension).
1745 *
1746 * @param string The image filepath
1747 * @param string New extension, eg. "gif", "png", "jpg", "tif". If $newExt is NOT set, the new imagefile will be of the original format. If newExt = 'WEB' then one of the web-formats is applied.
1748 * @param string Width. $w / $h is optional. If only one is given the image is scaled proportionally. If an 'm' exists in the $w or $h and if both are present the $w and $h is regarded as the Maximum w/h and the proportions will be kept
1749 * @param string Height. See $w
1750 * @param string Additional ImageMagick parameters.
1751 * @param string Refers to which frame-number to select in the image. '' or 0 will select the first frame, 1 will select the next and so on...
1752 * @param array An array with options passed to getImageScale (see this function).
1753 * @param boolean If set, then another image than the input imagefile MUST be returned. Otherwise you can risk that the input image is good enough regarding messures etc and is of course not rendered to a new, temporary file in typo3temp/. But this option will force it to.
1754 * @return array [0]/[1] is w/h, [2] is file extension and [3] is the filename.
1755 * @see getImageScale(), typo3/show_item.php, fileList_ext::renderImage(), tslib_cObj::getImgResource(), SC_tslib_showpic::show(), maskImageOntoImage(), copyImageOntoImage(), scale()
1756 */
1757 function imageMagickConvert($imagefile,$newExt='',$w='',$h='',$params='',$frame='',$options='',$mustCreate=0) {
1758 if ($this->NO_IMAGE_MAGICK) {
1759 // Returning file info right away
1760 return $this->getImageDimensions($imagefile);
1761 }
1762
1763 if($info=$this->getImageDimensions($imagefile)) {
1764 $newExt=strtolower(trim($newExt));
1765 if (!$newExt) { // If no extension is given the original extension is used
1766 $newExt = $info[2];
1767 }
1768 if ($newExt=='web') {
1769 if (t3lib_div::inList($this->webImageExt,$info[2])) {
1770 $newExt = $info[2];
1771 } else {
1772 $newExt = $this->gif_or_jpg($info[2],$info[0],$info[1]);
1773 if (!$params) {
1774 $params = $this->cmds[$newExt];
1775 }
1776 }
1777 }
1778 if (t3lib_div::inList($this->imageFileExt,$newExt)) {
1779 if (strstr($w.$h, 'm')) {$max=1;} else {$max=0;}
1780
1781 $data = $this->getImageScale($info,$w,$h,$options);
1782 $w=$data['origW'];
1783 $h=$data['origH'];
1784
1785 // if no convertion should be performed
1786 $wh_noscale = (!$w && !$h) || ($data[0]==$info[0] && $data[1]==$info[1]); // this flag is true if the width / height does NOT dictate the image to be scaled!! (that is if no w/h is given or if the destination w/h matches the original image-dimensions....
1787
1788 if ($wh_noscale && !$params && !$frame && $newExt==$info[2] && !$mustCreate) {
1789 $info[3] = $imagefile;
1790 return $info;
1791 }
1792 $info[0]=$data[0];
1793 $info[1]=$data[1];
1794
1795 $frame = $this->noFramePrepended ? '' : '['.intval($frame).']';
1796
1797 if (!$params) {
1798 $params = $this->cmds[$newExt];
1799 }
1800
1801 $command = $this->scalecmd.' '.$info[0].'x'.$info[1].'! '.$params.' ';
1802
1803 if ($this->alternativeOutputKey) {
1804 $theOutputName = t3lib_div::shortMD5($command.basename($imagefile).$this->alternativeOutputKey.$frame);
1805 } else {
1806 $theOutputName = t3lib_div::shortMD5($command.$imagefile.filemtime($imagefile).$frame);
1807 }
1808 if ($this->imageMagickConvert_forceFileNameBody) {
1809 $theOutputName = $this->imageMagickConvert_forceFileNameBody;
1810 $this->imageMagickConvert_forceFileNameBody='';
1811 }
1812
1813 // Making the temporary filename:
1814 $this->createTempSubDir('pics/');
1815 $output = $this->tempPath.'pics/'.$this->filenamePrefix.$theOutputName.'.'.$newExt;
1816
1817 // Register temporary filename:
1818 $GLOBALS['TEMP_IMAGES_ON_PAGE'][] = $output;
1819
1820 if (!$this->file_exists_typo3temp_file($output,$imagefile) || $this->dontCheckForExistingTempFile) {
1821 $this->imageMagickExec($imagefile.$frame,$output,$command);
1822 }
1823 if (@file_exists($output)) {
1824 $info[3] = $output;
1825 $info[2] = $newExt;
1826 if ($params) { // params could realisticly change som imagedata!
1827 $info=$this->getImageDimensions($info[3]);
1828 }
1829 if ($info[2]==$this->gifExtension && !$this->dontCompress) {
1830 t3lib_div::gif_compress($info[3],''); // Compress with IM (lzw) or GD (rle) (Workaround for the absence of lzw-compression in GD)
1831 }
1832 return $info;
1833 }
1834 }
1835 }
1836 }
1837
1838 /**
1839 * Gets the input image dimensions.
1840 *
1841 * @param string The image filepath
1842 * @return array Returns an array where [0]/[1] is w/h, [2] is extension and [3] is the filename.
1843 * @see imageMagickConvert(), tslib_cObj::getImgResource()
1844 */
1845 function getImageDimensions($imageFile) {
1846 ereg('([^\.]*)$',$imageFile,$reg);
1847 if (@file_exists($imageFile) && t3lib_div::inList($this->imageFileExt,strtolower($reg[0]))) {
1848 if ($returnArr = $this->getCachedImageDimensions($imageFile)) {
1849 return $returnArr;
1850 } else {
1851 if ($temp = @getImageSize($imageFile)) {
1852 $returnArr = Array($temp[0], $temp[1], strtolower($reg[0]), $imageFile);
1853 } else {
1854 $returnArr = $this->imageMagickIdentify($imageFile);
1855 }
1856 if ($returnArr) {
1857 $this->cacheImageDimensions($returnArr);
1858 return $returnArr;
1859 }
1860 }
1861 }
1862 return false;
1863 }
1864
1865 /**
1866 * Cache the result of the getImageDimensions function into the database. Does not check if the
1867 * file exists!
1868 *
1869 * @param array $identifyResult: Result of the getImageDimensions function
1870 * @return boolean True if operation was successful
1871 * @author Michael Stucki <mundaun@gmx.ch> / Robert Lemke <rl@robertlemke.de>
1872 */
1873 function cacheImageDimensions($identifyResult) {
1874 global $TYPO3_DB;
1875 // Create a md5 hash of the filename
1876 if (function_exists('md5_file')) {
1877 $md5Hash = md5_file($identifyResult[3]);
1878 } else {
1879 $md5Hash = md5 (t3lib_div::getURL($identifyResult[3]));
1880 }
1881 if ($md5Hash) {
1882 $fieldArr = array (
1883 'md5hash' => $md5Hash,
1884 'md5filename' => md5($identifyResult[3]),
1885 'tstamp' => time(),
1886 'filename' => $identifyResult[3],
1887 'imagewidth' => $identifyResult[0],
1888 'imageheight' => $identifyResult[1],
1889 );
1890 $TYPO3_DB->exec_INSERTquery('cache_imagesizes', $fieldArr);
1891 if (!$err = $TYPO3_DB->sql_error()) {
1892 return true;
1893 }
1894 }
1895 return false;
1896 }
1897
1898 /**
1899 * Fetch the cached imageDimensions from the MySQL database. Does not check if the image file exists!
1900 *
1901 * @param string The image filepath
1902 * @return array Returns an array where [0]/[1] is w/h, [2] is extension and [3] is the filename.
1903 * @author Michael Stucki <mundaun@gmx.ch> / Robert Lemke <rl@robertlemke.de>
1904 */
1905 function getCachedImageDimensions($imageFile) {
1906 global $TYPO3_DB;
1907 // Create a md5 hash of the filename
1908 if(function_exists('md5_file')) {
1909 $md5Hash = md5_file($imageFile);
1910 } else {
1911 $md5Hash = md5(t3lib_div::getURL ($imageFile));
1912 }
1913 ereg('([^\.]*)$',$imageFile,$reg);
1914 $res = $TYPO3_DB->exec_SELECTquery ('md5hash, imagewidth, imageheight', 'cache_imagesizes', 'md5filename="'.md5($imageFile).'"');
1915 if ($res) {
1916 if ($row = $TYPO3_DB->sql_fetch_assoc($res)) {
1917 if ($row['md5hash']!=$md5Hash) {
1918 // file has changed, delete the row
1919 $TYPO3_DB->exec_DELETEquery ('cache_imagesizes', 'md5hash="'.$TYPO3_DB->quoteStr($row['md5hash'], 'cache_imagesizes').'"');
1920 } else {
1921 return (array($row['imagewidth'], $row['imageheight'], strtolower($reg[0]), $imageFile));
1922 }
1923 }
1924 }
1925 return false;
1926 }
1927
1928 /**
1929 * Get numbers for scaling the image based on input
1930 *
1931 * @param array Current image information: Width, Height etc.
1932 * @param integer "required" width
1933 * @param integer "required" height
1934 * @param array Options: Keys are like "maxW", "maxH", "minW", "minH"
1935 * @return array
1936 * @access private
1937 * @see imageMagickConvert()
1938 */
1939 function getImageScale($info,$w,$h,$options) {
1940 if (strstr($w.$h, 'm')) {$max=1;} else {$max=0;}
1941 $w=intval($w);
1942 $h=intval($h);
1943 // if there are max-values...
1944 if ($options['maxW']) {
1945 if ($w) { // if width is given...
1946 if ($w>$options['maxW']) {
1947 $w=$options['maxW'];
1948 $max=1; // height should follow
1949 }
1950 } else {
1951 if ($info[0]>$options['maxW']) {
1952 $w=$options['maxW'];
1953 $max=1; // height should follow
1954 }
1955 }
1956 }
1957 if ($options['maxH']) {
1958 if ($h) { // if height is given...
1959 if ($h>$options['maxH']) {
1960 $h=$options['maxH'];
1961 $max=1; // height should follow
1962 }
1963 } else {
1964 if ($info[1]>$options['maxH']) { // Changed [0] to [1] 290801
1965 $h=$options['maxH'];
1966 $max=1; // height should follow
1967 }
1968 }
1969 }
1970 $out['origW']=$w;
1971 $out['origH']=$h;
1972 $out['max'] = $max;
1973
1974 if (!$this->mayScaleUp) {
1975 if ($w>$info[0]){$w=$info[0];}
1976 if ($h>$info[1]){$h=$info[1];}
1977 }
1978 if ($w || $h) { // if scaling should be performed
1979 if ($w && !$h) {
1980 $info[1] = ceil($info[1]*($w/$info[0]));
1981 $info[0] = $w;
1982 }
1983 if (!$w && $h) {
1984 $info[0] = ceil($info[0]*($h/$info[1]));
1985 $info[1] = $h;
1986 }
1987 if ($w && $h) {
1988 if ($max) {
1989 $ratio = $info[0]/$info[1];
1990 if ($h*$ratio > $w) {
1991 $h = round($w/$ratio);
1992 } else {
1993 $w = round($h*$ratio);
1994 }
1995 }
1996 $info[0] = $w;
1997 $info[1] = $h;
1998 }
1999 }
2000 $out[0]=$info[0];
2001 $out[1]=$info[1];
2002 // Set minimum-measures!
2003 if ($options['minW'] && $out[0]<$options['minW']) {
2004 if ($max && $out[0]) {
2005 $out[1]= round($out[1]*$options['minW']/$out[0]);
2006 }
2007 $out[0]=$options['minW'];
2008 }
2009 if ($options['minH'] && $out[1]<$options['minH']) {
2010 if ($max && $out[1]) {
2011 $out[0]= round($out[0]*$options['minH']/$out[1]);
2012 }
2013 $out[1]=$options['minH'];
2014 }
2015
2016 return $out;
2017 }
2018
2019 /**
2020 * Used to check if a certain process of scaling an image is already being carried out (can be logged in the SQL database)
2021 *
2022 * @param string Output imagefile
2023 * @param string Original basis file
2024 * @return boolean Returns true if the file is already being made; thus "true" means "Don't render the image again"
2025 * @access private
2026 */
2027 function file_exists_typo3temp_file($output,$orig='') {
2028 if ($this->enable_typo3temp_db_tracking) {
2029 if (@file_exists($output)) { // If file exists, then we return immediately
2030 return 1;
2031 } else { // If not, we look up in the cache_typo3temp_log table to see if there is a image being rendered right now.
2032 $md5Hash=md5($output);
2033 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('md5hash', 'cache_typo3temp_log', 'md5hash="'.$GLOBALS['TYPO3_DB']->quoteStr($md5Hash, 'cache_typo3temp_log').'" AND tstamp>'.(time()-30));
2034 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { // If there was a record, the image is being generated by another proces (we assume)
2035 if (is_object($GLOBALS['TSFE'])) $GLOBALS['TSFE']->set_no_cache(); // ...so we set no_cache, because we dont want this page (which will NOT display an image...!) to be cached! (Only a page with the correct image on...)
2036 if (is_object($GLOBALS['TT'])) $GLOBALS['TT']->setTSlogMessage('typo3temp_log: Assume this file is being rendered now: '.$output);
2037 return 2; // Return 'success - 2'
2038 } else { // If the current time is more than 30 seconds since this record was written, we clear the record, write a new and render the image.
2039
2040 $insertFields = array(
2041 'md5hash' => $md5Hash,
2042 'tstamp' => time(),
2043 'filename' => $output,
2044 'orig_filename' => $orig
2045 );
2046 $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_typo3temp_log', 'md5hash="'.$GLOBALS['TYPO3_DB']->quoteStr($md5Hash, 'cache_typo3temp_log').'"');
2047 $GLOBALS['TYPO3_DB']->exec_INSERTquery('cache_typo3temp_log', $insertFields);
2048
2049 if (is_object($GLOBALS['TT'])) $GLOBALS['TT']->setTSlogMessage('typo3temp_log: The row did not exist, so a new is written and file is being processed: '.$output);
2050 return 0;
2051 }
2052 }
2053 } else {
2054 return @file_exists($output);
2055 }
2056 }
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075 /***********************************
2076 *
2077 * ImageMagick API functions
2078 *
2079 ***********************************/
2080
2081 /**
2082 * Returns an array where [0]/[1] is w/h, [2] is extension and [3] is the filename.
2083 * Using ImageMagick
2084 *
2085 * @param string The absolute image filepath
2086 * @return array
2087 */
2088 function imageMagickIdentify($imagefile) {
2089 if (!$this->NO_IMAGE_MAGICK) {
2090 $frame = $this->noFramePrepended?'':'[0]';
2091 $cmd = $this->imageMagickPath.'identify '.$this->wrapFileName($imagefile).$frame;
2092 exec($cmd, $returnVal);
2093 $splitstring=$returnVal[0];
2094 $this->IM_commands[] = Array ('identify',$cmd,$returnVal[0]);
2095 if ($splitstring) {
2096 ereg('([^\.]*)$',$imagefile,$reg);
2097 $splitinfo = explode(' ', $splitstring);
2098 while (list($key,$val) = each($splitinfo)) {
2099 $temp = '';
2100 if ($val) {$temp = explode('x', $val);}
2101 if (intval($temp[0]) && intval($temp[1])) {
2102 $dim=$temp;
2103 break;
2104 }
2105 }
2106 if ($dim[0] && $dim[1]) {
2107 return Array($dim[0], $dim[1], strtolower($reg[0]), $imagefile);
2108 }
2109 }
2110 }
2111 }
2112
2113 /**
2114 * Executes a ImageMagick "convert" on two filenames, $input and $output using $params before them.
2115 * Can be used for many things, mostly scaling and effects.
2116 *
2117 * @param string The absolute image filepath, input file (read from)
2118 * @param string The absolute image filepath, output filename (written to)
2119 * @param string ImageMagick parameters
2120 * @return string The result of a call to PHP function "exec()"
2121 */
2122 function imageMagickExec($input,$output,$params) {
2123 if (!$this->NO_IMAGE_MAGICK) {
2124 $cmd = $this->imageMagickPath.'convert '.$params.' '.$this->wrapFileName($input).' '.$this->wrapFileName($output);
2125 $this->IM_commands[] = Array ($output,$cmd);
2126 return exec($cmd);
2127 }
2128 }
2129
2130 /**
2131 * Executes a ImageMagick "combine" (or composite in newer times) on four filenames - $input, $overlay and $mask as input files and $output as the output filename (written to)
2132 * Can be used for many things, mostly scaling and effects.
2133 *
2134 * @param string The absolute image filepath, bottom file
2135 * @param string The absolute image filepath, overlay file (top)
2136 * @param string The absolute image filepath, the mask file (grayscale)
2137 * @param string The absolute image filepath, output filename (written to)
2138 * @return void
2139 */
2140 function combineExec($input,$overlay,$mask,$output) {
2141 if (!$this->NO_IMAGE_MAGICK) {
2142 $cmd = $this->imageMagickPath.$this->combineScript.' -compose over '.$this->wrapFileName($input).' '.$this->wrapFileName($overlay).' '.$this->wrapFileName($mask).' '.$this->wrapFileName($output);
2143 $this->IM_commands[] = Array ($output,$cmd);
2144 exec($cmd);
2145 }
2146 }
2147
2148 /**
2149 * Wrapping the input filename in double-quotes
2150 *
2151 * @param string Input filename
2152 * @return string The output wrapped in "" (if there are spaces in the filepath)
2153 * @access private
2154 */
2155 function wrapFileName($inputName) {
2156 if (strstr($inputName,' ')) {
2157 $inputName='"'.$inputName.'"';
2158 }
2159 return $inputName;
2160 }
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184 /***********************************
2185 *
2186 * Various IO functions
2187 *
2188 ***********************************/
2189
2190 /**
2191 * Returns true if the input file existed
2192 *
2193 * @param string Input file to check
2194 * @return string Returns the filename if the file existed, otherwise empty.
2195 */
2196 function checkFile($file) {
2197 if (@is_file($file)) {
2198 return $file;
2199 } else {
2200 return '';
2201 }
2202 }
2203
2204 /**
2205 * Creates subdirectory in typo3temp/ if not already found.
2206 */
2207 function createTempSubDir($dirName) {
2208 // Making the temporary filename:
2209 if (!@is_dir(PATH_site.$this->tempPath.$dirName)) {
2210 return t3lib_div::mkdir(PATH_site.$this->tempPath.$dirName);
2211 }
2212 }
2213
2214 /**
2215 * Applies an ImageMagick parameter to a GDlib image pointer resource by writing the resource to file, performing an IM operation upon it and reading back the result into the ImagePointer.
2216 *
2217 * @param pointer The image pointer (reference)
2218 * @param string The ImageMagick parameters. Like effects, scaling etc.
2219 * @return void
2220 */
2221 function applyImageMagickToPHPGif(&$im, $command) {
2222 $tmpStr = $this->randomName();
2223 $theFile = $tmpStr.'.'.$this->gifExtension;
2224 $this->ImageGif($im, $theFile);
2225 $this->imageMagickExec($theFile,$theFile,$command);
2226 $tmpImg = $this->imageCreateFromGif($theFile);
2227 if ($tmpImg) {
2228 ImageDestroy($im);
2229 $im = $tmpImg;
2230 $this->w = imagesx($im);
2231 $this->h = imagesy($im);
2232 }
2233 if (!$this->dontUnlinkTempFiles) {
2234 unlink($theFile);
2235 }
2236 }
2237
2238 /**
2239 * Returns an image extension for an output image based on the number of pixels of the output and the file extension of the original file.
2240 * For example: If the number of pixels exceeds $this->pixelLimitGif (normally 10000) then it will be a "jpg" string in return.
2241 *
2242 * @param string The file extension, lowercase.
2243 * @param integer The width of the output image.
2244 * @param integer The height of the output image.
2245 * @return string The filename, either "jpg" or "gif"/"png" (whatever $this->gifExtension is set to.)
2246 */
2247 function gif_or_jpg($type,$w,$h) {
2248 if ($type=='ai' || $w*$h < $this->pixelLimitGif) {
2249 return $this->gifExtension;
2250 } else {
2251 return 'jpg';
2252 }
2253 }
2254
2255 /**
2256 * Writing the internal image pointer, $this->im, to file based on the extension of the input filename
2257 * Used in GIFBUILDER
2258 * Uses $this->setup['reduceColors'] for gif/png images and $this->setup['quality'] for jpg images to reduce size/quality if needed.
2259 *
2260 * @param string The filename to write to.
2261 * @return string Returns input filename
2262 * @see tslib_gifBuilder::gifBuild()
2263 */
2264 function output($file) {
2265 if ($file) {
2266 ereg('([^\.]*)$',$file,$reg);
2267 $ext=strtolower($reg[0]);
2268 switch($ext) {
2269 case $this->gifExtension:
2270 if ($this->ImageGif($this->im, $file)) {
2271 // ImageMagick operations
2272 if($this->setup['reduceColors']) {
2273 $this->imageMagickExec($file,$file,' -colors '.t3lib_div::intInRange($this->setup['reduceColors'],2,255));
2274 t3lib_div::gif_compress($file,''); // Compress with IM (lzw) or GD (rle) (Workaround for the absence of lzw-compression in GD)
2275 } else {
2276 t3lib_div::gif_compress($file, 'IM'); // Compress with IM! (adds extra compression, LZW from ImageMagick) (Workaround for the absence of lzw-compression in GD)
2277 }
2278 }
2279 break;
2280 case 'jpg':
2281 case 'jpeg':
2282 $tmpStr = $this->randomName();
2283 $theFile = $tmpStr.'.'.$this->gifExtension;
2284 if ($this->ImageGif($this->im, $theFile)) {
2285 // ImageMagick operations
2286 $operations='';
2287 if($this->setup['quality']) {
2288 $operations.=' -quality '.t3lib_div::intInRange($this->setup['quality'],10,100);
2289 }
2290 $this->imageMagickExec($theFile,$file,$operations);
2291 if (!$this->dontUnlinkTempFiles) {
2292 unlink($theFile);
2293 }
2294 }
2295 break;
2296 }
2297 $GLOBALS['TEMP_IMAGES_ON_PAGE'][]=$file;
2298 }
2299 return $file;
2300 }
2301
2302 /**
2303 * Destroy internal image pointer, $this->im
2304 *
2305 * @return void
2306 * @see tslib_gifBuilder::gifBuild()
2307 */
2308 function destroy() {
2309 ImageDestroy($this->im);
2310 }
2311
2312 /**
2313 * Returns Image Tag for input image information array.
2314 *
2315 * @param array Image information array, key 0/1 is width/height and key 3 is the src value
2316 * @return string Image tag for the input image information array.
2317 */
2318 function imgTag ($imgInfo) {
2319 return '<img src="'.$imgInfo[3].'" width="'.$imgInfo[0].'" height="'.$imgInfo[1].'" border="0" alt="" />';
2320 }
2321
2322 /**
2323 * Writes the input GDlib image pointer to file
2324 *
2325 * @param pointer The GDlib image resource pointer
2326 * @param string The filename to write to
2327 * @return mixed The output of either imageGif or imagePng based on whether the $this->gifExtension was set to "gif" or "png"
2328 * @see maskImageOntoImage(), scale(), output()
2329 */
2330 function ImageGif($destImg, $theImage) {
2331 imageinterlace ($destImg,0);
2332 if ($this->gifExtension=='gif') {
2333 return ImageGif($destImg, $theImage);
2334 }
2335 if ($this->gifExtension=='png') {
2336 return ImagePng($destImg, $theImage);
2337 }
2338 }
2339
2340 /**
2341 * Creates a new GDlib image resource based on the input image filename.
2342 * If it fails creating a image from the input file a blank gray image with the dimensions of the input image will be created instead.
2343 *
2344 * @param string Image filename
2345 * @return pointer Image Resource pointer
2346 */
2347 function imageCreateFromGif($sourceImg) {
2348 $imgInf = pathinfo($sourceImg);
2349 $ext = strtolower($imgInf['extension']);
2350
2351 // if ($ext=='gif' && (ImageTypes() & IMG_GIF)) {
2352 if ($ext=='gif' && function_exists('imagecreatefromgif')) {
2353 return imageCreateFromGif($sourceImg);
2354 }
2355 // if ($ext=='png' && (ImageTypes() & IMG_PNG)) {
2356 if ($ext=='png' && function_exists('imagecreatefrompng')) {
2357 return imageCreateFromPng($sourceImg);
2358 }
2359 // if (($ext=='jpg' || $ext=='jpeg') && (ImageTypes() & IMG_JPG)) {
2360 if (($ext=='jpg' || $ext=='jpeg') && function_exists('imagecreatefromjpeg')) {
2361 return imageCreateFromJpeg($sourceImg);
2362 }
2363
2364 // If non of the above:
2365 $i = @getimagesize($sourceImg);
2366 $im = imagecreate($i[0],$i[1]);
2367 ImageColorAllocate($im, 128,128,128);
2368 return $im;
2369 }
2370 }
2371
2372
2373 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_stdgraphic.php']) {
2374 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_stdgraphic.php']);
2375 }
2376 ?>