Disabling some or all controls in group field - controllable via pageTS
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_stdgraphic.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2008 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 * Standard graphical functions
29 *
30 * $Id$
31 * Revised for TYPO3 3.6 July/2003 by Kasper Skaarhoj
32 *
33 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
34 */
35 /**
36 * [CLASS/FUNCTION INDEX of SCRIPT]
37 *
38 *
39 *
40 * 155: class t3lib_stdGraphic
41 * 236: function init()
42 *
43 * SECTION: Layering images / "IMAGE" GIFBUILDER object
44 * 366: function maskImageOntoImage(&$im,$conf,$workArea)
45 * 436: function copyImageOntoImage(&$im,$conf,$workArea)
46 * 458: function copyGifOntoGif(&$im,$cpImg,$conf,$workArea)
47 * 537: function imagecopyresized(&$im, $cpImg, $Xstart, $Ystart, $cpImgCutX, $cpImgCutY, $w, $h, $w, $h)
48 *
49 * SECTION: Text / "TEXT" GIFBUILDER object
50 * 587: function makeText(&$im,$conf,$workArea)
51 * 707: function txtPosition($conf,$workArea,$BB)
52 * 761: function calcBBox($conf)
53 * 820: function addToMap($cords,$conf)
54 * 843: function calcTextCordsForMap($cords,$offset, $conf)
55 * 878: function SpacedImageTTFText(&$im, $fontSize, $angle, $x, $y, $Fcolor, $fontFile, $text, $spacing, $wordSpacing, $splitRenderingConf, $sF=1)
56 * 915: function fontResize($conf)
57 * 958: function ImageTTFBBoxWrapper($fontSize, $angle, $fontFile, $string, $splitRendering, $sF=1)
58 * 1005: function ImageTTFTextWrapper($im, $fontSize, $angle, $x, $y, $color, $fontFile, $string, $splitRendering,$sF=1)
59 * 1058: function splitString($string,$splitRendering,$fontSize,$fontFile)
60 * 1208: function calcWordSpacing($conf, $scaleFactor=1)
61 * 1227: function getTextScalFactor($conf)
62 *
63 * SECTION: Other GIFBUILDER objects related to TEXT
64 * 1262: function makeOutline(&$im,$conf,$workArea,$txtConf)
65 * 1291: function circleOffset($distance, $iterations)
66 * 1315: function makeEmboss(&$im,$conf,$workArea,$txtConf)
67 * 1337: function makeShadow(&$im,$conf,$workArea,$txtConf)
68 *
69 * SECTION: Other GIFBUILDER objects
70 * 1469: function makeBox(&$im,$conf,$workArea)
71 * 1491: function makeEffect(&$im, $conf)
72 * 1506: function IMparams($setup)
73 * 1589: function adjust(&$im, $conf)
74 * 1621: function crop(&$im,$conf)
75 * 1652: function scale(&$im,$conf)
76 * 1684: function setWorkArea($workArea)
77 *
78 * SECTION: Adjustment functions
79 * 1725: function autolevels(&$im)
80 * 1756: function outputLevels(&$im,$low,$high,$swap='')
81 * 1788: function inputLevels(&$im,$low,$high,$swap='')
82 * 1819: function reduceColors(&$im,$limit, $cols)
83 * 1832: function IMreduceColors($file, $cols)
84 *
85 * SECTION: GIFBUILDER Helper functions
86 * 1875: function prependAbsolutePath($fontFile)
87 * 1889: function v5_sharpen($factor)
88 * 1908: function v5_blur($factor)
89 * 1925: function randomName()
90 * 1938: function applyOffset($cords,$OFFSET)
91 * 1951: function convertColor($string)
92 * 2001: function recodeString($string)
93 * 2023: function singleChars($theText,$returnUnicodeNumber=FALSE)
94 * 2046: function objPosition($conf,$workArea,$BB)
95 *
96 * SECTION: Scaling, Dimensions of images
97 * 2125: function imageMagickConvert($imagefile,$newExt='',$w='',$h='',$params='',$frame='',$options='',$mustCreate=0)
98 * 2238: function getImageDimensions($imageFile)
99 * 2266: function cacheImageDimensions($identifyResult)
100 * 2298: function getCachedImageDimensions($imageFile)
101 * 2332: function getImageScale($info,$w,$h,$options)
102 * 2438: function file_exists_typo3temp_file($output,$orig='')
103 *
104 * SECTION: ImageMagick API functions
105 * 2499: function imageMagickIdentify($imagefile)
106 * 2534: function imageMagickExec($input,$output,$params)
107 * 2557: function combineExec($input,$overlay,$mask,$output, $handleNegation = false)
108 * 2588: function wrapFileName($inputName)
109 *
110 * SECTION: Various IO functions
111 * 2629: function checkFile($file)
112 * 2643: function createTempSubDir($dirName)
113 * 2665: function applyImageMagickToPHPGif(&$im, $command)
114 * 2691: function gif_or_jpg($type,$w,$h)
115 * 2708: function output($file)
116 * 2748: function destroy()
117 * 2758: function imgTag ($imgInfo)
118 * 2770: function ImageWrite($destImg, $theImage)
119 * 2808: function imageGif($destImg, $theImage)
120 * 2820: function imageCreateFromGif($sourceImg)
121 * 2831: function imageCreateFromFile($sourceImg)
122 * 2870: function imagecreate($w, $h)
123 * 2885: function hexColor($col)
124 * 2903: function unifyColors(&$img, $colArr, $closest = false)
125 *
126 * TOTAL FUNCTIONS: 66
127 * (This index is automatically created/updated by the extension "extdeveval")
128 *
129 */
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146 /**
147 * Class contains a bunch of cool functions for manipulating graphics with GDlib/Freetype and ImageMagick
148 * VERY OFTEN used with gifbuilder that extends this class and provides a TypoScript API to using these functions
149 *
150 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
151 * @package TYPO3
152 * @subpackage t3lib
153 * @see tslib_gifBuilder
154 */
155 class t3lib_stdGraphic {
156
157 // Internal configuration, set in init()
158 var $combineScript = 'combine'; // The ImageMagick filename used for combining two images. This name changed during the versions.
159 var $noFramePrepended=0; // If set, there is no frame pointer prepended to the filenames.
160 var $GD2=0; // Set, if the GDlib used is version 2.
161 var $imagecopyresized_fix=0; // If set, imagecopyresized will not be called directly. For GD2 (some PHP installs?)
162 var $gifExtension = 'gif'; // This should be changed to 'png' if you want this class to read/make PNG-files instead!
163 var $gdlibExtensions = ''; // File formats supported by gdlib. This variable get's filled in "init" method
164 var $truecolor = true; // Internal variable which get's used to determine wheter GDlib should use function truecolor pendants
165 var $png_truecolor = false; // Set to true if generated png's should be truecolor by default
166 var $truecolorColors = 0xffffff; // 16777216 Colors is the maximum value for PNG, JPEG truecolor images (24-bit, 8-bit / Channel)
167 var $TTFLocaleConv = ''; // Used to recode input to TTF-functions for other charsets.
168 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.
169 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!
170 var $webImageExt = 'gif,jpg,jpeg,png'; // Commalist of web image extensions (can be shown by a webbrowser)
171 var $maskNegate = ''; // Will be ' -negate' if ImageMagick ver 5.2+. See init();
172 var $NO_IM_EFFECTS = '';
173 var $cmds = Array (
174 'jpg' => '',
175 'jpeg' => '',
176 'gif' => '-colors 64',
177 'png' => '-colors 64'
178 );
179 var $NO_IMAGE_MAGICK = '';
180 var $V5_EFFECTS = 0;
181 var $im_version_4 = 0;
182 var $mayScaleUp = 1;
183
184 // Variables for testing, alternative usage etc.
185 var $filenamePrefix=''; // Filename prefix for images scaled in imageMagickConvert()
186 var $imageMagickConvert_forceFileNameBody=''; // Forcing the output filename of imageMagickConvert() to this value. However after calling imageMagickConvert() it will be set blank again.
187 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.
188 var $dontCompress=0; // Prevents imageMagickConvert() from compressing the gif-files with t3lib_div::gif_compress()
189 var $dontUnlinkTempFiles=0; // For debugging ONLY!
190 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...
191
192 // Internal:
193 var $IM_commands = Array(); // All ImageMagick commands executed is stored in this array for tracking. Used by the Install Tools Image section
194 var $workArea = Array();
195
196 // Constants:
197 var $tempPath = 'typo3temp/'; // The temp-directory where to store the files. Normally relative to PATH_site but is allowed to be the absolute path AS LONG AS it is a subdir to PATH_site.
198 var $absPrefix = ''; // Prefix for relative paths. Used in "show_item.php" script. Is prefixed the output file name IN imageMagickConvert()
199 var $scalecmd = '-geometry'; // ImageMagick scaling command; "-geometry" eller "-sample". Used in makeText() and imageMagickConvert()
200 var $im5fx_blurSteps='1x2,2x2,3x2,4x3,5x3,5x4,6x4,7x5,8x5,9x5'; // Used by v5_blur() to simulate 10 continuous steps of blurring
201 var $im5fx_sharpenSteps='1x2,2x2,3x2,2x3,3x3,4x3,3x4,4x4,4x5,5x5'; // Used by v5_sharpen() to simulate 10 continuous steps of sharpening.
202 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
203 var $colMap = Array ( // Array mapping HTML color names to RGB values.
204 'aqua' => Array(0,255,255),
205 'black' => Array(0,0,0),
206 'blue' => Array(0,0,255),
207 'fuchsia' => Array(255,0,255),
208 'gray' => Array(128,128,128),
209 'green' => Array(0,128,0),
210 'lime' => Array(0,255,0),
211 'maroon' => Array(128,0,0),
212 'navy' => Array(0,0,128),
213 'olive' => Array(128,128,0),
214 'purple' => Array(128,0,128),
215 'red' => Array(255,0,0),
216 'silver' => Array(192,192,192),
217 'teal' => Array(0,128,128),
218 'yellow' => Array(255,255,0),
219 'white' => Array(255,255,255)
220 );
221
222 /**
223 * Charset conversion object:
224 *
225 * @var t3lib_cs
226 */
227 var $csConvObj;
228 var $nativeCharset=''; // Is set to the native character set of the input strings.
229
230
231
232
233
234 /**
235 * Init function. Must always call this when using the class.
236 * This function will read the configuration information from $GLOBALS['TYPO3_CONF_VARS']['GFX'] can set some values in internal variables.
237 *
238 * @return void
239 */
240 function init() {
241 $gfxConf = $GLOBALS['TYPO3_CONF_VARS']['GFX'];
242
243 if (function_exists('imagecreatefromjpeg')&&function_exists('imagejpeg')) {
244 $this->gdlibExtensions .= ',jpg,jpeg';
245 }
246 if (function_exists('imagecreatefrompng')&&function_exists('imagepng')) {
247 $this->gdlibExtensions .= ',png';
248 }
249 if (function_exists('imagecreatefromgif')&&function_exists('imagegif')) {
250 $this->gdlibExtensions .= ',gif';
251 }
252 if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['png_truecolor']) {
253 $this->png_truecolor = true;
254 }
255 if (!$gfxConf['gdlib_2'] || !function_exists('imagecreatetruecolor')) {
256 $this->truecolor = false;
257 }
258 if (!$gfxConf['im_version_5']) {
259 $this->im_version_4 = true;
260 }
261
262 // When GIFBUILDER gets used in truecolor mode (GD2 required)
263 if ($this->truecolor) {
264 if ($this->png_truecolor) {
265 $this->cmds['png'] = ''; // No colors parameter if we generate truecolor images.
266 }
267 $this->cmds['gif'] = ''; // No colors parameter if we generate truecolor images.
268 }
269
270 // Setting default JPG parameters:
271 $this->jpegQuality = t3lib_div::intInRange($gfxConf['jpg_quality'], 10, 100, 75);
272 $this->cmds['jpg'] = $this->cmds['jpeg'] = '-colorspace RGB -sharpen 50 -quality '.$this->jpegQuality;
273
274 if ($gfxConf['im_combine_filename']) $this->combineScript=$gfxConf['im_combine_filename'];
275 if ($gfxConf['im_noFramePrepended']) $this->noFramePrepended=1;
276
277 if ($gfxConf['gdlib_2']) {
278 $this->GD2 = 1;
279 $this->imagecopyresized_fix = $gfxConf['gdlib_2']==='no_imagecopyresized_fix' ? 0 : 1;
280 }
281 if ($gfxConf['gdlib_png']) {
282 $this->gifExtension='png';
283 }
284 if ($gfxConf['TTFLocaleConv']) {
285 $this->TTFLocaleConv = $gfxConf['TTFLocaleConv'];
286 }
287 if ($gfxConf['enable_typo3temp_db_tracking']) {
288 $this->enable_typo3temp_db_tracking = $gfxConf['enable_typo3temp_db_tracking'];
289 }
290
291 $this->imageFileExt = $gfxConf['imagefile_ext'];
292
293 // This should be set if ImageMagick ver. 5+ is used.
294 if ($gfxConf['im_negate_mask']) {
295 // Boolean. Indicates if the mask images should be inverted first.
296 // This depends of the ImageMagick version. Below ver. 5.1 this should be false.
297 // Above ImageMagick version 5.2+ it should be true.
298 // Just set the flag if the masks works opposite the intension!
299 $this->maskNegate = ' -negate';
300 }
301 if ($gfxConf['im_no_effects']) {
302 // Boolean. This is necessary if using ImageMagick 5+.
303 // Approved version for using effects is version 4.2.9.
304 // Effects in Imagemagick 5+ tends to render very slowly!!
305 // - therefore must be disabled in order not to perform sharpen, blurring and such.
306 $this->NO_IM_EFFECTS = 1;
307
308 $this->cmds['jpg'] = $this->cmds['jpeg'] = '-colorspace RGB -quality '.$this->jpegQuality;
309 }
310 // ... but if 'im_v5effects' is set, don't care about 'im_no_effects'
311 if ($gfxConf['im_v5effects']) {
312 $this->NO_IM_EFFECTS = 0;
313 $this->V5_EFFECTS = 1;
314
315 if ($gfxConf['im_v5effects']>0) {
316 $this->cmds['jpg'] = $this->cmds['jpeg'] = '-colorspace RGB -quality '.intval($gfxConf['jpg_quality']).$this->v5_sharpen(10);
317 }
318 }
319
320 if (!$gfxConf['im']) {
321 $this->NO_IMAGE_MAGICK = 1;
322 }
323 // Secures that images are not scaled up.
324 if ($gfxConf['im_noScaleUp']) {
325 $this->mayScaleUp=0;
326 }
327
328 if (TYPO3_MODE=='FE') {
329 $this->csConvObj = &$GLOBALS['TSFE']->csConvObj;
330 } elseif(is_object($GLOBALS['LANG'])) { // BE assumed:
331 $this->csConvObj = &$GLOBALS['LANG']->csConvObj;
332 } else { // The object may not exist yet, so we need to create it now. Happens in the Install Tool for example.
333 $this->csConvObj = t3lib_div::makeInstance('t3lib_cs');
334 }
335 $this->nativeCharset = $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'];
336 }
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353 /*************************************************
354 *
355 * Layering images / "IMAGE" GIFBUILDER object
356 *
357 *************************************************/
358
359 /**
360 * Implements the "IMAGE" GIFBUILDER object, when the "mask" property is true.
361 * 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
362 * The operation involves ImageMagick for combining.
363 *
364 * @param pointer GDlib image pointer
365 * @param array TypoScript array with configuration for the GIFBUILDER object.
366 * @param array The current working area coordinates.
367 * @return void
368 * @see tslib_gifBuilder::make()
369 */
370 function maskImageOntoImage(&$im,$conf,$workArea) {
371 if ($conf['file'] && $conf['mask']) {
372 $imgInf = pathinfo($conf['file']);
373 $imgExt = strtolower($imgInf['extension']);
374 if (!t3lib_div::inList($this->gdlibExtensions, $imgExt)) {
375 $BBimage = $this->imageMagickConvert($conf['file'],$this->gifExtension,'','','','','');
376 } else {
377 $BBimage = $this->getImageDimensions($conf['file']);
378 }
379 $maskInf = pathinfo($conf['mask']);
380 $maskExt = strtolower($maskInf['extension']);
381 if (!t3lib_div::inList($this->gdlibExtensions, $maskExt)) {
382 $BBmask = $this->imageMagickConvert($conf['mask'],$this->gifExtension,'','','','','');
383 } else {
384 $BBmask = $this->getImageDimensions($conf['mask']);
385 }
386 if ($BBimage && $BBmask) {
387 $w = imagesx($im);
388 $h = imagesy($im);
389 $tmpStr = $this->randomName();
390 $theImage = $tmpStr.'_img.'.$this->gifExtension;
391 $theDest = $tmpStr.'_dest.'.$this->gifExtension;
392 $theMask = $tmpStr.'_mask.'.$this->gifExtension;
393 // prepare overlay image
394 $cpImg = $this->imageCreateFromFile($BBimage[3]);
395 $destImg = $this->imagecreate($w,$h);
396 $Bcolor = ImageColorAllocate($destImg, 0,0,0);
397 ImageFilledRectangle($destImg, 0, 0, $w, $h, $Bcolor);
398 $this->copyGifOntoGif($destImg,$cpImg,$conf,$workArea);
399 $this->ImageWrite($destImg, $theImage);
400 imageDestroy($cpImg);
401 imageDestroy($destImg);
402 // prepare mask image
403 $cpImg = $this->imageCreateFromFile($BBmask[3]);
404 $destImg = $this->imagecreate($w,$h);
405 $Bcolor = ImageColorAllocate($destImg, 0, 0, 0);
406 ImageFilledRectangle($destImg, 0, 0, $w, $h, $Bcolor);
407 $this->copyGifOntoGif($destImg,$cpImg,$conf,$workArea);
408 $this->ImageWrite($destImg, $theMask);
409 imageDestroy($cpImg);
410 imageDestroy($destImg);
411 // mask the images
412 $this->ImageWrite($im, $theDest);
413
414 $this->combineExec($theDest,$theImage,$theMask,$theDest, true); // Let combineExec handle maskNegation
415
416 $backIm = $this->imageCreateFromFile($theDest); // The main image is loaded again...
417 if ($backIm) { // ... and if nothing went wrong we load it onto the old one.
418 ImageColorTransparent($backIm,-1);
419 $im = $backIm;
420 }
421 // unlink files from process
422 if (!$this->dontUnlinkTempFiles) {
423 unlink($theDest);
424 unlink($theImage);
425 unlink($theMask);
426 }
427 }
428 }
429 }
430
431 /**
432 * Implements the "IMAGE" GIFBUILDER object, when the "mask" property is false (using only $conf['file'])
433 *
434 * @param pointer GDlib image pointer
435 * @param array TypoScript array with configuration for the GIFBUILDER object.
436 * @param array The current working area coordinates.
437 * @return void
438 * @see tslib_gifBuilder::make(), maskImageOntoImage()
439 */
440 function copyImageOntoImage(&$im,$conf,$workArea) {
441 if ($conf['file']) {
442 if (!t3lib_div::inList($this->gdlibExtensions, $conf['BBOX'][2])) {
443 $conf['BBOX']=$this->imageMagickConvert($conf['BBOX'][3],$this->gifExtension,'','','','','');
444 $conf['file']=$conf['BBOX'][3];
445 }
446 $cpImg = $this->imageCreateFromFile($conf['file']);
447 $this->copyGifOntoGif($im,$cpImg,$conf,$workArea);
448 imageDestroy($cpImg);
449 }
450 }
451
452 /**
453 * Copies two GDlib image pointers onto each other, using TypoScript configuration from $conf and the input $workArea definition.
454 *
455 * @param pointer GDlib image pointer, destination (bottom image)
456 * @param pointer GDlib image pointer, source (top image)
457 * @param array TypoScript array with the properties for the IMAGE GIFBUILDER object. Only used for the "tile" property value.
458 * @param array Work area
459 * @return void Works on the $im image pointer
460 * @access private
461 */
462 function copyGifOntoGif(&$im,$cpImg,$conf,$workArea) {
463 $cpW = imagesx($cpImg);
464 $cpH = imagesy($cpImg);
465 $tile = t3lib_div::intExplode(',',$conf['tile']);
466 $tile[0] = t3lib_div::intInRange($tile[0],1,20);
467 $tile[1] = t3lib_div::intInRange($tile[1],1,20);
468 $cpOff = $this->objPosition($conf,$workArea,Array($cpW*$tile[0],$cpH*$tile[1]));
469
470 for ($xt=0;$xt<$tile[0];$xt++) {
471 $Xstart=$cpOff[0]+$cpW*$xt;
472 if ($Xstart+$cpW > $workArea[0]) { // if this image is inside of the workArea, then go on
473 // X:
474 if ($Xstart < $workArea[0]) {
475 $cpImgCutX = $workArea[0]-$Xstart;
476 $Xstart = $workArea[0];
477 } else {
478 $cpImgCutX = 0;
479 }
480 $w = $cpW-$cpImgCutX;
481 if ($Xstart > $workArea[0]+$workArea[2]-$w) {
482 $w = $workArea[0]+$workArea[2]-$Xstart;
483 }
484 if ($Xstart < $workArea[0]+$workArea[2]) { // if this image is inside of the workArea, then go on
485 // Y:
486 for ($yt=0;$yt<$tile[1];$yt++) {
487 $Ystart=$cpOff[1]+$cpH*$yt;
488 if ($Ystart+$cpH > $workArea[1]) { // if this image is inside of the workArea, then go on
489 if ($Ystart < $workArea[1]) {
490 $cpImgCutY = $workArea[1]-$Ystart;
491 $Ystart = $workArea[1];
492 } else {
493 $cpImgCutY = 0;
494 }
495 $h = $cpH-$cpImgCutY;
496 if ($Ystart > $workArea[1]+$workArea[3]-$h) {
497 $h = $workArea[1]+$workArea[3]-$Ystart;
498 }
499 if ($Ystart < $workArea[1]+$workArea[3]) { // if this image is inside of the workArea, then go on
500 $this->imagecopyresized($im, $cpImg, $Xstart, $Ystart, $cpImgCutX, $cpImgCutY, $w, $h, $w, $h);
501 }
502 }
503 } // Y:
504 }
505 }
506 }
507 }
508
509 /**
510 * Alternative function for using the similar PHP function imagecopyresized(). Used for GD2 only.
511 *
512 * OK, the reason for this stupid fix is the following story:
513 * GD1.x was capable of copying two images together and combining their palettes! GD2 is apparently not.
514 * With GD2 only the palette of the dest-image is used which mostly results in totally black images when trying to
515 * copy a color-ful image onto the destination.
516 * The GD2-fix is to
517 * 1) Create a blank TRUE-COLOR image
518 * 2) Copy the destination image onto that one
519 * 3) Then do the actual operation; Copying the source (top image) onto that
520 * 4) ... and return the result pointer.
521 * 5) Reduce colors (if we do not, the result may become strange!)
522 * It works, but the resulting images is now a true-color PNG which may be very large.
523 * So, why not use 'imagetruecolortopalette ($im, TRUE, 256)' - well because it does NOT WORK! So simple is that.
524 *
525 * For parameters, see PHP function "imagecopyresized()"
526 *
527 * @param pointer see PHP function "imagecopyresized()"
528 * @param pointer see PHP function "imagecopyresized()"
529 * @param integer see PHP function "imagecopyresized()"
530 * @param integer see PHP function "imagecopyresized()"
531 * @param integer see PHP function "imagecopyresized()"
532 * @param integer see PHP function "imagecopyresized()"
533 * @param integer see PHP function "imagecopyresized()"
534 * @param integer see PHP function "imagecopyresized()"
535 * @param integer see PHP function "imagecopyresized()"
536 * @param integer see PHP function "imagecopyresized()"
537 * @return void
538 * @access private
539 * @see t3lib_iconWorks::imagecopyresized()
540 */
541 function imagecopyresized(&$im, $cpImg, $Xstart, $Ystart, $cpImgCutX, $cpImgCutY, $w, $h, $w, $h) {
542 if ($this->imagecopyresized_fix) {
543 $im_base = $this->imagecreate(imagesx($im), imagesy($im)); // Make true color image
544 imagecopyresized($im_base, $im, 0,0,0,0, imagesx($im),imagesy($im),imagesx($im),imagesy($im)); // Copy the source image onto that
545 imagecopyresized($im_base, $cpImg, $Xstart, $Ystart, $cpImgCutX, $cpImgCutY, $w, $h, $w, $h); // Then copy the $cpImg onto that (the actual operation!)
546 $im = $im_base; // Set pointer
547 if (!$this->truecolor) {
548 $this->makeEffect($im, Array('value'=>'colors='.t3lib_div::intInRange($this->setup['reduceColors'], 256, $this->truecolorColors, 256))); // Reduce to "reduceColors" colors - make SURE that IM is working then!
549 }
550 } else {
551 imagecopyresized($im, $cpImg, $Xstart, $Ystart, $cpImgCutX, $cpImgCutY, $w, $h, $w, $h);
552 }
553 }
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576 /********************************
577 *
578 * Text / "TEXT" GIFBUILDER object
579 *
580 ********************************/
581
582 /**
583 * Implements the "TEXT" GIFBUILDER object
584 *
585 * @param pointer GDlib image pointer
586 * @param array TypoScript array with configuration for the GIFBUILDER object.
587 * @param array The current working area coordinates.
588 * @return void
589 * @see tslib_gifBuilder::make()
590 */
591 function makeText(&$im,$conf,$workArea) {
592 // Spacing
593 list($spacing,$wordSpacing) = $this->calcWordSpacing($conf);
594 // Position
595 $txtPos = $this->txtPosition($conf,$workArea,$conf['BBOX']);
596 $theText = $this->recodeString($conf['text']);
597
598 if ($conf['imgMap'] && is_array($conf['imgMap.'])) {
599 $this->addToMap($this->calcTextCordsForMap($conf['BBOX'][2],$txtPos, $conf['imgMap.']), $conf['imgMap.']);
600 }
601 if (!$conf['hideButCreateMap']) {
602 // Font Color:
603 $cols=$this->convertColor($conf['fontColor']);
604 // NiceText is calculated
605 if (!$conf['niceText']) {
606 // Font Color is reserved:
607 if (!$this->truecolor) {
608 $reduce = t3lib_div::intInRange($this->setup['reduceColors'], 256, $this->truecolorColors, 256);
609 $this->reduceColors($im, $reduce-49, $reduce-50); // If "reduce-49" colors (or more) are used reduce them to "reduce-50"
610 }
611 $Fcolor = ImageColorAllocate($im, $cols[0],$cols[1],$cols[2]);
612 // antiAliasing is setup:
613 $Fcolor = ($conf['antiAlias']) ? $Fcolor : -$Fcolor;
614
615 for ($a=0; $a<$conf['iterations']; $a++) {
616 if ($spacing || $wordSpacing) { // If any kind of spacing applys, we use this function:
617 $this->SpacedImageTTFText($im, $conf['fontSize'], $conf['angle'], $txtPos[0], $txtPos[1], $Fcolor, t3lib_stdGraphic::prependAbsolutePath($conf['fontFile']), $theText, $spacing, $wordSpacing, $conf['splitRendering.']);
618 } else {
619 $this->ImageTTFTextWrapper($im, $conf['fontSize'], $conf['angle'], $txtPos[0], $txtPos[1], $Fcolor, $conf['fontFile'], $theText, $conf['splitRendering.']);
620 }
621 }
622 } else { // NICETEXT::
623 // options anti_aliased and iterations is NOT available when doing this!!
624 $w = imagesx($im);
625 $h = imagesy($im);
626 $tmpStr = $this->randomName();
627
628 $fileMenu = $tmpStr.'_menuNT.'.$this->gifExtension;
629 $fileColor = $tmpStr.'_colorNT.'.$this->gifExtension;
630 $fileMask = $tmpStr.'_maskNT.'.$this->gifExtension;
631 // Scalefactor
632 $sF = t3lib_div::intInRange($conf['niceText.']['scaleFactor'],2,5);
633 $newW = ceil($sF*imagesx($im));
634 $newH = ceil($sF*imagesy($im));
635
636 // Make mask
637 $maskImg = $this->imagecreate($newW, $newH);
638 $Bcolor = ImageColorAllocate($maskImg, 255,255,255);
639 ImageFilledRectangle($maskImg, 0, 0, $newW, $newH, $Bcolor);
640 $Fcolor = ImageColorAllocate($maskImg, 0,0,0);
641 if ($spacing || $wordSpacing) { // If any kind of spacing applys, we use this function:
642 $this->SpacedImageTTFText($maskImg, $conf['fontSize'], $conf['angle'], $txtPos[0], $txtPos[1], $Fcolor, t3lib_stdGraphic::prependAbsolutePath($conf['fontFile']), $theText, $spacing, $wordSpacing, $conf['splitRendering.'],$sF);
643 } else {
644 $this->ImageTTFTextWrapper($maskImg, $conf['fontSize'], $conf['angle'], $txtPos[0], $txtPos[1], $Fcolor, $conf['fontFile'], $theText, $conf['splitRendering.'],$sF);
645 }
646 $this->ImageWrite($maskImg, $fileMask);
647 ImageDestroy($maskImg);
648
649 // Downscales the mask
650 if ($this->NO_IM_EFFECTS) {
651 if ($this->maskNegate) {
652 $command = trim($this->scalecmd.' '.$w.'x'.$h.'!'); // Negate 2 times makes no negate...
653 } else {
654 $command = trim($this->scalecmd.' '.$w.'x'.$h.'! -negate');
655 }
656 } else {
657 if ($this->maskNegate) {
658 $command = trim($conf['niceText.']['before'].' '.$this->scalecmd.' '.$w.'x'.$h.'! '.$conf['niceText.']['after']);
659 } else {
660 $command = trim($conf['niceText.']['before'].' '.$this->scalecmd.' '.$w.'x'.$h.'! '.$conf['niceText.']['after'].' -negate');
661 }
662 if ($conf['niceText.']['sharpen']) {
663 if ($this->V5_EFFECTS) {
664 $command.=$this->v5_sharpen($conf['niceText.']['sharpen']);
665 } else {
666 $command.=' -sharpen '.t3lib_div::intInRange($conf['niceText.']['sharpen'],1,99);
667 }
668 }
669 }
670
671 $this->imageMagickExec($fileMask,$fileMask,$command);
672
673 // Make the color-file
674 $colorImg = $this->imagecreate($w,$h);
675 $Ccolor = ImageColorAllocate($colorImg, $cols[0],$cols[1],$cols[2]);
676 ImageFilledRectangle($colorImg, 0, 0, $w, $h, $Ccolor);
677 $this->ImageWrite($colorImg, $fileColor);
678 ImageDestroy($colorImg);
679
680 // The mask is applied
681 $this->ImageWrite($im, $fileMenu); // The main pictures is saved temporarily
682
683 $this->combineExec($fileMenu,$fileColor,$fileMask, $fileMenu);
684
685 $backIm = $this->imageCreateFromFile($fileMenu); // The main image is loaded again...
686 if ($backIm) { // ... and if nothing went wrong we load it onto the old one.
687 ImageColorTransparent($backIm,-1);
688 $im = $backIm;
689 }
690
691 // Deleting temporary files;
692 if (!$this->dontUnlinkTempFiles) {
693 unlink($fileMenu);
694 unlink($fileColor);
695 unlink($fileMask);
696 }
697 }
698 }
699 }
700
701 /**
702 * Calculates text position for printing the text onto the image based on configuration like alignment and workarea.
703 *
704 * @param array TypoScript array for the TEXT GIFBUILDER object
705 * @param array Workarea definition
706 * @param array Bounding box information, was set in tslib_gifBuilder::start()
707 * @return array [0]=x, [1]=y, [2]=w, [3]=h
708 * @access private
709 * @see makeText()
710 */
711 function txtPosition($conf,$workArea,$BB) {
712 $bbox = $BB[2];
713 $angle=intval($conf['angle'])/180*pi();
714 $conf['angle']=0;
715 $straightBB = $this->calcBBox($conf);
716
717 // offset, align, valign, workarea
718 $result=Array(); // [0]=x, [1]=y, [2]=w, [3]=h
719 $result[2] = $BB[0];
720 $result[3] = $BB[1];
721 $w=$workArea[2];
722 $h=$workArea[3];
723
724 switch($conf['align']) {
725 case 'right':
726 case 'center':
727 $factor=abs(cos($angle));
728 $sign=(cos($angle)<0)?-1:1;
729 $len1 = $sign*$factor*$straightBB[0];
730 $len2= $sign*$BB[0];
731 $result[0] = $w-ceil($len2*$factor+(1-$factor)*$len1);
732
733 $factor=abs(sin($angle));
734 $sign=(sin($angle)<0)?-1:1;
735 $len1= $sign*$factor*$straightBB[0];
736 $len2= $sign*$BB[1];
737 $result[1]=ceil($len2*$factor+(1-$factor)*$len1);
738 break;
739 }
740 switch($conf['align']) {
741 case 'right':
742 break;
743 case 'center':
744 $result[0] = round(($result[0])/2);
745 $result[1] = round(($result[1])/2);
746 break;
747 default:
748 $result[0]=0;
749 $result[1]=0;
750 break;
751 }
752 $result = $this->applyOffset($result,t3lib_div::intExplode(',',$conf['offset']));
753 $result = $this->applyOffset($result,$workArea);
754 return $result;
755 }
756
757 /**
758 * Calculates bounding box information for the TEXT GIFBUILDER object.
759 *
760 * @param array TypoScript array for the TEXT GIFBUILDER object
761 * @return array Array with three keys [0]/[1] being x/y and [2] being the bounding box array
762 * @access private
763 * @see txtPosition(), tslib_gifBuilder::start()
764 */
765 function calcBBox($conf) {
766 $sF = $this->getTextScalFactor($conf);
767 list($spacing,$wordSpacing) = $this->calcWordSpacing($conf, $sF);
768 $theText = $this->recodeString($conf['text']);
769
770 $charInf = $this->ImageTTFBBoxWrapper($conf['fontSize'], $conf['angle'], $conf['fontFile'], $theText, $conf['splitRendering.'],$sF);
771 $theBBoxInfo = $charInf;
772 if ($conf['angle']) {
773 $xArr = Array($charInf[0],$charInf[2],$charInf[4],$charInf[6]);
774 $yArr = Array($charInf[1],$charInf[3],$charInf[5],$charInf[7]);
775 $x=max($xArr)-min($xArr);
776 $y=max($yArr)-min($yArr);
777 } else {
778 $x = ($charInf[2]-$charInf[0]);
779 $y = ($charInf[1]-$charInf[7]);
780 }
781 if ($spacing || $wordSpacing) { // If any kind of spacing applys, we use this function:
782 $x=0;
783 if (!$spacing && $wordSpacing) {
784 $bits = explode(' ',$theText);
785 while(list(,$word)=each($bits)) {
786 $word.=' ';
787 $wordInf = $this->ImageTTFBBoxWrapper($conf['fontSize'], $conf['angle'], $conf['fontFile'], $word, $conf['splitRendering.'],$sF);
788 $wordW = ($wordInf[2]-$wordInf[0]);
789 $x+=$wordW+$wordSpacing;
790 }
791 } else {
792 $utf8Chars = $this->singleChars($theText);
793 // For each UTF-8 char, do:
794 foreach($utf8Chars as $char) {
795 $charInf = $this->ImageTTFBBoxWrapper($conf['fontSize'], $conf['angle'], $conf['fontFile'], $char, $conf['splitRendering.'],$sF);
796 $charW = ($charInf[2]-$charInf[0]);
797 $x+=$charW+(($char==' ')?$wordSpacing:$spacing);
798 }
799 }
800 }
801
802 if ($sF>1) {
803 $x = ceil($x/$sF);
804 $y = ceil($y/$sF);
805 if (is_array($theBBoxInfo)) {
806 reset($theBBoxInfo);
807 while(list($key,$val)=each($theBBoxInfo)) {
808 $theBBoxInfo[$key]=ceil($theBBoxInfo[$key]/$sF);
809 }
810 }
811 }
812 return array($x,$y,$theBBoxInfo);
813 }
814
815 /**
816 * Adds an <area> tag to the internal variable $this->map which is used to accumulate the content for an ImageMap
817 *
818 * @param array Coordinates for a polygon image map as created by ->calcTextCordsForMap()
819 * @param array Configuration for "imgMap." property of a TEXT GIFBUILDER object.
820 * @return void
821 * @access private
822 * @see makeText(), calcTextCordsForMap()
823 */
824 function addToMap($cords,$conf) {
825 $JS = $conf['noBlur'] ? '' : ' onfocus="blurLink(this);"';
826
827 $this->map.='<area'.
828 ' shape="poly"'.
829 ' coords="'.implode(',',$cords).'"'.
830 ' href="'.htmlspecialchars($conf['url']).'"'.
831 ($conf['target'] ? ' target="'.htmlspecialchars($conf['target']).'"' : '').
832 $JS.
833 (strlen($conf['titleText']) ? ' title="'.htmlspecialchars($conf['titleText']).'"' : '').
834 ' alt="'.htmlspecialchars($conf['altText']).'" />';
835 }
836
837 /**
838 * Calculating the coordinates for a TEXT string on an image map. Used in an <area> tag
839 *
840 * @param array Coordinates (from BBOX array)
841 * @param array Offset array
842 * @param array Configuration for "imgMap." property of a TEXT GIFBUILDER object.
843 * @return array
844 * @access private
845 * @see makeText(), calcTextCordsForMap()
846 */
847 function calcTextCordsForMap($cords,$offset, $conf) {
848 $pars = t3lib_div::intExplode(',',$conf['explode'].',');
849
850 $newCords[0] = $cords[0]+$offset[0]-$pars[0];
851 $newCords[1] = $cords[1]+$offset[1]+$pars[1];
852 $newCords[2] = $cords[2]+$offset[0]+$pars[0];
853 $newCords[3] = $cords[3]+$offset[1]+$pars[1];
854 $newCords[4] = $cords[4]+$offset[0]+$pars[0];
855 $newCords[5] = $cords[5]+$offset[1]-$pars[1];
856 $newCords[6] = $cords[6]+$offset[0]-$pars[0];
857 $newCords[7] = $cords[7]+$offset[1]-$pars[1];
858
859 return $newCords;
860 }
861
862 /**
863 * Printing text onto an image like the PHP function imageTTFText does but in addition it offers options for spacing of letters and words.
864 * Spacing is done by printing one char at a time and this means that the spacing is rather uneven and probably not very nice.
865 * See
866 *
867 * @param pointer (See argument for PHP function imageTTFtext())
868 * @param integer (See argument for PHP function imageTTFtext())
869 * @param integer (See argument for PHP function imageTTFtext())
870 * @param integer (See argument for PHP function imageTTFtext())
871 * @param integer (See argument for PHP function imageTTFtext())
872 * @param integer (See argument for PHP function imageTTFtext())
873 * @param string (See argument for PHP function imageTTFtext())
874 * @param string (See argument for PHP function imageTTFtext()). UTF-8 string, possibly with entities in.
875 * @param integer The spacing of letters in pixels
876 * @param integer The spacing of words in pixels
877 * @param array $splitRenderingConf array
878 * @param integer Scale factor
879 * @return void
880 * @access private
881 */
882 function SpacedImageTTFText(&$im, $fontSize, $angle, $x, $y, $Fcolor, $fontFile, $text, $spacing, $wordSpacing, $splitRenderingConf, $sF=1) {
883
884 $spacing*=$sF;
885 $wordSpacing*=$sF;
886
887 if (!$spacing && $wordSpacing) {
888 $bits = explode(' ',$text);
889 reset($bits);
890 while(list(,$word)=each($bits)) {
891 $word.=' ';
892 $word = $word;
893 $wordInf = $this->ImageTTFBBoxWrapper($fontSize, $angle, $fontFile, $word, $splitRenderingConf ,$sF);
894 $wordW = ($wordInf[2]-$wordInf[0]);
895 $this->ImageTTFTextWrapper($im, $fontSize, $angle, $x, $y, $Fcolor, $fontFile, $word, $splitRenderingConf, $sF);
896 $x+=$wordW+$wordSpacing;
897 }
898 } else {
899 $utf8Chars = $this->singleChars($text);
900 // For each UTF-8 char, do:
901 foreach($utf8Chars as $char) {
902 $charInf = $this->ImageTTFBBoxWrapper($fontSize, $angle, $fontFile, $char, $splitRenderingConf, $sF);
903 $charW = ($charInf[2]-$charInf[0]);
904 $this->ImageTTFTextWrapper($im, $fontSize, $angle, $x, $y, $Fcolor, $fontFile, $char, $splitRenderingConf, $sF);
905 $x+=$charW+(($char==' ')?$wordSpacing:$spacing);
906 }
907 }
908 }
909
910 /**
911 * Function that finds the right fontsize that will render the textstring within a certain width
912 *
913 * @param array The TypoScript properties of the TEXT GIFBUILDER object
914 * @return integer The new fontSize
915 * @access private
916 * @author Rene Fritz <r.fritz@colorcube.de>
917 * @see tslib_gifBuilder::start()
918 */
919 function fontResize($conf) {
920 // 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!!!!
921 $maxWidth = intval($conf['maxWidth']);
922 list($spacing,$wordSpacing) = $this->calcWordSpacing($conf);
923 if ($maxWidth) {
924 if ($spacing || $wordSpacing) { // If any kind of spacing applys, we use this function:
925 return $conf['fontSize'];
926 // ################ no calc for spacing yet !!!!!!
927 } else {
928 do {
929 // determine bounding box.
930 $bounds = $this->ImageTTFBBoxWrapper($conf['fontSize'], $conf['angle'], $conf['fontFile'], $this->recodeString($conf['text']), $conf['splitRendering.']);
931 if ($conf['angle']< 0) {
932 $pixelWidth = abs($bounds[4]-$bounds[0]);
933 } elseif ($conf['angle'] > 0) {
934 $pixelWidth = abs($bounds[2]-$bounds[6]);
935 } else {
936 $pixelWidth = abs($bounds[4]-$bounds[6]);
937 }
938
939 // Size is fine, exit:
940 if ($pixelWidth <= $maxWidth) {
941 break;
942 } else {
943 $conf['fontSize']--;
944 }
945 } while ($conf['fontSize']>1);
946 }//if spacing
947 }
948 return $conf['fontSize'];
949 }
950
951 /**
952 * Wrapper for ImageTTFBBox
953 *
954 * @param integer (See argument for PHP function ImageTTFBBox())
955 * @param integer (See argument for PHP function ImageTTFBBox())
956 * @param string (See argument for PHP function ImageTTFBBox())
957 * @param string (See argument for PHP function ImageTTFBBox())
958 * @param array Split-rendering configuration
959 * @param integer Scale factor
960 * @return array Information array.
961 */
962 function ImageTTFBBoxWrapper($fontSize, $angle, $fontFile, $string, $splitRendering, $sF=1) {
963
964 // Initialize:
965 $offsetInfo = array();
966 $stringParts = $this->splitString($string,$splitRendering,$fontSize,$fontFile);
967
968 // Traverse string parts:
969 foreach($stringParts as $strCfg) {
970 $fontFile = t3lib_stdGraphic::prependAbsolutePath($strCfg['fontFile']);
971 if (is_readable($fontFile)) {
972
973 // Calculate Bounding Box for part:
974 $calc = ImageTTFBBox(t3lib_div::freetypeDpiComp($sF*$strCfg['fontSize']), $angle, $fontFile, $strCfg['str']);
975
976 // Calculate offsets:
977 if (!count($offsetInfo)) {
978 $offsetInfo = $calc; // First run, just copy over.
979 } else {
980 $offsetInfo[2]+=$calc[2]-$calc[0]+intval($splitRendering['compX'])+intval($strCfg['xSpaceBefore'])+intval($strCfg['xSpaceAfter']);
981 $offsetInfo[3]+=$calc[3]-$calc[1]-intval($splitRendering['compY'])-intval($strCfg['ySpaceBefore'])-intval($strCfg['ySpaceAfter']);
982 $offsetInfo[4]+=$calc[4]-$calc[6]+intval($splitRendering['compX'])+intval($strCfg['xSpaceBefore'])+intval($strCfg['xSpaceAfter']);
983 $offsetInfo[5]+=$calc[5]-$calc[7]-intval($splitRendering['compY'])-intval($strCfg['ySpaceBefore'])-intval($strCfg['ySpaceAfter']);
984 }
985
986 } else {
987 debug('cannot read file: '.$fontFile, 't3lib_stdGraphic::ImageTTFBBoxWrapper()');
988 }
989 }
990
991 return $offsetInfo;
992 }
993
994 /**
995 * Wrapper for ImageTTFText
996 *
997 * @param pointer (See argument for PHP function imageTTFtext())
998 * @param integer (See argument for PHP function imageTTFtext())
999 * @param integer (See argument for PHP function imageTTFtext())
1000 * @param integer (See argument for PHP function imageTTFtext())
1001 * @param integer (See argument for PHP function imageTTFtext())
1002 * @param integer (See argument for PHP function imageTTFtext())
1003 * @param string (See argument for PHP function imageTTFtext())
1004 * @param string (See argument for PHP function imageTTFtext()). UTF-8 string, possibly with entities in.
1005 * @param array Split-rendering configuration
1006 * @param integer Scale factor
1007 * @return void
1008 */
1009 function ImageTTFTextWrapper($im, $fontSize, $angle, $x, $y, $color, $fontFile, $string, $splitRendering,$sF=1) {
1010
1011 // Initialize:
1012 $stringParts = $this->splitString($string,$splitRendering,$fontSize,$fontFile);
1013 $x = ceil($sF*$x);
1014 $y = ceil($sF*$y);
1015
1016 // Traverse string parts:
1017 foreach($stringParts as $i => $strCfg) {
1018
1019 // Initialize:
1020 $colorIndex = $color;
1021
1022 // Set custom color if any (only when niceText is off):
1023 if ($strCfg['color'] && $sF==1) {
1024 $cols = $this->convertColor($strCfg['color']);
1025 $colorIndex = ImageColorAllocate($im, $cols[0],$cols[1],$cols[2]);
1026 $colorIndex = $color >= 0 ? $colorIndex : -$colorIndex;
1027 }
1028
1029 // Setting xSpaceBefore
1030 if ($i) {
1031 $x+= intval($strCfg['xSpaceBefore']);
1032 $y-= intval($strCfg['ySpaceBefore']);
1033 }
1034
1035 $fontFile = t3lib_stdGraphic::prependAbsolutePath($strCfg['fontFile']);
1036 if (is_readable($fontFile)) {
1037
1038 // Render part:
1039 ImageTTFText($im, t3lib_div::freetypeDpiComp($sF*$strCfg['fontSize']), $angle, $x, $y, $colorIndex, $fontFile, $strCfg['str']);
1040
1041 // Calculate offset to apply:
1042 $wordInf = ImageTTFBBox(t3lib_div::freetypeDpiComp($sF*$strCfg['fontSize']), $angle, t3lib_stdGraphic::prependAbsolutePath($strCfg['fontFile']), $strCfg['str']);
1043 $x+= $wordInf[2]-$wordInf[0]+intval($splitRendering['compX'])+intval($strCfg['xSpaceAfter']);
1044 $y+= $wordInf[5]-$wordInf[7]-intval($splitRendering['compY'])-intval($strCfg['ySpaceAfter']);
1045
1046 } else {
1047 debug('cannot read file: '.$fontFile, 't3lib_stdGraphic::ImageTTFTextWrapper()');
1048 }
1049
1050 }
1051 }
1052
1053 /**
1054 * Splitting a string for ImageTTFBBox up into an array where each part has its own configuration options.
1055 *
1056 * @param string UTF-8 string
1057 * @param array Split-rendering configuration from GIFBUILDER TEXT object.
1058 * @param integer Current fontsize
1059 * @param string Current font file
1060 * @return array Array with input string splitted according to configuration
1061 */
1062 function splitString($string,$splitRendering,$fontSize,$fontFile) {
1063
1064 // Initialize by setting the whole string and default configuration as the first entry.
1065 $result = array();
1066 $result[] = array(
1067 'str' => $string,
1068 'fontSize' => $fontSize,
1069 'fontFile' => $fontFile
1070 );
1071
1072 // Traverse the split-rendering configuration:
1073 // Splitting will create more entries in $result with individual configurations.
1074 if (is_array($splitRendering)) {
1075 $sKeyArray = t3lib_TStemplate::sortedKeyList($splitRendering);
1076
1077 // Traverse configured options:
1078 foreach($sKeyArray as $key) {
1079 $cfg = $splitRendering[$key.'.'];
1080
1081 // Process each type of split rendering keyword:
1082 switch((string)$splitRendering[$key]) {
1083 case 'highlightWord':
1084 if (strlen($cfg['value'])) {
1085 $newResult = array();
1086
1087 // Traverse the current parts of the result array:
1088 foreach($result as $part) {
1089 // Explode the string value by the word value to highlight:
1090 $explodedParts = explode($cfg['value'],$part['str']);
1091 foreach($explodedParts as $c => $expValue) {
1092 if (strlen($expValue)) {
1093 $newResult[] = array_merge($part,array('str' => $expValue));
1094 }
1095 if ($c+1 < count($explodedParts)) {
1096 $newResult[] = array(
1097 'str' => $cfg['value'],
1098 'fontSize' => $cfg['fontSize'] ? $cfg['fontSize'] : $part['fontSize'],
1099 'fontFile' => $cfg['fontFile'] ? $cfg['fontFile'] : $part['fontFile'],
1100 'color' => $cfg['color'],
1101 'xSpaceBefore' => $cfg['xSpaceBefore'],
1102 'xSpaceAfter' => $cfg['xSpaceAfter'],
1103 'ySpaceBefore' => $cfg['ySpaceBefore'],
1104 'ySpaceAfter' => $cfg['ySpaceAfter'],
1105 );
1106 }
1107 }
1108 }
1109
1110 // Set the new result as result array:
1111 if (count($newResult)) {
1112 $result = $newResult;
1113 }
1114 }
1115 break;
1116 case 'charRange':
1117 if (strlen($cfg['value'])) {
1118
1119 // Initialize range:
1120 $ranges = t3lib_div::trimExplode(',',$cfg['value'],1);
1121 foreach($ranges as $i => $rangeDef) {
1122 $ranges[$i] = t3lib_div::intExplode('-',$ranges[$i]);
1123 if (!isset($ranges[$i][1])) $ranges[$i][1] = $ranges[$i][0];
1124 }
1125 $newResult = array();
1126
1127 // Traverse the current parts of the result array:
1128 foreach($result as $part) {
1129
1130 // Initialize:
1131 $currentState = -1;
1132 $bankAccum = '';
1133
1134 // Explode the string value by the word value to highlight:
1135 $utf8Chars = $this->singleChars($part['str']);
1136 foreach($utf8Chars as $utfChar) {
1137
1138 // Find number and evaluate position:
1139 $uNumber = $this->csConvObj->utf8CharToUnumber($utfChar);
1140 $inRange = 0;
1141 foreach($ranges as $rangeDef) {
1142 if ($uNumber >= $rangeDef[0] && (!$rangeDef[1] || $uNumber <= $rangeDef[1])) {
1143 $inRange = 1;
1144 break;
1145 }
1146 }
1147 if ($currentState==-1) $currentState = $inRange; // Initialize first char
1148
1149 // Switch bank:
1150 if ($inRange != $currentState && !t3lib_div::inList('32,10,13,9',$uNumber)) {
1151
1152 // Set result:
1153 if (strlen($bankAccum)) {
1154 $newResult[] = array(
1155 'str' => $bankAccum,
1156 'fontSize' => $currentState && $cfg['fontSize'] ? $cfg['fontSize'] : $part['fontSize'],
1157 'fontFile' => $currentState && $cfg['fontFile'] ? $cfg['fontFile'] : $part['fontFile'],
1158 'color' => $currentState ? $cfg['color'] : '',
1159 'xSpaceBefore' => $currentState ? $cfg['xSpaceBefore'] : '',
1160 'xSpaceAfter' => $currentState ? $cfg['xSpaceAfter'] : '',
1161 'ySpaceBefore' => $currentState ? $cfg['ySpaceBefore'] : '',
1162 'ySpaceAfter' => $currentState ? $cfg['ySpaceAfter'] : '',
1163 );
1164 }
1165
1166 // Initialize new settings:
1167 $currentState = $inRange;
1168 $bankAccum = '';
1169 }
1170
1171 // Add char to bank:
1172 $bankAccum.=$utfChar;
1173 }
1174
1175 // Set result for FINAL part:
1176 if (strlen($bankAccum)) {
1177 $newResult[] = array(
1178 'str' => $bankAccum,
1179 'fontSize' => $currentState && $cfg['fontSize'] ? $cfg['fontSize'] : $part['fontSize'],
1180 'fontFile' => $currentState && $cfg['fontFile'] ? $cfg['fontFile'] : $part['fontFile'],
1181 'color' => $currentState ? $cfg['color'] : '',
1182 'xSpaceBefore' => $currentState ? $cfg['xSpaceBefore'] : '',
1183 'xSpaceAfter' => $currentState ? $cfg['xSpaceAfter'] : '',
1184 'ySpaceBefore' => $currentState ? $cfg['ySpaceBefore'] : '',
1185 'ySpaceAfter' => $currentState ? $cfg['ySpaceAfter'] : '',
1186 );
1187 }
1188 }
1189
1190 // Set the new result as result array:
1191 if (count($newResult)) {
1192 $result = $newResult;
1193 }
1194 }
1195 break;
1196 }
1197 }
1198 }
1199
1200 return $result;
1201 }
1202
1203 /**
1204 * Calculates the spacing and wordSpacing values
1205 *
1206 * @param array TypoScript array for the TEXT GIFBUILDER object
1207 * @param integer TypoScript value from eg $conf['niceText.']['scaleFactor']
1208 * @return array Array with two keys [0]/[1] being array($spacing,$wordSpacing)
1209 * @access private
1210 * @see calcBBox()
1211 */
1212 function calcWordSpacing($conf, $scaleFactor=1) {
1213
1214 $spacing = intval($conf['spacing']);
1215 $wordSpacing = intval($conf['wordSpacing']);
1216 $wordSpacing = $wordSpacing?$wordSpacing:$spacing*2;
1217
1218 $spacing*=$scaleFactor;
1219 $wordSpacing*=$scaleFactor;
1220
1221 return array($spacing,$wordSpacing);
1222 }
1223
1224 /**
1225 * Calculates and returns the niceText.scaleFactor
1226 *
1227 * @param array TypoScript array for the TEXT GIFBUILDER object
1228 * @return integer TypoScript value from eg $conf['niceText.']['scaleFactor']
1229 * @access private
1230 */
1231 function getTextScalFactor($conf) {
1232 if (!$conf['niceText']) {
1233 $sF = 1;
1234 } else { // NICETEXT::
1235 $sF = t3lib_div::intInRange($conf['niceText.']['scaleFactor'],2,5);
1236 }
1237 return $sF;
1238 }
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250 /*********************************************
1251 *
1252 * Other GIFBUILDER objects related to TEXT
1253 *
1254 *********************************************/
1255
1256 /**
1257 * Implements the "OUTLINE" GIFBUILDER object / property for the TEXT object
1258 *
1259 * @param pointer GDlib image pointer
1260 * @param array TypoScript array with configuration for the GIFBUILDER object.
1261 * @param array The current working area coordinates.
1262 * @param array TypoScript array with configuration for the associated TEXT GIFBUILDER object.
1263 * @return void
1264 * @see tslib_gifBuilder::make(), makeText()
1265 */
1266 function makeOutline(&$im,$conf,$workArea,$txtConf) {
1267 $thickness = intval($conf['thickness']);
1268 if ($thickness) {
1269 $txtConf['fontColor'] = $conf['color'];
1270 $outLineDist = t3lib_div::intInRange($thickness,1,2);
1271 for ($b=1;$b<=$outLineDist;$b++) {
1272 if ($b==1) {
1273 $it = 8;
1274 } else {
1275 $it = 16;
1276 }
1277 $outL = $this->circleOffset($b, $it);
1278 for ($a=0;$a<$it;$a++) {
1279 $this->makeText($im,$txtConf,$this->applyOffset($workArea,$outL[$a]));
1280 }
1281 }
1282 }
1283 }
1284
1285 /**
1286 * Creates some offset values in an array used to simulate a circularly applied outline around TEXT
1287 *
1288 * access private
1289 *
1290 * @param integer Distance
1291 * @param integer Iterations.
1292 * @return array
1293 * @see makeOutline()
1294 */
1295 function circleOffset($distance, $iterations) {
1296 $res = Array();
1297 if ($distance && $iterations) {
1298 for ($a=0;$a<$iterations;$a++) {
1299 $yOff = round(sin(2*pi()/$iterations*($a+1))*100*$distance);
1300 if ($yOff) {$yOff = intval(ceil(abs($yOff/100))*($yOff/abs($yOff)));}
1301 $xOff = round(cos(2*pi()/$iterations*($a+1))*100*$distance);
1302 if ($xOff) {$xOff = intval(ceil(abs($xOff/100))*($xOff/abs($xOff)));}
1303 $res[$a] = Array($xOff,$yOff);
1304 }
1305 }
1306 return $res;
1307 }
1308
1309 /**
1310 * Implements the "EMBOSS" GIFBUILDER object / property for the TEXT object
1311 *
1312 * @param pointer GDlib image pointer
1313 * @param array TypoScript array with configuration for the GIFBUILDER object.
1314 * @param array The current working area coordinates.
1315 * @param array TypoScript array with configuration for the associated TEXT GIFBUILDER object.
1316 * @return void
1317 * @see tslib_gifBuilder::make(), makeShadow()
1318 */
1319 function makeEmboss(&$im,$conf,$workArea,$txtConf) {
1320 $conf['color']=$conf['highColor'];
1321 $this->makeShadow($im,$conf,$workArea,$txtConf);
1322 $newOffset = t3lib_div::intExplode(',',$conf['offset']);
1323 $newOffset[0]*=-1;
1324 $newOffset[1]*=-1;
1325 $conf['offset']=implode(',',$newOffset);
1326 $conf['color']=$conf['lowColor'];
1327 $this->makeShadow($im,$conf,$workArea,$txtConf);
1328 }
1329
1330 /**
1331 * Implements the "SHADOW" GIFBUILDER object / property for the TEXT object
1332 * The operation involves ImageMagick for combining.
1333 *
1334 * @param pointer GDlib image pointer
1335 * @param array TypoScript array with configuration for the GIFBUILDER object.
1336 * @param array The current working area coordinates.
1337 * @param array TypoScript array with configuration for the associated TEXT GIFBUILDER object.
1338 * @return void
1339 * @see tslib_gifBuilder::make(), makeText(), makeEmboss()
1340 */
1341 function makeShadow(&$im,$conf,$workArea,$txtConf) {
1342 $workArea = $this->applyOffset($workArea,t3lib_div::intExplode(',',$conf['offset']));
1343 $blurRate = t3lib_div::intInRange(intval($conf['blur']),0,99);
1344
1345 if (!$blurRate || $this->NO_IM_EFFECTS) { // No effects if ImageMagick ver. 5+
1346 $txtConf['fontColor'] = $conf['color'];
1347 $this->makeText($im,$txtConf,$workArea);
1348 } else {
1349 $w = imagesx($im);
1350 $h = imagesy($im);
1351 $blurBorder= 3; // area around the blur used for cropping something
1352 $tmpStr = $this->randomName();
1353 $fileMenu = $tmpStr.'_menu.'.$this->gifExtension;
1354 $fileColor = $tmpStr.'_color.'.$this->gifExtension;
1355 $fileMask = $tmpStr.'_mask.'.$this->gifExtension;
1356
1357 // BlurColor Image laves
1358 $blurColImg = $this->imagecreate($w,$h);
1359 $bcols=$this->convertColor($conf['color']);
1360 $Bcolor = ImageColorAllocate($blurColImg, $bcols[0],$bcols[1],$bcols[2]);
1361 ImageFilledRectangle($blurColImg, 0, 0, $w, $h, $Bcolor);
1362 $this->ImageWrite($blurColImg, $fileColor);
1363 ImageDestroy($blurColImg);
1364
1365 // The mask is made: BlurTextImage
1366 $blurTextImg = $this->imagecreate($w+$blurBorder*2,$h+$blurBorder*2);
1367 $Bcolor = ImageColorAllocate($blurTextImg, 0,0,0); // black background
1368 ImageFilledRectangle($blurTextImg, 0, 0, $w+$blurBorder*2, $h+$blurBorder*2, $Bcolor);
1369 $txtConf['fontColor'] = 'white';
1370 $blurBordArr = Array($blurBorder,$blurBorder);
1371 $this->makeText($blurTextImg,$txtConf, $this->applyOffset($workArea,$blurBordArr));
1372 $this->ImageWrite($blurTextImg, $fileMask); // dump to temporary file
1373 ImageDestroy($blurTextImg); // destroy
1374
1375
1376 $command='';
1377 $command.=$this->maskNegate;
1378
1379 if ($this->V5_EFFECTS) {
1380 $command.=$this->v5_blur($blurRate+1);
1381 } else {
1382 // Blurring of the mask
1383 $times = ceil($blurRate/10); // How many blur-commands that is executed. Min = 1;
1384 $newBlurRate = $blurRate*4; // Here I boost the blur-rate so that it is 100 already at 25. The rest is done by up to 99 iterations of the blur-command.
1385 $newBlurRate = t3lib_div::intInRange($newBlurRate,1,99);
1386 for ($a=0;$a<$times;$a++) { // Building blur-command
1387 $command.=' -blur '.$blurRate;
1388 }
1389 }
1390
1391 $this->imageMagickExec($fileMask,$fileMask,$command.' +matte');
1392
1393 $blurTextImg_tmp = $this->imageCreateFromFile($fileMask); // the mask is loaded again
1394 if ($blurTextImg_tmp) { // if nothing went wrong we continue with the blurred mask
1395
1396 // cropping the border from the mask
1397 $blurTextImg = $this->imagecreate($w,$h);
1398 $this->imagecopyresized($blurTextImg, $blurTextImg_tmp, 0, 0, $blurBorder, $blurBorder, $w, $h, $w, $h);
1399 ImageDestroy($blurTextImg_tmp); // Destroy the temporary mask
1400
1401 // adjust the mask
1402 $intensity = 40;
1403 if ($conf['intensity']) {
1404 $intensity = t3lib_div::intInRange($conf['intensity'],0,100);
1405 }
1406 $intensity = ceil(255-($intensity/100*255));
1407 $this->inputLevels($blurTextImg,0,$intensity,$this->maskNegate);
1408
1409 $opacity = t3lib_div::intInRange(intval($conf['opacity']),0,100);
1410 if ($opacity && $opacity<100) {
1411 $high = ceil(255*$opacity/100);
1412 $this->outputLevels($blurTextImg,0,$high,$this->maskNegate); // reducing levels as the opacity demands
1413 }
1414
1415 $this->ImageWrite($blurTextImg, $fileMask); // Dump the mask again
1416 ImageDestroy($blurTextImg); // Destroy the mask
1417
1418 // The pictures are combined
1419 $this->ImageWrite($im, $fileMenu); // The main pictures is saved temporarily
1420
1421 $this->combineExec($fileMenu,$fileColor,$fileMask,$fileMenu);
1422
1423 $backIm = $this->imageCreateFromFile($fileMenu); // The main image is loaded again...
1424 if ($backIm) { // ... and if nothing went wrong we load it onto the old one.
1425 ImageColorTransparent($backIm,-1);
1426 $im = $backIm;
1427 }
1428 }
1429 // Deleting temporary files;
1430 if (!$this->dontUnlinkTempFiles) {
1431 unlink($fileMenu);
1432 unlink($fileColor);
1433 unlink($fileMask);
1434 }
1435 }
1436 }
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458 /****************************
1459 *
1460 * Other GIFBUILDER objects
1461 *
1462 ****************************/
1463
1464 /**
1465 * Implements the "BOX" GIFBUILDER object
1466 *
1467 * @param pointer GDlib image pointer
1468 * @param array TypoScript array with configuration for the GIFBUILDER object.
1469 * @param array The current working area coordinates.
1470 * @return void
1471 * @see tslib_gifBuilder::make()
1472 */
1473 function makeBox(&$im,$conf,$workArea) {
1474 $cords = t3lib_div::intExplode(',',$conf['dimensions'].',,,');
1475 $conf['offset']=$cords[0].','.$cords[1];
1476 $cords = $this->objPosition($conf,$workArea,Array($cords[2],$cords[3]));
1477 $cols=$this->convertColor($conf['color']);
1478 if (!$this->truecolor) {
1479 $reduce = t3lib_div::intInRange($this->setup['reduceColors'], 256, $this->truecolorColors, 256);
1480 $this->reduceColors($im, $reduce-1, $reduce-2); // If "reduce-1" colors (or more) are used reduce them to "reduce-2"
1481 }
1482 $tmpColor = ImageColorAllocate($im, $cols[0],$cols[1],$cols[2]);
1483 imagefilledrectangle($im, $cords[0], $cords[1], $cords[0]+$cords[2]-1, $cords[1]+$cords[3]-1, $tmpColor);
1484 }
1485
1486 /**
1487 * Implements the "EFFECT" GIFBUILDER object
1488 * The operation involves ImageMagick for applying effects
1489 *
1490 * @param pointer GDlib image pointer
1491 * @param array TypoScript array with configuration for the GIFBUILDER object.
1492 * @return void
1493 * @see tslib_gifBuilder::make(), applyImageMagickToPHPGif()
1494 */
1495 function makeEffect(&$im, $conf) {
1496 $commands = $this->IMparams($conf['value']);
1497 if ($commands) {
1498 $this->applyImageMagickToPHPGif($im, $commands);
1499 }
1500 }
1501
1502 /**
1503 * Creating ImageMagick paramters from TypoScript property
1504 *
1505 * @param string A string with effect keywords=value pairs separated by "|"
1506 * @return string ImageMagick prepared parameters.
1507 * @access private
1508 * @see makeEffect()
1509 */
1510 function IMparams($setup) {
1511 if (!trim($setup)){return '';}
1512 $effects = explode('|', $setup);
1513 $commands = '';
1514 while(list(,$val)=each($effects)) {
1515 $pairs=explode('=',$val,2);
1516 $value = trim($pairs[1]);
1517 $effect = strtolower(trim($pairs[0]));
1518 switch($effect) {
1519 case 'gamma':
1520 $commands.=' -gamma '.doubleval($value);
1521 break;
1522 case 'blur':
1523 if (!$this->NO_IM_EFFECTS) {
1524 if ($this->V5_EFFECTS) {
1525 $commands.=$this->v5_blur($value);
1526 } else {
1527 $commands.=' -blur '.t3lib_div::intInRange($value,1,99);
1528 }
1529 }
1530 break;
1531 case 'sharpen':
1532 if (!$this->NO_IM_EFFECTS) {
1533 if ($this->V5_EFFECTS) {
1534 $commands.=$this->v5_sharpen($value);
1535 } else {
1536 $commands.=' -sharpen '.t3lib_div::intInRange($value,1,99);
1537 }
1538 }
1539 break;
1540 case 'rotate':
1541 $commands.=' -rotate '.t3lib_div::intInRange($value,0,360);
1542 break;
1543 case 'solarize':
1544 $commands.=' -solarize '.t3lib_div::intInRange($value,0,99);
1545 break;
1546 case 'swirl':
1547 $commands.=' -swirl '.t3lib_div::intInRange($value,0,1000);
1548 break;
1549 case 'wave':
1550 $params = t3lib_div::intExplode(',',$value);
1551 $commands.=' -wave '.t3lib_div::intInRange($params[0],0,99).'x'.t3lib_div::intInRange($params[1],0,99);
1552 break;
1553 case 'charcoal':
1554 $commands.=' -charcoal '.t3lib_div::intInRange($value,0,100);
1555 break;
1556 case 'gray':
1557 $commands.=' -colorspace GRAY';
1558 break;
1559 case 'edge':
1560 $commands.=' -edge '.t3lib_div::intInRange($value,0,99);
1561 break;
1562 case 'emboss':
1563 $commands.=' -emboss';
1564 break;
1565 case 'flip':
1566 $commands.=' -flip';
1567 break;
1568 case 'flop':
1569 $commands.=' -flop';
1570 break;
1571 case 'colors':
1572 $commands.=' -colors '.t3lib_div::intInRange($value,2,255);
1573 break;
1574 case 'shear':
1575 $commands.=' -shear '.t3lib_div::intInRange($value,-90,90);
1576 break;
1577 case 'invert':
1578 $commands.=' -negate';
1579 break;
1580 }
1581 }
1582 return $commands;
1583 }
1584
1585 /**
1586 * Implements the "ADJUST" GIFBUILDER object
1587 *
1588 * @param pointer GDlib image pointer
1589 * @param array TypoScript array with configuration for the GIFBUILDER object.
1590 * @return void
1591 * @see tslib_gifBuilder::make(), autoLevels(), outputLevels(), inputLevels()
1592 */
1593 function adjust(&$im, $conf) {
1594 $setup = $conf['value'];
1595 if (!trim($setup)){return '';}
1596 $effects = explode('|', $setup);
1597 while(list(,$val)=each($effects)) {
1598 $pairs=explode('=',$val,2);
1599 $value = trim($pairs[1]);
1600 $effect = strtolower(trim($pairs[0]));
1601 switch($effect) {
1602 case 'inputlevels': // low,high
1603 $params = t3lib_div::intExplode(',',$value);
1604 $this->inputLevels($im,$params[0],$params[1]);
1605 break;
1606 case 'outputlevels':
1607 $params = t3lib_div::intExplode(',',$value);
1608 $this->outputLevels($im,$params[0],$params[1]);
1609 break;
1610 case 'autolevels':
1611 $this->autoLevels($im);
1612 break;
1613 }
1614 }
1615 }
1616
1617 /**
1618 * Implements the "CROP" GIFBUILDER object
1619 *
1620 * @param pointer GDlib image pointer
1621 * @param array TypoScript array with configuration for the GIFBUILDER object.
1622 * @return void
1623 * @see tslib_gifBuilder::make()
1624 */
1625 function crop(&$im,$conf) {
1626 $this->setWorkArea(''); // clears workArea to total image
1627 $cords = t3lib_div::intExplode(',',$conf['crop'].',,,');
1628 $conf['offset']=$cords[0].','.$cords[1];
1629 $cords = $this->objPosition($conf,$this->workArea,Array($cords[2],$cords[3]));
1630
1631 $newIm = $this->imagecreate($cords[2],$cords[3]);
1632 $cols=$this->convertColor($conf['backColor']?$conf['backColor']:$this->setup['backColor']);
1633 $Bcolor = ImageColorAllocate($newIm, $cols[0],$cols[1],$cols[2]);
1634 ImageFilledRectangle($newIm, 0, 0, $cords[2], $cords[3], $Bcolor);
1635
1636 $newConf = Array();
1637 $workArea = Array(0,0,$cords[2],$cords[3]);
1638 if ($cords[0]<0) {$workArea[0]=abs($cords[0]);} else {$newConf['offset']=-$cords[0];}
1639 if ($cords[1]<0) {$workArea[1]=abs($cords[1]);} else {$newConf['offset'].=','.-$cords[1];}
1640
1641 $this->copyGifOntoGif($newIm,$im,$newConf,$workArea);
1642 $im = $newIm;
1643 $this->w = imagesx($im);
1644 $this->h = imagesy($im);
1645 $this->setWorkArea(''); // clears workArea to total image
1646 }
1647
1648 /**
1649 * Implements the "SCALE" GIFBUILDER object
1650 *
1651 * @param pointer GDlib image pointer
1652 * @param array TypoScript array with configuration for the GIFBUILDER object.
1653 * @return void
1654 * @see tslib_gifBuilder::make()
1655 */
1656 function scale(&$im,$conf) {
1657 if ($conf['width'] || $conf['height'] || $conf['params']) {
1658 $tmpStr = $this->randomName();
1659 $theFile = $tmpStr.'.'.$this->gifExtension;
1660 $this->ImageWrite($im, $theFile);
1661 $theNewFile = $this->imageMagickConvert($theFile,$this->gifExtension,$conf['width'],$conf['height'],$conf['params'],'','');
1662 $tmpImg = $this->imageCreateFromFile($theNewFile[3]);
1663 if ($tmpImg) {
1664 ImageDestroy($im);
1665 $im = $tmpImg;
1666 $this->w = imagesx($im);
1667 $this->h = imagesy($im);
1668 $this->setWorkArea(''); // clears workArea to total image
1669 }
1670 if (!$this->dontUnlinkTempFiles) {
1671 unlink($theFile);
1672 if ($theNewFile[3] && $theNewFile[3]!=$theFile) {
1673 unlink($theNewFile[3]);
1674 }
1675 }
1676 }
1677 }
1678
1679 /**
1680 * Implements the "WORKAREA" GIFBUILDER object when setting it
1681 * Setting internal working area boundaries (->workArea)
1682 *
1683 * @param string Working area dimensions, comma separated
1684 * @return void
1685 * @access private
1686 * @see tslib_gifBuilder::make()
1687 */
1688 function setWorkArea($workArea) {
1689 $this->workArea = t3lib_div::intExplode(',',$workArea);
1690 $this->workArea = $this->applyOffset($this->workArea,$this->OFFSET);
1691 if (!$this->workArea[2]) {$this->workArea[2]=$this->w;}
1692 if (!$this->workArea[3]) {$this->workArea[3]=$this->h;}
1693 }
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717 /*************************
1718 *
1719 * Adjustment functions
1720 *
1721 ************************/
1722
1723 /**
1724 * Apply auto-levels to input image pointer
1725 *
1726 * @param integer GDlib Image Pointer
1727 * @return void
1728 */
1729 function autolevels(&$im) {
1730 $totalCols = ImageColorsTotal($im);
1731 $min=255;
1732 $max=0;
1733 for ($c=0; $c<$totalCols; $c++) {
1734 $cols = ImageColorsForIndex($im,$c);
1735 $grayArr[] = round(($cols['red']+$cols['green']+$cols['blue'])/3);
1736 }
1737 $min=min($grayArr);
1738 $max=max($grayArr);
1739 $delta = $max-$min;
1740 if ($delta) {
1741 for ($c=0; $c<$totalCols; $c++) {
1742 $cols = ImageColorsForIndex($im,$c);
1743 $cols['red'] = floor(($cols['red']-$min)/$delta*255);
1744 $cols['green'] = floor(($cols['green']-$min)/$delta*255);
1745 $cols['blue'] = floor(($cols['blue']-$min)/$delta*255);
1746 ImageColorSet($im,$c,$cols['red'],$cols['green'],$cols['blue']);
1747 }
1748 }
1749 }
1750
1751 /**
1752 * Apply output levels to input image pointer (decreasing contrast)
1753 *
1754 * @param integer GDlib Image Pointer
1755 * @param integer The "low" value (close to 0)
1756 * @param integer The "high" value (close to 255)
1757 * @param boolean If swap, then low and high are swapped. (Useful for negated masks...)
1758 * @return void
1759 */
1760 function outputLevels(&$im,$low,$high,$swap='') {
1761 if ($low<$high){
1762 $low = t3lib_div::intInRange($low,0,255);
1763 $high = t3lib_div::intInRange($high,0,255);
1764
1765 if ($swap) {
1766 $temp = $low;
1767 $low = 255-$high;
1768 $high = 255-$temp;
1769 }
1770
1771 $delta = $high-$low;
1772 $totalCols = ImageColorsTotal($im);
1773 for ($c=0; $c<$totalCols; $c++) {
1774 $cols = ImageColorsForIndex($im,$c);
1775 $cols['red'] = $low+floor($cols['red']/255*$delta);
1776 $cols['green'] = $low+floor($cols['green']/255*$delta);
1777 $cols['blue'] = $low+floor($cols['blue']/255*$delta);
1778 ImageColorSet($im,$c,$cols['red'],$cols['green'],$cols['blue']);
1779 }
1780 }
1781 }
1782
1783 /**
1784 * Apply input levels to input image pointer (increasing contrast)
1785 *
1786 * @param integer GDlib Image Pointer
1787 * @param integer The "low" value (close to 0)
1788 * @param integer The "high" value (close to 255)
1789 * @param boolean If swap, then low and high are swapped. (Useful for negated masks...)
1790 * @return void
1791 */
1792 function inputLevels(&$im,$low,$high,$swap='') {
1793 if ($low<$high){
1794 $low = t3lib_div::intInRange($low,0,255);
1795 $high = t3lib_div::intInRange($high,0,255);
1796
1797 if ($swap) {
1798 $temp = $low;
1799 $low = 255-$high;
1800 $high = 255-$temp;
1801 }
1802
1803 $delta = $high-$low;
1804 $totalCols = ImageColorsTotal($im);
1805 for ($c=0; $c<$totalCols; $c++) {
1806 $cols = ImageColorsForIndex($im,$c);
1807 $cols['red'] = t3lib_div::intInRange(($cols['red']-$low)/$delta*255, 0,255);
1808 $cols['green'] = t3lib_div::intInRange(($cols['green']-$low)/$delta*255, 0,255);
1809 $cols['blue'] = t3lib_div::intInRange(($cols['blue']-$low)/$delta*255, 0,255);
1810 ImageColorSet($im,$c,$cols['red'],$cols['green'],$cols['blue']);
1811 }
1812 }
1813 }
1814
1815 /**
1816 * Reduce colors in image dependend on the actual amount of colors (Only works if we are not in truecolor mode)
1817 *
1818 * @param integer GDlib Image Pointer
1819 * @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.
1820 * @param integer Number of colors to reduce the image to.
1821 * @return void
1822 */
1823 function reduceColors(&$im,$limit, $cols) {
1824 if (!$this->truecolor && ImageColorsTotal($im)>=$limit) {
1825 $this->makeEffect($im, Array('value'=>'colors='.$cols) );
1826 }
1827 }
1828
1829 /**
1830 * Reduce colors in image using IM and create a palette based image if possible (<=256 colors)
1831 *
1832 * @param string Image file to reduce
1833 * @param integer Number of colors to reduce the image to.
1834 * @return string Reduced file
1835 */
1836 function IMreduceColors($file, $cols) {
1837 $fI = t3lib_div::split_fileref($file);
1838 $ext = strtolower($fI['fileext']);
1839 $result = $this->randomName().'.'.$ext;
1840 if (($reduce = t3lib_div::intInRange($cols, 0, ($ext=='gif'?256:$this->truecolorColors), 0))>0) {
1841 $params = ' -colors '.$reduce;
1842 if (!$this->im_version_4) {
1843 // IM4 doesn't have this options but forces them automatically if applicaple (<256 colors in image)
1844 if ($reduce<=256) { $params .= ' -type Palette'; }
1845 if ($ext=='png' && $reduce<=256) { $prefix = 'png8:'; }
1846 }
1847 $this->imageMagickExec($file, $prefix.$result, $params);
1848 if ($result) {
1849 return $result;
1850 }
1851 }
1852 return '';
1853 }
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865 /*********************************
1866 *
1867 * GIFBUILDER Helper functions
1868 *
1869 *********************************/
1870
1871 /**
1872 * Checks if the $fontFile is already at an absolute path and if not, prepends the correct path.
1873 * Use PATH_site unless we are in the backend.
1874 * Call it by t3lib_stdGraphic::prependAbsolutePath()
1875 *
1876 * @param string The font file
1877 * @return string The font file with absolute path.
1878 */
1879 function prependAbsolutePath($fontFile) {
1880 $absPath = defined('PATH_typo3') ? dirname(PATH_thisScript).'/' :PATH_site;
1881 $fontFile = t3lib_div::isAbsPath($fontFile) ? $fontFile : t3lib_div::resolveBackPath($absPath.$fontFile);
1882 return $fontFile;
1883 }
1884
1885 /**
1886 * Returns the IM command for sharpening with ImageMagick 5 (when $this->V5_EFFECTS is set).
1887 * Uses $this->im5fx_sharpenSteps for translation of the factor to an actual command.
1888 *
1889 * @param integer The sharpening factor, 0-100 (effectively in 10 steps)
1890 * @return string The sharpening command, eg. " -sharpen 3x4"
1891 * @see makeText(), IMparams(), v5_blur()
1892 */
1893 function v5_sharpen($factor) {
1894 $factor = t3lib_div::intInRange(ceil($factor/10),0,10);
1895
1896 $sharpenArr=explode(',',','.$this->im5fx_sharpenSteps);
1897 $sharpenF= trim($sharpenArr[$factor]);
1898 if ($sharpenF) {
1899 $cmd = ' -sharpen '.$sharpenF;
1900 return $cmd;
1901 }
1902 }
1903
1904 /**
1905 * Returns the IM command for blurring with ImageMagick 5 (when $this->V5_EFFECTS is set).
1906 * Uses $this->im5fx_blurSteps for translation of the factor to an actual command.
1907 *
1908 * @param integer The blurring factor, 0-100 (effectively in 10 steps)
1909 * @return string The blurring command, eg. " -blur 3x4"
1910 * @see makeText(), IMparams(), v5_sharpen()
1911 */
1912 function v5_blur($factor) {
1913 $factor = t3lib_div::intInRange(ceil($factor/10),0,10);
1914
1915 $blurArr=explode(',',','.$this->im5fx_blurSteps);
1916 $blurF= trim($blurArr[$factor]);
1917 if ($blurF) {
1918 $cmd=' -blur '.$blurF;
1919 return $cmd;
1920 }
1921 }
1922
1923 /**
1924 * Returns a random filename prefixed with "temp_" and then 32 char md5 hash (without extension) from $this->tempPath.
1925 * 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.
1926 *
1927 * @return string
1928 */
1929 function randomName() {
1930 $this->createTempSubDir('temp/');
1931 return $this->tempPath.'temp/'.md5(uniqid(''));
1932 }
1933
1934 /**
1935 * Applies offset value to coordinated in $cords.
1936 * Basically the value of key 0/1 of $OFFSET is added to keys 0/1 of $cords
1937 *
1938 * @param array Integer coordinates in key 0/1
1939 * @param array Offset values in key 0/1
1940 * @return array Modified $cords array
1941 */
1942 function applyOffset($cords,$OFFSET) {
1943 $cords[0] = intval($cords[0])+intval($OFFSET[0]);
1944 $cords[1] = intval($cords[1])+intval($OFFSET[1]);
1945 return $cords;
1946 }
1947
1948 /**
1949 * Converts a "HTML-color" TypoScript datatype to RGB-values.
1950 * Default is 0,0,0
1951 *
1952 * @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
1953 * @return array RGB values in key 0/1/2 of the array
1954 */
1955 function convertColor($string) {
1956 $col=array();
1957 $cParts = explode(':',$string,2);
1958
1959 // Finding the RGB definitions of the color:
1960 $string=$cParts[0];
1961 if (strstr($string,'#')) {
1962 $string = ereg_replace('[^A-Fa-f0-9]*','',$string);
1963 $col[]=HexDec(substr($string,0,2));
1964 $col[]=HexDec(substr($string,2,2));
1965 $col[]=HexDec(substr($string,4,2));
1966 } elseif (strstr($string,',')) {
1967 $string = ereg_replace('[^,0-9]*','',$string);
1968 $strArr = explode(',',$string);
1969 $col[]=intval($strArr[0]);
1970 $col[]=intval($strArr[1]);
1971 $col[]=intval($strArr[2]);
1972 } else {
1973 $string = strtolower(trim($string));
1974 if ($this->colMap[$string]) {
1975 $col = $this->colMap[$string];
1976 } else {
1977 $col = Array(0,0,0);
1978 }
1979 }
1980 // ... and possibly recalculating the value
1981 if (trim($cParts[1])) {
1982 $cParts[1]=trim($cParts[1]);
1983 if (substr($cParts[1],0,1)=='*') {
1984 $val=doubleval(substr($cParts[1],1));
1985 $col[0]=t3lib_div::intInRange($col[0]*$val,0,255);
1986 $col[1]=t3lib_div::intInRange($col[1]*$val,0,255);
1987 $col[2]=t3lib_div::intInRange($col[2]*$val,0,255);
1988 } else {
1989 $val=intval($cParts[1]);
1990 $col[0]=t3lib_div::intInRange($col[0]+$val,0,255);
1991 $col[1]=t3lib_div::intInRange($col[1]+$val,0,255);
1992 $col[2]=t3lib_div::intInRange($col[2]+$val,0,255);
1993 }
1994 }
1995 return $col;
1996 }
1997
1998 /**
1999 * Recode string
2000 * Used with text strings for fonts when languages has other character sets.
2001 *
2002 * @param string The text to recode
2003 * @return string The recoded string. Should be UTF-8 output. MAY contain entities (eg. &#123; or &#quot; which should render as real chars).
2004 */
2005 function recodeString($string) {
2006 // Recode string to UTF-8 from $this->nativeCharset:
2007 if ($this->nativeCharset && $this->nativeCharset!='utf-8') {
2008 $string = $this->csConvObj->utf8_encode($string,$this->nativeCharset); // Convert to UTF-8
2009 }
2010
2011 // Recode string accoding to TTFLocaleConv. Deprecated.
2012 if ($this->TTFLocaleConv) {
2013 $string = recode_string($this->TTFLocaleConv,$string);
2014 }
2015
2016 return $string;
2017 }
2018
2019 /**
2020 * Split a string into an array of individual characters
2021 * 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.
2022 *
2023 * @param string The text string to split
2024 * @param boolean Return Unicode numbers instead of chars.
2025 * @return array Numerical array with a char as each value.
2026 */
2027 function singleChars($theText,$returnUnicodeNumber=FALSE) {
2028 if ($this->nativeCharset) {
2029 return $this->csConvObj->utf8_to_numberarray($theText,1,$returnUnicodeNumber ? 0 : 1); // Get an array of separated UTF-8 chars
2030 } else {
2031 $output=array();
2032 $c=strlen($theText);
2033 for($a=0;$a<$c;$a++) {
2034 $output[]=substr($theText,$a,1);
2035 }
2036 return $output;
2037 }
2038 }
2039
2040 /**
2041 * 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
2042 *
2043 * @param array TypoScript configuration for a GIFBUILDER object
2044 * @param array Workarea definition
2045 * @param array BB (Bounding box) array. Not just used for TEXT objects but also for others
2046 * @return array [0]=x, [1]=y, [2]=w, [3]=h
2047 * @access private
2048 * @see copyGifOntoGif(), makeBox(), crop()
2049 */
2050 function objPosition($conf,$workArea,$BB) {
2051 // offset, align, valign, workarea
2052 $result=Array();
2053 $result[2] = $BB[0];
2054 $result[3] = $BB[1];
2055 $w=$workArea[2];
2056 $h=$workArea[3];
2057
2058 $align = explode(',',$conf['align']);
2059 $align[0] = strtolower(substr(trim($align[0]),0,1));
2060 $align[1] = strtolower(substr(trim($align[1]),0,1));
2061
2062 switch($align[0]) {
2063 case 'r':
2064 $result[0]=$w-$result[2];
2065 break;
2066 case 'c':
2067 $result[0] = round(($w-$result[2])/2);
2068 break;
2069 default:
2070 $result[0] = 0;
2071 break;
2072 }
2073 switch($align[1]) {
2074 case 'b':
2075 $result[1] = $h-$result[3]; // y pos
2076 break;
2077 case 'c':
2078 $result[1] = round(($h-$result[3])/2);
2079 break;
2080 default:
2081 $result[1]=0;
2082 break;
2083 }
2084 $result = $this->applyOffset($result,t3lib_div::intExplode(',',$conf['offset']));
2085 $result = $this->applyOffset($result,$workArea);
2086 return $result;
2087 }
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109 /***********************************
2110 *
2111 * Scaling, Dimensions of images
2112 *
2113 ***********************************/
2114
2115 /**
2116 * Converts $imagefile to another file in temp-dir of type $newExt (extension).
2117 *
2118 * @param string The image filepath
2119 * @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.
2120 * @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
2121 * @param string Height. See $w
2122 * @param string Additional ImageMagick parameters.
2123 * @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...
2124 * @param array An array with options passed to getImageScale (see this function).
2125 * @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.
2126 * @return array [0]/[1] is w/h, [2] is file extension and [3] is the filename.
2127 * @see getImageScale(), typo3/show_item.php, fileList_ext::renderImage(), tslib_cObj::getImgResource(), SC_tslib_showpic::show(), maskImageOntoImage(), copyImageOntoImage(), scale()
2128 */
2129 function imageMagickConvert($imagefile,$newExt='',$w='',$h='',$params='',$frame='',$options='',$mustCreate=0) {
2130 if ($this->NO_IMAGE_MAGICK) {
2131 // Returning file info right away
2132 return $this->getImageDimensions($imagefile);
2133 }
2134
2135 if($info=$this->getImageDimensions($imagefile)) {
2136 $newExt=strtolower(trim($newExt));
2137 if (!$newExt) { // If no extension is given the original extension is used
2138 $newExt = $info[2];
2139 }
2140 if ($newExt=='web') {
2141 if (t3lib_div::inList($this->webImageExt,$info[2])) {
2142 $newExt = $info[2];
2143 } else {
2144 $newExt = $this->gif_or_jpg($info[2],$info[0],$info[1]);
2145 if (!$params) {
2146 $params = $this->cmds[$newExt];
2147 }
2148 }
2149 }
2150 if (t3lib_div::inList($this->imageFileExt,$newExt)) {
2151 if (strstr($w.$h, 'm')) {$max=1;} else {$max=0;}
2152
2153 $data = $this->getImageScale($info,$w,$h,$options);
2154 $w=$data['origW'];
2155 $h=$data['origH'];
2156
2157 // if no convertion should be performed
2158 $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....
2159
2160 if ($wh_noscale && !$data['crs'] && !$params && !$frame && $newExt==$info[2] && !$mustCreate) {
2161 $info[3] = $imagefile;
2162 return $info;
2163 }
2164 $info[0]=$data[0];
2165 $info[1]=$data[1];
2166
2167 $frame = $this->noFramePrepended ? '' : '['.intval($frame).']';
2168
2169 if (!$params) {
2170 $params = $this->cmds[$newExt];
2171 }
2172
2173 // Cropscaling:
2174 if ($data['crs']) {
2175 if (!$data['origW']) { $data['origW'] = $data[0]; }
2176 if (!$data['origH']) { $data['origH'] = $data[1]; }
2177 $offsetX = intval(($data[0] - $data['origW']) * ($data['cropH']+100)/200);
2178 $offsetY = intval(($data[1] - $data['origH']) * ($data['cropV']+100)/200);
2179 $params .= ' -crop '.$data['origW'].'x'.$data['origH'].'+'.$offsetX.'+'.$offsetY.'! ';
2180 }
2181
2182 $command = $this->scalecmd.' '.$info[0].'x'.$info[1].'! '.$params.' ';
2183 $cropscale = ($data['crs'] ? 'crs-V'.$data['cropV'].'H'.$data['cropH'] : '');
2184
2185 if ($this->alternativeOutputKey) {
2186 $theOutputName = t3lib_div::shortMD5($command.$cropscale.basename($imagefile).$this->alternativeOutputKey.$frame);
2187 } else {
2188 $theOutputName = t3lib_div::shortMD5($command.$cropscale.$imagefile.filemtime($imagefile).$frame);
2189 }
2190 if ($this->imageMagickConvert_forceFileNameBody) {
2191 $theOutputName = $this->imageMagickConvert_forceFileNameBody;
2192 $this->imageMagickConvert_forceFileNameBody='';
2193 }
2194
2195 // Making the temporary filename:
2196 $this->createTempSubDir('pics/');
2197 $output = $this->absPrefix.$this->tempPath.'pics/'.$this->filenamePrefix.$theOutputName.'.'.$newExt;
2198
2199 // Register temporary filename:
2200 $GLOBALS['TEMP_IMAGES_ON_PAGE'][] = $output;
2201
2202 if ($this->dontCheckForExistingTempFile || !$this->file_exists_typo3temp_file($output, $imagefile)) {
2203 $this->imageMagickExec($imagefile.$frame, $output, $command);
2204 }
2205 if (@file_exists($output)) {
2206 $info[3] = $output;
2207 $info[2] = $newExt;
2208 if ($params) { // params could realisticly change some imagedata!
2209 $info=$this->getImageDimensions($info[3]);
2210 }
2211 if ($info[2]==$this->gifExtension && !$this->dontCompress) {
2212 t3lib_div::gif_compress($info[3],''); // Compress with IM (lzw) or GD (rle) (Workaround for the absence of lzw-compression in GD)
2213 }
2214 return $info;
2215 }
2216 }
2217 }
2218 }
2219
2220 /**
2221 * Gets the input image dimensions.
2222 *
2223 * @param string The image filepath
2224 * @return array Returns an array where [0]/[1] is w/h, [2] is extension and [3] is the filename.
2225 * @see imageMagickConvert(), tslib_cObj::getImgResource()
2226 */
2227 function getImageDimensions($imageFile) {
2228 ereg('([^\.]*)$',$imageFile,$reg);
2229 if (@file_exists($imageFile) && t3lib_div::inList($this->imageFileExt,strtolower($reg[0]))) {
2230 if ($returnArr = $this->getCachedImageDimensions($imageFile)) {
2231 return $returnArr;
2232 } else {
2233 if ($temp = @getImageSize($imageFile)) {
2234 $returnArr = Array($temp[0], $temp[1], strtolower($reg[0]), $imageFile);
2235 } else {
2236 $returnArr = $this->imageMagickIdentify($imageFile);
2237 }
2238 if ($returnArr) {
2239 $this->cacheImageDimensions($returnArr);
2240 return $returnArr;
2241 }
2242 }
2243 }
2244 return false;
2245 }
2246
2247 /**
2248 * Cache the result of the getImageDimensions function into the database. Does not check if the
2249 * file exists!
2250 *
2251 * @param array $identifyResult: Result of the getImageDimensions function
2252 * @return boolean True if operation was successful
2253 * @author Michael Stucki <michael@typo3.org> / Robert Lemke <rl@robertlemke.de>
2254 */
2255 function cacheImageDimensions($identifyResult) {
2256 global $TYPO3_DB;
2257 // Create a md5 hash of the filename
2258 $md5Hash = md5_file($identifyResult[3]);
2259 if ($md5Hash) {
2260 $fieldArr = array (
2261 'md5hash' => $md5Hash,
2262 'md5filename' => md5($identifyResult[3]),
2263 'tstamp' => time(),
2264 'filename' => $identifyResult[3],
2265 'imagewidth' => $identifyResult[0],
2266 'imageheight' => $identifyResult[1],
2267 );
2268 $TYPO3_DB->exec_INSERTquery('cache_imagesizes', $fieldArr);
2269 if (!$err = $TYPO3_DB->sql_error()) {
2270 return true;
2271 }
2272 }
2273 return false;
2274 }
2275
2276 /**
2277 * Fetch the cached imageDimensions from the MySQL database. Does not check if the image file exists!
2278 *
2279 * @param string The image filepath
2280 * @return array Returns an array where [0]/[1] is w/h, [2] is extension and [3] is the filename.
2281 * @author Michael Stucki <michael@typo3.org> / Robert Lemke <rl@robertlemke.de>
2282 */
2283 function getCachedImageDimensions($imageFile) {
2284 global $TYPO3_DB;
2285 // Create a md5 hash of the filename
2286 $md5Hash = md5_file($imageFile);
2287 ereg('([^\.]*)$',$imageFile,$reg);
2288 $res = $TYPO3_DB->exec_SELECTquery ('md5hash, imagewidth, imageheight', 'cache_imagesizes', 'md5filename='.$TYPO3_DB->fullQuoteStr(md5($imageFile),'cache_imagesizes'));
2289 if ($res) {
2290 if ($row = $TYPO3_DB->sql_fetch_assoc($res)) {
2291 if ($row['md5hash']!=$md5Hash) {
2292 // file has changed, delete the row
2293 $TYPO3_DB->exec_DELETEquery ('cache_imagesizes', 'md5hash='.$TYPO3_DB->fullQuoteStr($row['md5hash'],'cache_imagesizes'));
2294 } else {
2295 return (array($row['imagewidth'], $row['imageheight'], strtolower($reg[0]), $imageFile));
2296 }
2297 }
2298 }
2299 return false;
2300 }
2301
2302 /**
2303 * Get numbers for scaling the image based on input
2304 *
2305 * @param array Current image information: Width, Height etc.
2306 * @param integer "required" width
2307 * @param integer "required" height
2308 * @param array Options: Keys are like "maxW", "maxH", "minW", "minH"
2309 * @return array
2310 * @access private
2311 * @see imageMagickConvert()
2312 */
2313 function getImageScale($info,$w,$h,$options) {
2314 if (strstr($w.$h, 'm')) {$max=1;} else {$max=0;}
2315
2316 if (strstr($w.$h, 'c')) {
2317 $out['cropH'] = intval(substr(strstr($w, 'c'), 1));
2318 $out['cropV'] = intval(substr(strstr($h, 'c'), 1));
2319 $crs = true;
2320 } else {
2321 $crs = false;
2322 }
2323 $out['crs'] = $crs;
2324
2325 $w=intval($w);
2326 $h=intval($h);
2327 // if there are max-values...
2328 if ($options['maxW']) {
2329 if ($w) { // if width is given...
2330 if ($w>$options['maxW']) {
2331 $w=$options['maxW'];
2332 $max=1; // height should follow
2333 }
2334 } else {
2335 if ($info[0]>$options['maxW']) {
2336 $w=$options['maxW'];
2337 $max=1; // height should follow
2338 }
2339 }
2340 }
2341 if ($options['maxH']) {
2342 if ($h) { // if height is given...
2343 if ($h>$options['maxH']) {
2344 $h=$options['maxH'];
2345 $max=1; // height should follow
2346 }
2347 } else {
2348 if ($info[1]>$options['maxH']) { // Changed [0] to [1] 290801
2349 $h=$options['maxH'];
2350 $max=1; // height should follow
2351 }
2352 }
2353 }
2354 $out['origW']=$w;
2355 $out['origH']=$h;
2356 $out['max'] = $max;
2357
2358 if (!$this->mayScaleUp) {
2359 if ($w>$info[0]){$w=$info[0];}
2360 if ($h>$info[1]){$h=$info[1];}
2361 }
2362 if ($w || $h) { // if scaling should be performed
2363 if ($w && !$h) {
2364 $info[1] = ceil($info[1]*($w/$info[0]));
2365 $info[0] = $w;
2366 }
2367 if (!$w && $h) {
2368 $info[0] = ceil($info[0]*($h/$info[1]));
2369 $info[1] = $h;
2370 }
2371 if ($w && $h) {
2372 if ($max) {
2373 $ratio = $info[0]/$info[1];
2374 if ($h*$ratio > $w) {
2375 $h = round($w/$ratio);
2376 } else {
2377 $w = round($h*$ratio);
2378 }
2379 }
2380 if ($crs) {
2381 $ratio = $info[0] / $info[1];
2382 if ($h * $ratio < $w) {
2383 $h = round($w / $ratio);
2384 } else {
2385 $w = round($h * $ratio);
2386 }
2387 }
2388 $info[0] = $w;
2389 $info[1] = $h;
2390 }
2391 }
2392 $out[0]=$info[0];
2393 $out[1]=$info[1];
2394 // Set minimum-measures!
2395 if ($options['minW'] && $out[0]<$options['minW']) {
2396 if (($max || $crs) && $out[0]) {
2397 $out[1]= round($out[1]*$options['minW']/$out[0]);
2398 }
2399 $out[0]=$options['minW'];
2400 }
2401 if ($options['minH'] && $out[1]<$options['minH']) {
2402 if (($max || $crs) && $out[1]) {
2403 $out[0]= round($out[0]*$options['minH']/$out[1]);
2404 }
2405 $out[1]=$options['minH'];
2406 }
2407
2408 return $out;
2409 }
2410
2411 /**
2412 * Used to check if a certain process of scaling an image is already being carried out (can be logged in the SQL database)
2413 *
2414 * @param string Output imagefile
2415 * @param string Original basis file
2416 * @return boolean Returns true if the file is already being made; thus "true" means "Don't render the image again"
2417 * @access private
2418 */
2419 function file_exists_typo3temp_file($output,$orig='') {
2420 if ($this->enable_typo3temp_db_tracking) {
2421 if (@file_exists($output)) { // If file exists, then we return immediately
2422 return 1;
2423 } else { // If not, we look up in the cache_typo3temp_log table to see if there is a image being rendered right now.
2424 $md5Hash=md5($output);
2425 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('md5hash', 'cache_typo3temp_log', 'md5hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr($md5Hash, 'cache_typo3temp_log').' AND tstamp>'.(time()-30));
2426 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { // If there was a record, the image is being generated by another proces (we assume)
2427 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...)
2428 if (is_object($GLOBALS['TT'])) $GLOBALS['TT']->setTSlogMessage('typo3temp_log: Assume this file is being rendered now: '.$output);
2429 return 2; // Return 'success - 2'
2430 } 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.
2431
2432 $insertFields = array(
2433 'md5hash' => $md5Hash,
2434 'tstamp' => time(),
2435 'filename' => $output,
2436 'orig_filename' => $orig
2437 );
2438 $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_typo3temp_log', 'md5hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr($md5Hash, 'cache_typo3temp_log'));
2439 $GLOBALS['TYPO3_DB']->exec_INSERTquery('cache_typo3temp_log', $insertFields);
2440
2441 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);
2442 return 0;
2443 }
2444 }
2445 } else {
2446 return @file_exists($output);
2447 }
2448 }
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467 /***********************************
2468 *
2469 * ImageMagick API functions
2470 *
2471 ***********************************/
2472
2473 /**
2474 * Returns an array where [0]/[1] is w/h, [2] is extension and [3] is the filename.
2475 * Using ImageMagick
2476 *
2477 * @param string The relative (to PATH_site) image filepath
2478 * @return array
2479 */
2480 function imageMagickIdentify($imagefile) {
2481 if (!$this->NO_IMAGE_MAGICK) {
2482 $frame = $this->noFramePrepended?'':'[0]';
2483 $cmd = t3lib_div::imageMagickCommand('identify', $this->wrapFileName($imagefile).$frame);
2484 $returnVal = array();
2485 exec($cmd, $returnVal);
2486 $splitstring=$returnVal[0];
2487 $this->IM_commands[] = Array ('identify',$cmd,$returnVal[0]);
2488 if ($splitstring) {
2489 ereg('([^\.]*)$',$imagefile,$reg);
2490 $splitinfo = explode(' ', $splitstring);
2491 while (list($key,$val) = each($splitinfo)) {
2492 $temp = '';
2493 if ($val) {$temp = explode('x', $val);}
2494 if (intval($temp[0]) && intval($temp[1])) {
2495 $dim=$temp;
2496 break;
2497 }
2498 }
2499 if ($dim[0] && $dim[1]) {
2500 return Array($dim[0], $dim[1], strtolower($reg[0]), $imagefile);
2501 }
2502 }
2503 }
2504 }
2505
2506 /**
2507 * Executes a ImageMagick "convert" on two filenames, $input and $output using $params before them.
2508 * Can be used for many things, mostly scaling and effects.
2509 *
2510 * @param string The relative (to PATH_site) image filepath, input file (read from)
2511 * @param string The relative (to PATH_site) image filepath, output filename (written to)
2512 * @param string ImageMagick parameters
2513 * @return string The result of a call to PHP function "exec()"
2514 */
2515 function imageMagickExec($input,$output,$params) {
2516 if (!$this->NO_IMAGE_MAGICK) {
2517 $cmd = t3lib_div::imageMagickCommand('convert', $params.' '.$this->wrapFileName($input).' '.$this->wrapFileName($output));
2518 $this->IM_commands[] = array($output,$cmd);
2519
2520 $ret = exec($cmd);
2521 t3lib_div::fixPermissions($this->wrapFileName($output)); // Change the permissions of the file
2522
2523 return $ret;
2524 }
2525 }
2526
2527 /**
2528 * 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)
2529 * Can be used for many things, mostly scaling and effects.
2530 *
2531 * @param string The relative (to PATH_site) image filepath, bottom file
2532 * @param string The relative (to PATH_site) image filepath, overlay file (top)
2533 * @param string The relative (to PATH_site) image filepath, the mask file (grayscale)
2534 * @param string The relative (to PATH_site) image filepath, output filename (written to)
2535 * @param [type] $handleNegation: ...
2536 * @return void
2537 */
2538 function combineExec($input,$overlay,$mask,$output, $handleNegation = false) {
2539 if (!$this->NO_IMAGE_MAGICK) {
2540 $params = '-colorspace GRAY +matte';
2541 if ($handleNegation) {
2542 if ($this->maskNegate) {
2543 $params .= ' '.$this->maskNegate;
2544 }
2545 }
2546 $theMask = $this->randomName().'.'.$this->gifExtension;
2547 $this->imageMagickExec($mask, $theMask, $params);
2548 $cmd = t3lib_div::imageMagickCommand('combine', '-compose over +matte '.$this->wrapFileName($input).' '.$this->wrapFileName($overlay).' '.$this->wrapFileName($theMask).' '.$this->wrapFileName($output)); // +matte = no alpha layer in output
2549 $this->IM_commands[] = Array ($output,$cmd);
2550
2551 $ret = exec($cmd);
2552 t3lib_div::fixPermissions($this->wrapFileName($output)); // Change the permissions of the file
2553
2554 if (is_file($theMask)) {
2555 @unlink($theMask);
2556 }
2557
2558 return $ret;
2559 }
2560 }
2561
2562 /**
2563 * Wrapping the input filename in double-quotes
2564 *
2565 * @param string Input filename
2566 * @return string The output wrapped in "" (if there are spaces in the filepath)
2567 * @access private
2568 */
2569 function wrapFileName($inputName) {
2570 if (strstr($inputName,' ')) {
2571 $inputName='"'.$inputName.'"';
2572 }
2573 return $inputName;
2574 }
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598 /***********************************
2599 *
2600 * Various IO functions
2601 *
2602 ***********************************/
2603
2604 /**
2605 * Returns true if the input file existed
2606 *
2607 * @param string Input file to check
2608 * @return string Returns the filename if the file existed, otherwise empty.
2609 */
2610 function checkFile($file) {
2611 if (@is_file($file)) {
2612 return $file;
2613 } else {
2614 return '';
2615 }
2616 }
2617
2618 /**
2619 * Creates subdirectory in typo3temp/ if not already found.
2620 *
2621 * @param string Name of sub directory
2622 * @return boolean Result of t3lib_div::mkdir(), true if it went well.
2623 */
2624 function createTempSubDir($dirName) {
2625
2626 // Checking if the this->tempPath is already prefixed with PATH_site and if not, prefix it with that constant.
2627 if (t3lib_div::isFirstPartOfStr($this->tempPath,PATH_site)) {
2628 $tmpPath = $this->tempPath;
2629 } else {
2630 $tmpPath = PATH_site.$this->tempPath;
2631 }
2632
2633 // Making the temporary filename:
2634 if (!@is_dir($tmpPath.$dirName)) {
2635 return t3lib_div::mkdir($tmpPath.$dirName);
2636 }
2637 }
2638
2639 /**
2640 * 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.
2641 *
2642 * @param pointer The image pointer (reference)
2643 * @param string The ImageMagick parameters. Like effects, scaling etc.
2644 * @return void
2645 */
2646 function applyImageMagickToPHPGif(&$im, $command) {
2647 $tmpStr = $this->randomName();
2648 $theFile = $tmpStr.'.'.$this->gifExtension;
2649 $this->ImageWrite($im, $theFile);
2650 $this->imageMagickExec($theFile,$theFile,$command);
2651 $tmpImg = $this->imageCreateFromFile($theFile);
2652 if ($tmpImg) {
2653 ImageDestroy($im);
2654 $im = $tmpImg;
2655 $this->w = imagesx($im);
2656 $this->h = imagesy($im);
2657 }
2658 if (!$this->dontUnlinkTempFiles) {
2659 unlink($theFile);
2660 }
2661 }
2662
2663 /**
2664 * 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.
2665 * For example: If the number of pixels exceeds $this->pixelLimitGif (normally 10000) then it will be a "jpg" string in return.
2666 *
2667 * @param string The file extension, lowercase.
2668 * @param integer The width of the output image.
2669 * @param integer The height of the output image.
2670 * @return string The filename, either "jpg" or "gif"/"png" (whatever $this->gifExtension is set to.)
2671 */
2672 function gif_or_jpg($type,$w,$h) {
2673 if ($type=='ai' || $w*$h < $this->pixelLimitGif) {
2674 return $this->gifExtension;
2675 } else {
2676 return 'jpg';
2677 }
2678 }
2679
2680 /**
2681 * Writing the internal image pointer, $this->im, to file based on the extension of the input filename
2682 * Used in GIFBUILDER
2683 * Uses $this->setup['reduceColors'] for gif/png images and $this->setup['quality'] for jpg images to reduce size/quality if needed.
2684 *
2685 * @param string The filename to write to.
2686 * @return string Returns input filename
2687 * @see tslib_gifBuilder::gifBuild()
2688 */
2689 function output($file) {
2690 if ($file) {
2691 $reg = array();
2692 ereg('([^\.]*)$',$file,$reg);
2693 $ext=strtolower($reg[0]);
2694 switch($ext) {
2695 case 'gif':
2696 case 'png':
2697 if ($this->ImageWrite($this->im, $file)) {
2698 // ImageMagick operations
2699 if ($this->setup['reduceColors'] || (!$this->png_truecolor && $this->truecolor)) {
2700 $reduced = $this->IMreduceColors($file, t3lib_div::intInRange($this->setup['reduceColors'], 256, $this->truecolorColors, 256));
2701 if ($reduced) {
2702 @copy($reduced, $file);
2703 @unlink($reduced);
2704 }
2705 }
2706 t3lib_div::gif_compress($file, 'IM'); // Compress with IM! (adds extra compression, LZW from ImageMagick) (Workaround for the absence of lzw-compression in GD)
2707 }
2708 break;
2709 case 'jpg':
2710 case 'jpeg':
2711 $quality = 0; // Use the default
2712 if($this->setup['quality']) {
2713 $quality = t3lib_div::intInRange($this->setup['quality'],10,100);
2714 }
2715 if ($this->ImageWrite($this->im, $file, $quality));
2716 break;
2717 }
2718 $GLOBALS['TEMP_IMAGES_ON_PAGE'][]=$file;
2719 }
2720 return $file;
2721 }
2722
2723 /**
2724 * Destroy internal image pointer, $this->im
2725 *
2726 * @return void
2727 * @see tslib_gifBuilder::gifBuild()
2728 */
2729 function destroy() {
2730 ImageDestroy($this->im);
2731 }
2732
2733 /**
2734 * Returns Image Tag for input image information array.
2735 *
2736 * @param array Image information array, key 0/1 is width/height and key 3 is the src value
2737 * @return string Image tag for the input image information array.
2738 */
2739 function imgTag ($imgInfo) {
2740 return '<img src="'.$imgInfo[3].'" width="'.$imgInfo[0].'" height="'.$imgInfo[1].'" border="0" alt="" />';
2741 }
2742
2743 /**
2744 * Writes the input GDlib image pointer to file
2745 *
2746 * @param pointer The GDlib image resource pointer
2747 * @param string The filename to write to
2748 * @param integer The image quality (for JPEGs)
2749 * @return mixed The output of either imageGif, imagePng or imageJpeg based on the filename to write
2750 * @see maskImageOntoImage(), scale(), output()
2751 */
2752 function ImageWrite($destImg, $theImage, $quality=0) {
2753 imageinterlace ($destImg,0);
2754 $ext = strtolower(substr($theImage, strrpos($theImage, '.')+1));
2755 switch ($ext) {
2756 case 'jpg':
2757 case 'jpeg':
2758 if (function_exists('imageJpeg')) {
2759 if ($quality == 0) {
2760 $quality = $this->jpegQuality;
2761 }
2762 return imageJpeg($destImg, $theImage, $quality);
2763 }
2764 break;
2765 case 'gif':
2766 if (function_exists('imageGif')) {
2767 if ($this->truecolor) {
2768 imagetruecolortopalette($destImg, true, 256);
2769 }
2770 return imageGif($destImg, $theImage);
2771 }
2772 break;
2773 case 'png':
2774 if (function_exists('imagePng')) {
2775 return ImagePng($destImg, $theImage);
2776 }
2777 break;
2778 }
2779 return false; // Extension invalid or write-function does not exist
2780 }
2781
2782
2783
2784 /**
2785 * Writes the input GDlib image pointer to file. Now just a wrapper to ImageWrite.
2786 *
2787 * @param pointer The GDlib image resource pointer
2788 * @param string The filename to write to
2789 * @return mixed The output of either imageGif, imagePng or imageJpeg based on the filename to write
2790 * @see imageWrite()
2791 * @deprecated
2792 */
2793 function imageGif($destImg, $theImage) {
2794 return $this->imageWrite($destImg, $theImage);
2795 }
2796
2797 /**
2798 * This function has been renamed and only exists for providing backwards compatibility.
2799 * Please use $this->imageCreateFromFile() instead.
2800 *
2801 * @param string Image filename
2802 * @return pointer Image Resource pointer
2803 * @deprecated
2804 */
2805 function imageCreateFromGif($sourceImg) {
2806 return $this->imageCreateFromFile($sourceImg);
2807 }
2808
2809 /**
2810 * Creates a new GDlib image resource based on the input image filename.
2811 * 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.
2812 *
2813 * @param string Image filename
2814 * @return pointer Image Resource pointer
2815 */
2816 function imageCreateFromFile($sourceImg) {
2817 $imgInf = pathinfo($sourceImg);
2818 $ext = strtolower($imgInf['extension']);
2819
2820 switch ($ext) {
2821 case 'gif':
2822 if (function_exists('imagecreatefromgif')) {
2823 return imageCreateFromGif($sourceImg);
2824 }
2825 break;
2826 case 'png':
2827 if (function_exists('imagecreatefrompng')) {
2828 return imageCreateFromPng($sourceImg);
2829 }
2830 break;
2831 case 'jpg':
2832 case 'jpeg':
2833 if (function_exists('imagecreatefromjpeg')) {
2834 return imageCreateFromJpeg($sourceImg);
2835 }
2836 break;
2837 }
2838
2839 // If non of the above:
2840 $i = @getimagesize($sourceImg);
2841 $im = $this->imagecreate($i[0],$i[1]);
2842 $Bcolor = ImageColorAllocate($im, 128,128,128);
2843 ImageFilledRectangle($im, 0, 0, $i[0], $i[1], $Bcolor);
2844 return $im;
2845 }
2846
2847
2848 /**
2849 * Creates a new GD image resource. Wrapper for imagecreate(truecolor) depended if GD2 is used.
2850 *
2851 * @param integer Width of image
2852 * @param integer Height of image
2853 * @return pointer Image Resource pointer
2854 */
2855 function imagecreate($w, $h) {
2856 if($this->truecolor && function_exists('imagecreatetruecolor')) {
2857 return imagecreatetruecolor($w, $h);
2858 } else {
2859 return imagecreate($w, $h);
2860 }
2861
2862 }
2863
2864 /**
2865 * Returns the HEX color value for an RGB color array
2866 *
2867 * @param array RGB color array
2868 * @return string HEX color value
2869 */
2870 function hexColor($col) {
2871 $r = dechex($col[0]);
2872 if (strlen($r)<2) { $r = '0'.$r; }
2873 $g = dechex($col[1]);
2874 if (strlen($g)<2) { $g = '0'.$g; }
2875 $b = dechex($col[2]);
2876 if (strlen($b)<2) { $b = '0'.$b; }
2877 return '#'.$r.$g.$b;
2878 }
2879
2880 /**
2881 * Unifies all colors given in the colArr color array to the first color in the array.
2882 *
2883 * @param pointer Image resource
2884 * @param array Array containing RGB color arrays
2885 * @param [type] $closest: ...
2886 * @return integer The index of the unified color
2887 */
2888 function unifyColors(&$img, $colArr, $closest = false) {
2889 $retCol = -1;
2890 if (is_array($colArr) && count($colArr) && function_exists('imagepng') && function_exists('imagecreatefrompng')) {
2891 $firstCol = array_shift($colArr);
2892 $firstColArr = $this->convertColor($firstCol);
2893 if (count($colArr)>1) {
2894 $origName = $preName = $this->randomName().'.png';
2895 $postName = $this->randomName().'.png';
2896 $this->imageWrite($img, $preName);
2897 $firstCol = $this->hexColor($firstColArr);
2898 foreach ($colArr as $transparentColor) {
2899 $transparentColor = $this->convertColor($transparentColor);
2900 $transparentColor = $this->hexColor($transparentColor);
2901 $cmd = '-fill "'.$firstCol.'" -opaque "'.$transparentColor.'"';
2902 $this->imageMagickExec($preName, $postName, $cmd);
2903 $preName = $postName;
2904 }
2905 $this->imageMagickExec($postName, $origName, '');
2906 if (@is_file($origName)) {
2907 $tmpImg = $this->imageCreateFromFile($origName);
2908 }
2909 } else {
2910 $tmpImg = $img;
2911 }
2912 if ($tmpImg) {
2913 $img = $tmpImg;
2914 if ($closest) {
2915 $retCol = ImageColorClosest ($img, $firstColArr[0], $firstColArr[1], $firstColArr[2]);
2916 } else {
2917 $retCol = ImageColorExact ($img, $firstColArr[0], $firstColArr[1], $firstColArr[2]);
2918 }
2919 }
2920 // unlink files from process
2921 if (!$this->dontUnlinkTempFiles) {
2922 if ($origName) {
2923 @unlink($origName);
2924 }
2925 if ($postName) {
2926 @unlink($postName);
2927 }
2928 }
2929 }
2930 return $retCol;
2931 }
2932
2933
2934 }
2935
2936 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_stdgraphic.php']) {
2937 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_stdgraphic.php']);
2938 }
2939 ?>