2 /***************************************************************
5 * (c) 1999-2004 Kasper Skaarhoj (kasper@typo3.com)
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.
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.
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.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
28 * Standard graphical functions
31 * Revised for TYPO3 3.6 July/2003 by Kasper Skaarhoj
33 * @author Kasper Skaarhoj <kasper@typo3.com>
36 * [CLASS/FUNCTION INDEX of SCRIPT]
40 * 143: class t3lib_stdGraphic
41 * 218: function init()
43 * SECTION: Layering images / "IMAGE" GIFBUILDER object
44 * 317: function maskImageOntoImage(&$im,$conf,$workArea)
45 * 377: function copyImageOntoImage(&$im,$conf,$workArea)
46 * 399: function copyGifOntoGif(&$im,$cpImg,$conf,$workArea)
47 * 478: function imagecopyresized(&$im, $cpImg, $Xstart, $Ystart, $cpImgCutX, $cpImgCutY, $w, $h, $w, $h)
49 * SECTION: Text / "TEXT" GIFBUILDER object
50 * 527: function makeText(&$im,$conf,$workArea)
51 * 643: function txtPosition($conf,$workArea,$BB)
52 * 697: function calcBBox($conf)
53 * 766: function addToMap($cords,$conf)
54 * 787: function calcTextCordsForMap($cords,$offset, $conf)
55 * 820: function SpacedImageTTFText(&$im, $fontSize, $angle, $x, $y, $Fcolor, $fontFile, $text, $spacing, $wordSpacing)
56 * 853: function fontResize($conf)
58 * SECTION: Other GIFBUILDER objects related to TEXT
59 * 915: function makeOutline(&$im,$conf,$workArea,$txtConf)
60 * 944: function circleOffset($distance, $iterations)
61 * 968: function makeEmboss(&$im,$conf,$workArea,$txtConf)
62 * 990: function makeShadow(&$im,$conf,$workArea,$txtConf)
64 * SECTION: Other GIFBUILDER objects
65 * 1120: function makeBox(&$im,$conf,$workArea)
66 * 1139: function makeEffect(&$im, $conf)
67 * 1154: function IMparams($setup)
68 * 1237: function adjust(&$im, $conf)
69 * 1269: function crop(&$im,$conf)
70 * 1299: function scale(&$im,$conf)
71 * 1331: function setWorkArea($workArea)
73 * SECTION: Adjustment functions
74 * 1372: function autolevels(&$im)
75 * 1403: function outputLevels(&$im,$low,$high,$swap='')
76 * 1435: function inputLevels(&$im,$low,$high,$swap='')
77 * 1466: function reduceColors(&$im,$limit, $cols)
79 * SECTION: GIFBUILDER Helper functions
80 * 1504: function prependAbsolutePath($fontFile)
81 * 1518: function v5_sharpen($factor)
82 * 1537: function v5_blur($factor)
83 * 1554: function randomName()
84 * 1566: function applyOffset($cords,$OFFSET)
85 * 1579: function convertColor($string)
86 * 1629: function recodeString($string)
87 * 1650: function singleChars($theText)
88 * 1673: function objPosition($conf,$workArea,$BB)
90 * SECTION: Scaling, Dimensions of images
91 * 1752: function imageMagickConvert($imagefile,$newExt='',$w='',$h='',$params='',$frame='',$options='',$mustCreate=0)
92 * 1835: function getImageDimensions($imageFile)
93 * 1863: function cacheImageDimensions($identifyResult)
94 * 1895: function getCachedImageDimensions($imageFile)
95 * 1930: function getImageScale($info,$w,$h,$options)
96 * 2018: function file_exists_typo3temp_file($output,$orig='')
98 * SECTION: ImageMagick API functions
99 * 2079: function imageMagickIdentify($imagefile)
100 * 2112: function imageMagickExec($input,$output,$params)
101 * 2130: function combineExec($input,$overlay,$mask,$output)
102 * 2145: function wrapFileName($inputName)
104 * SECTION: Various IO functions
105 * 2186: function checkFile($file)
106 * 2201: function applyImageMagickToPHPGif(&$im, $command)
107 * 2227: function gif_or_jpg($type,$w,$h)
108 * 2244: function output($file)
109 * 2288: function destroy()
110 * 2298: function imgTag ($imgInfo)
111 * 2310: function ImageGif($destImg, $theImage)
112 * 2327: function imageCreateFromGif($sourceImg)
114 * TOTAL FUNCTIONS: 54
115 * (This index is automatically created/updated by the extension "extdeveval")
135 * Class contains a bunch of cool functions for manipulating graphics with GDlib/Freetype and ImageMagick
136 * VERY OFTEN used with gifbuilder that extends this class and provides a TypoScript API to using these functions
138 * @author Kasper Skaarhoj <kasper@typo3.com>
141 * @see tslib_gifBuilder
143 class t3lib_stdGraphic
{
145 // Internal configuration, set in init()
146 var $combineScript = 'combine'; // The ImageMagick filename used for combining two images. This name changed during the versions.
147 var $noFramePrepended=0; // If set, there is no frame pointer prepended to the filenames.
148 var $GD2=0; // Set, if the GDlib used is version 2.
149 var $imagecopyresized_fix=0; // If set, imagecopyresized will not be called directly. For GD2 (some PHP installs?)
150 var $gifExtension = 'gif'; // This should be changed to 'png' if you want this class to read/make PNG-files instead!
151 var $TTFLocaleConv = ''; // Used to recode input to TTF-functions for other charsets.
152 var $enable_typo3temp_db_tracking = 0; // If set, then all files in typo3temp will be logged in a database table. In addition to being a log of the files with original filenames, it also serves to secure that the same image is not rendered simultaneously by two different processes.
153 var $imageMagickPath = ''; // path to imageMagick, eg: /usr/lib/
154 var $imageFileExt = 'gif,jpg,jpeg,png,tif,bmp,tga,pcx,ai,pdf'; // Commalist of file extensions perceived as images by TYPO3. List should be set to 'gif,png,jpeg,jpg' if IM is not available. Lowercase and no spaces between!
155 var $webImageExt = 'gif,jpg,jpeg,png'; // Commalist of web image extensions (can be shown by a webbrowser)
156 var $maskNegate = ''; // Will be ' -negate' if ImageMagick ver 5.2+. See init();
157 var $NO_IM_EFFECTS = '';
159 'jpg' => '-colorspace RGB -sharpen 50 -quality 60',
160 'jpeg' => '-colorspace RGB -sharpen 50 -quality 60',
161 'gif' => '-colors 64',
162 'png' => '-colors 64'
164 var $NO_IMAGE_MAGICK = '';
168 // Variables for testing, alternative usage etc.
169 var $filenamePrefix=''; // Filename prefix for images scaled in imageMagickConvert()
170 var $imageMagickConvert_forceFileNameBody=''; // Forcing the output filename of imageMagickConvert() to this value. However after calling imageMagickConvert() it will be set blank again.
171 var $dontCheckForExistingTempFile = 0; // This flag should always be false. If set true, imageMagickConvert will always write a new file to the tempdir! Used for debugging.
172 var $dontCompress=0; // Prevents imageMagickConvert() from compressing the gif-files with t3lib_div::gif_compress()
173 var $dontUnlinkTempFiles=0; // For debugging ONLY!
174 var $alternativeOutputKey=''; // For debugging only. Filenames will not be based on mtime and only filename (not path) will be used. This key is also included in the hash of the filename...
177 var $IM_commands = Array(); // All ImageMagick commands executed is stored in this array for tracking. Used by the Install Tools Image section
178 var $workArea = Array();
181 var $tempPath = 'typo3temp/'; // The temp-directory where to store the files. Relative to PATH_site.
182 var $scalecmd = '-geometry'; // ImageMagick scaling command; "-geometry" eller "-sample". Used in makeText() and imageMagickConvert()
183 var $im5fx_blurSteps='1x2,2x2,3x2,4x3,5x3,5x4,6x4,7x5,8x5,9x5'; // Used by v5_blur() to simulate 10 continuous steps of blurring
184 var $im5fx_sharpenSteps='1x2,2x2,3x2,2x3,3x3,4x3,3x4,4x4,4x5,5x5'; // Used by v5_sharpen() to simulate 10 continuous steps of sharpening.
185 var $pixelLimitGif = 10000; // This is the limit for the number of pixels in an image before it will be rendered as JPG instead of GIF/PNG
186 var $colMap = Array ( // Array mapping HTML color names to RGB values.
187 'aqua' => Array(0,255,255),
188 'black' => Array(0,0,0),
189 'blue' => Array(0,0,255),
190 'fuchsia' => Array(255,0,255),
191 'gray' => Array(128,128,128),
192 'green' => Array(0,128,0),
193 'lime' => Array(0,255,0),
194 'maroon' => Array(128,0,0),
195 'navy' => Array(0,0,128),
196 'olive' => Array(128,128,0),
197 'purple' => Array(128,0,128),
198 'red' => Array(255,0,0),
199 'silver' => Array(192,192,192),
200 'teal' => Array(0,128,128),
201 'yellow' => Array(255,255,0),
202 'white' => Array(255,255,255)
205 // Charset conversion object:
207 var $nativeCharset=''; // Is set to the native character set of the input strings.
214 * Init function. Must always call this when using the class.
215 * This function will read the configuration information from $GLOBALS['TYPO3_CONF_VARS']['GFX'] can set some values in internal variables.
220 $gfxConf = $GLOBALS['TYPO3_CONF_VARS']['GFX'];
222 if ($gfxConf['im_combine_filename']) $this->combineScript
=$gfxConf['im_combine_filename'];
223 if ($gfxConf['im_noFramePrepended']) $this->noFramePrepended
=1;
225 if ($gfxConf['gdlib_2']) {
227 $this->imagecopyresized_fix
= $gfxConf['gdlib_2']==='no_imagecopyresized_fix' ?
0 : 1;
229 if ($gfxConf['gdlib_png']) {
230 $this->gifExtension
='png';
232 if ($gfxConf['TTFLocaleConv']) {
233 $this->TTFLocaleConv
= $gfxConf['TTFLocaleConv'];
235 if ($gfxConf['enable_typo3temp_db_tracking']) {
236 $this->enable_typo3temp_db_tracking
= $gfxConf['enable_typo3temp_db_tracking'];
239 $this->imageMagickPath
= $gfxConf['im_path'];
240 $this->imageFileExt
= $gfxConf['imagefile_ext'];
242 // This should be set if ImageMagick ver. 5+ is used.
243 if ($gfxConf['im_negate_mask']) {
244 // Boolean. Indicates if the mask images should be inverted first.
245 // This depends of the ImageMagick version. Below ver. 5.1 this should be false.
246 // Above ImageMagick version 5.2+ it should be true.
247 // Just set the flag if the masks works opposite the intension!
248 $this->maskNegate
= ' -negate';
250 if ($gfxConf['im_no_effects']) {
251 // Boolean. This is necessary if using ImageMagick 5+.
252 // Approved version for using effects is version 4.2.9.
253 // Effects in Imagemagick 5+ tends to render very slowly!!
254 // - therefore must be disabled in order not to perform sharpen, blurring and such.
255 $this->NO_IM_EFFECTS
= 1;
257 $this->cmds
['jpg'] = '-colorspace RGB -quality 60';
258 $this->cmds
['jpeg'] = '-colorspace RGB -quality 60';
260 // ... but if 'im_v5effects' is set, dont care about 'im_no_effects'
261 if ($gfxConf['im_v5effects']) {
262 $this->NO_IM_EFFECTS
= 0;
263 $this->V5_EFFECTS
= 1;
265 if ($gfxConf['im_v5effects']>0) {
266 $this->cmds
['jpg'] = '-colorspace RGB -quality 60'.$this->v5_sharpen(10);
267 $this->cmds
['jpeg'] = '-colorspace RGB -quality 60'.$this->v5_sharpen(10);
271 if (!$gfxConf['im']) {
272 $this->NO_IMAGE_MAGICK
= 1;
274 // Secures that images are not scaled up.
275 if ($gfxConf['im_noScaleUp']) {
279 if (TYPO3_MODE
=='FE') {
280 $this->csConvObj
= &$GLOBALS['TSFE']->csConvObj
;
281 } else { // BE assumed:
282 $this->csConvObj
= &$GLOBALS['LANG']->csConvObj
;
284 $this->nativeCharset
= $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'];
302 /*************************************************
304 * Layering images / "IMAGE" GIFBUILDER object
306 *************************************************/
309 * Implements the "IMAGE" GIFBUILDER object, when the "mask" property is true.
310 * It reads the two images defined by $conf['file'] and $conf['mask'] and copies the $conf['file'] onto the input image pointer image using the $conf['mask'] as a grayscale mask
311 * The operation involves ImageMagick for combining.
313 * @param pointer GDlib image pointer
314 * @param array TypoScript array with configuration for the GIFBUILDER object.
315 * @param array The current working area coordinates.
317 * @see tslib_gifBuilder::make()
319 function maskImageOntoImage(&$im,$conf,$workArea) {
320 if ($conf['file'] && $conf['mask']) {
321 $BBimage = $this->imageMagickConvert($conf['file'],$this->gifExtension
,'','','','','');
322 $BBmask = $this->imageMagickConvert($conf['mask'],$this->gifExtension
,'','','','','');
323 if ($BBimage && $BBmask) {
326 $tmpStr = $this->randomName();
327 $theImage = $tmpStr.'_img.'.$this->gifExtension
;
328 $theDest = $tmpStr.'_dest.'.$this->gifExtension
;
329 $theMask = $tmpStr.'_mask.'.$this->gifExtension
;
330 $theMask2 = $tmpStr.'_mask2.'.trim($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_mask_temp_ext_noloss']);
331 // prepare overlay image
332 $cpImg = $this->imageCreateFromGif($BBimage[3]);
333 $destImg = imagecreate($w,$h);
334 ImageColorAllocate($destImg, 0,0,0);
335 $this->copyGifOntoGif($destImg,$cpImg,$conf,$workArea);
336 $this->ImageGif($destImg, $theImage);
337 imageDestroy($cpImg);
338 imageDestroy($destImg);
339 // prepare mask image
340 $cpImg = $this->imageCreateFromGif($BBmask[3]);
341 $destImg = imagecreate($w,$h);
342 ImageColorAllocate($destImg, 0,0,0);
343 $this->copyGifOntoGif($destImg,$cpImg,$conf,$workArea);
344 $this->ImageGif($destImg, $theMask);
345 imageDestroy($cpImg);
346 imageDestroy($destImg);
348 $this->imageMagickExec($theMask,$theMask2,'-colorspace GRAY'.$this->maskNegate
);
350 $this->ImageGif($im, $theDest);
352 $this->combineExec($theDest,$theImage,$theMask2,$theDest);
354 $backIm = $this->imageCreateFromGif($theDest); // The main image is loaded again...
355 if ($backIm) { // ... and if nothing went wrong we load it onto the old one.
356 ImageColorTransparent($backIm,-1);
359 // unlink files from process
360 if (!$this->dontUnlinkTempFiles
) {
371 * Implements the "IMAGE" GIFBUILDER object, when the "mask" property is false (using only $conf['file'])
373 * @param pointer GDlib image pointer
374 * @param array TypoScript array with configuration for the GIFBUILDER object.
375 * @param array The current working area coordinates.
377 * @see tslib_gifBuilder::make(), maskImageOntoImage()
379 function copyImageOntoImage(&$im,$conf,$workArea) {
381 if ($conf['BBOX'][2]!=$this->gifExtension
) {
382 $conf['BBOX']=$this->imageMagickConvert($conf['BBOX'][3],$this->gifExtension
,'','','','','');
383 $conf['file']=$conf['BBOX'][3];
385 $cpImg = $this->imageCreateFromGif($conf['file']);
386 $this->copyGifOntoGif($im,$cpImg,$conf,$workArea);
387 imageDestroy($cpImg);
392 * Copies two GDlib image pointers onto each other, using TypoScript configuration from $conf and the input $workArea definition.
394 * @param pointer GDlib image pointer, destination (bottom image)
395 * @param pointer GDlib image pointer, source (top image)
396 * @param array TypoScript array with the properties for the IMAGE GIFBUILDER object. Only used for the "tile" property value.
397 * @param array Work area
398 * @return void Works on the $im image pointer
401 function copyGifOntoGif(&$im,$cpImg,$conf,$workArea) {
402 $cpW = imagesx($cpImg);
403 $cpH = imagesy($cpImg);
404 $tile = t3lib_div
::intExplode(',',$conf['tile']);
405 $tile[0] = t3lib_div
::intInRange($tile[0],1,20);
406 $tile[1] = t3lib_div
::intInRange($tile[1],1,20);
407 $cpOff = $this->objPosition($conf,$workArea,Array($cpW*$tile[0],$cpH*$tile[1]));
409 for ($xt=0;$xt<$tile[0];$xt++
) {
410 $Xstart=$cpOff[0]+
$cpW*$xt;
411 if ($Xstart+
$cpW > $workArea[0]) { // if this image is inside of the workArea, then go on
413 if ($Xstart < $workArea[0]) {
414 $cpImgCutX = $workArea[0]-$Xstart;
415 $Xstart = $workArea[0];
419 $w = $cpW-$cpImgCutX;
420 if ($Xstart > $workArea[0]+
$workArea[2]-$w) {
421 $w = $workArea[0]+
$workArea[2]-$Xstart;
423 if ($Xstart < $workArea[0]+
$workArea[2]) { // if this image is inside of the workArea, then go on
425 for ($yt=0;$yt<$tile[1];$yt++
) {
426 $Ystart=$cpOff[1]+
$cpH*$yt;
427 if ($Ystart+
$cpH > $workArea[1]) { // if this image is inside of the workArea, then go on
428 if ($Ystart < $workArea[1]) {
429 $cpImgCutY = $workArea[1]-$Ystart;
430 $Ystart = $workArea[1];
434 $h = $cpH-$cpImgCutY;
435 if ($Ystart > $workArea[1]+
$workArea[3]-$h) {
436 $h = $workArea[1]+
$workArea[3]-$Ystart;
438 if ($Ystart < $workArea[1]+
$workArea[3]) { // if this image is inside of the workArea, then go on
439 $this->imagecopyresized($im, $cpImg, $Xstart, $Ystart, $cpImgCutX, $cpImgCutY, $w, $h, $w, $h);
449 * Alternative function for using the similar PHP function imagecopyresized(). Used for GD2 only.
451 * OK, the reason for this stupid fix is the following story:
452 * GD1.x was capable of copying two images together and combining their palettes! GD2 is apparently not.
453 * With GD2 only the palette of the dest-image is used which mostly results in totally black images when trying to
454 * copy a color-ful image onto the destination.
456 * 1) Create a blank TRUE-COLOR image
457 * 2) Copy the destination image onto that one
458 * 3) Then do the actual operation; Copying the source (top image) onto that
459 * 4) ... and return the result pointer.
460 * 5) Reduce colors (if we do not, the result may become strange!)
461 * It works, but the resulting images is now a true-color PNG which may be very large.
462 * So, why not use 'imagetruecolortopalette ($im, TRUE, 256)' - well because it does NOT WORK! So simple is that.
464 * For parameters, see PHP function "imagecopyresized()"
466 * @param pointer see PHP function "imagecopyresized()"
467 * @param pointer see PHP function "imagecopyresized()"
468 * @param integer see PHP function "imagecopyresized()"
469 * @param integer see PHP function "imagecopyresized()"
470 * @param integer see PHP function "imagecopyresized()"
471 * @param integer see PHP function "imagecopyresized()"
472 * @param integer see PHP function "imagecopyresized()"
473 * @param integer see PHP function "imagecopyresized()"
474 * @param integer see PHP function "imagecopyresized()"
475 * @param integer see PHP function "imagecopyresized()"
478 * @see t3lib_iconWorks::imagecopyresized()
480 function imagecopyresized(&$im, $cpImg, $Xstart, $Ystart, $cpImgCutX, $cpImgCutY, $w, $h, $w, $h) {
481 if ($this->imagecopyresized_fix
) {
482 $im_base = imagecreatetruecolor(imagesx($im), imagesy($im)); // Make true color image
483 imagecopyresized($im_base, $im, 0,0,0,0, imagesx($im),imagesy($im),imagesx($im),imagesy($im)); // Copy the source image onto that
484 imagecopyresized($im_base, $cpImg, $Xstart, $Ystart, $cpImgCutX, $cpImgCutY, $w, $h, $w, $h); // Then copy the $cpImg onto that (the actual operation!)
485 $im = $im_base; // Set pointer
486 $this->makeEffect($im, Array('value'=>'colors=256')); // Reduce colors to 256 - make SURE that IM is working then!
488 imagecopyresized($im, $cpImg, $Xstart, $Ystart, $cpImgCutX, $cpImgCutY, $w, $h, $w, $h);
514 /********************************
516 * Text / "TEXT" GIFBUILDER object
518 ********************************/
521 * Implements the "TEXT" GIFBUILDER object
523 * @param pointer GDlib image pointer
524 * @param array TypoScript array with configuration for the GIFBUILDER object.
525 * @param array The current working area coordinates.
527 * @see tslib_gifBuilder::make()
529 function makeText(&$im,$conf,$workArea) {
531 $spacing = intval($conf['spacing']);
532 $wordSpacing = intval($conf['wordSpacing']);
533 $wordSpacing = $wordSpacing?
$wordSpacing:$spacing*2;
535 $txtPos = $this->txtPosition($conf,$workArea,$conf['BBOX']);
536 $theText = $this->recodeString($conf['text']);
538 if ($conf['imgMap'] && is_array($conf['imgMap.'])) {
539 $this->addToMap($this->calcTextCordsForMap($conf['BBOX'][2],$txtPos, $conf['imgMap.']), $conf['imgMap.']);
541 if (!$conf['hideButCreateMap']) {
543 $cols=$this->convertColor($conf['fontColor']);
544 // NiceText is calculated
545 if (!$conf['niceText']) {
546 // Font Color is reserved:
547 $this->reduceColors($im,256, 200);
548 $Fcolor = ImageColorAllocate($im, $cols[0],$cols[1],$cols[2]);
549 // antiAliasing is setup:
550 $Fcolor = ($conf['antiAlias']) ?
$Fcolor : -$Fcolor;
552 for ($a=0; $a<$conf['iterations']; $a++
) {
553 if ($spacing ||
$wordSpacing) { // If any kind of spacing applys, we use this function:
554 $this->SpacedImageTTFText($im, $conf['fontSize'], $conf['angle'], $txtPos[0], $txtPos[1], $Fcolor, t3lib_stdGraphic
::prependAbsolutePath($conf['fontFile']), $theText, $spacing, $wordSpacing);
556 ImageTTFText($im, t3lib_div
::freetypeDpiComp($conf['fontSize']), $conf['angle'], $txtPos[0], $txtPos[1], $Fcolor, t3lib_stdGraphic
::prependAbsolutePath($conf['fontFile']), $theText);
559 } else { // NICETEXT::
560 // options anti_aliased and iterations is NOT available when doing this!!
563 $tmpStr = $this->randomName();
565 $fileMenu = $tmpStr.'_menuNT.'.$this->gifExtension
;
566 $fileColor = $tmpStr.'_colorNT.'.$this->gifExtension
;
567 $fileMask = $tmpStr.'_maskNT.'.$this->gifExtension
;
569 $sF = t3lib_div
::intInRange($conf['niceText.']['scaleFactor'],2,5);
570 $newW = ceil($sF*imagesx($im));
571 $newH = ceil($sF*imagesy($im));
574 $maskImg = imagecreate($newW, $newH);
575 ImageColorAllocate($maskImg, 255,255,255);
576 $Fcolor = ImageColorAllocate($maskImg, 0,0,0);
577 if ($spacing ||
$wordSpacing) { // If any kind of spacing applys, we use this function:
578 $this->SpacedImageTTFText($maskImg, ceil($sF*$conf['fontSize']), $conf['angle'], ceil($sF*$txtPos[0]), ceil($sF*$txtPos[1]), $Fcolor, t3lib_stdGraphic
::prependAbsolutePath($conf['fontFile']), $theText, ceil($sF*$spacing), ceil($sF*$wordSpacing));
580 ImageTTFText($maskImg, t3lib_div
::freetypeDpiComp(ceil($sF*$conf['fontSize'])), $conf['angle'], ceil($sF*$txtPos[0]), ceil($sF*$txtPos[1]), $Fcolor, t3lib_stdGraphic
::prependAbsolutePath($conf['fontFile']), $theText);
582 $this->ImageGif($maskImg, $fileMask);
583 ImageDestroy($maskImg);
585 // Downscales the mask
586 if ($this->NO_IM_EFFECTS
) {
587 if ($this->maskNegate
) {
588 $command = trim($this->scalecmd
.' '.$w.'x'.$h.'!'); // Negate 2 times makes no negate...
590 $command = trim($this->scalecmd
.' '.$w.'x'.$h.'! -negate');
593 if ($this->maskNegate
) {
594 $command = trim($conf['niceText.']['before'].' '.$this->scalecmd
.' '.$w.'x'.$h.'! '.$conf['niceText.']['after']);
596 $command = trim($conf['niceText.']['before'].' '.$this->scalecmd
.' '.$w.'x'.$h.'! '.$conf['niceText.']['after'].' -negate');
598 if ($conf['niceText.']['sharpen']) {
599 if ($this->V5_EFFECTS
) {
600 $command.=$this->v5_sharpen($conf['niceText.']['sharpen']);
602 $command.=' -sharpen '.t3lib_div
::intInRange($conf['niceText.']['sharpen'],1,99);
606 $this->imageMagickExec($fileMask,$fileMask,$command);
608 // Make the color-file
609 $colorImg = imagecreate($w,$h);
610 ImageColorAllocate($colorImg, $cols[0],$cols[1],$cols[2]);
611 $this->ImageGif($colorImg, $fileColor);
612 ImageDestroy($colorImg);
614 // The mask is applied
615 $this->ImageGif($im, $fileMenu); // The main pictures is saved temporarily
617 $this->combineExec($fileMenu,$fileColor,$fileMask,$fileMenu);
619 $backIm = $this->imageCreateFromGif($fileMenu); // The main image is loaded again...
620 if ($backIm) { // ... and if nothing went wrong we load it onto the old one.
621 ImageColorTransparent($backIm,-1);
625 // Deleting temporary files;
626 if (!$this->dontUnlinkTempFiles
) {
636 * Calculates text position for printing the text onto the image based on configuration like alignment and workarea.
638 * @param array TypoScript array for the TEXT GIFBUILDER object
639 * @param array Workarea definition
640 * @param array Bounding box information, was set in tslib_gifBuilder::start()
641 * @return array [0]=x, [1]=y, [2]=w, [3]=h
645 function txtPosition($conf,$workArea,$BB) {
647 $angle=intval($conf['angle'])/180*pi();
649 $straightBB = $this->calcBBox($conf);
651 // offset, align, valign, workarea
652 $result=Array(); // [0]=x, [1]=y, [2]=w, [3]=h
658 switch($conf['align']) {
661 $factor=abs(cos($angle));
662 $sign=(cos($angle)<0)?
-1:1;
663 $len1 = $sign*$factor*$straightBB[0];
665 $result[0] = $w-ceil($len2*$factor+
(1-$factor)*$len1);
667 $factor=abs(sin($angle));
668 $sign=(sin($angle)<0)?
-1:1;
669 $len1= $sign*$factor*$straightBB[0];
671 $result[1]=ceil($len2*$factor+
(1-$factor)*$len1);
674 switch($conf['align']) {
678 $result[0] = round(($result[0])/2);
679 $result[1] = round(($result[1])/2);
686 $result = $this->applyOffset($result,t3lib_div
::intExplode(',',$conf['offset']));
687 $result = $this->applyOffset($result,$workArea);
692 * Calculates bounding box information for the TEXT GIFBUILDER object.
694 * @param array TypoScript array for the TEXT GIFBUILDER object
695 * @return array Array with three keys [0]/[1] being x/y and [2] being the bounding box array
697 * @see txtPosition(), tslib_gifBuilder::start()
699 function calcBBox($conf) {
700 if (!$conf['niceText']) {
702 } else { // NICETEXT::
703 $sF = t3lib_div
::intInRange($conf['niceText.']['scaleFactor'],2,5);
706 $spacing = intval($conf['spacing']);
707 $wordSpacing = intval($conf['wordSpacing']);
708 $wordSpacing = $wordSpacing?
$wordSpacing:$spacing*2;
712 $theText = $this->recodeString($conf['text']);
714 $charInf = ImageTTFBBox(t3lib_div
::freetypeDpiComp($sF*$conf['fontSize']), $conf['angle'], t3lib_stdGraphic
::prependAbsolutePath($conf['fontFile']), $theText);
715 $theBBoxInfo = $charInf;
716 if ($conf['angle']) {
717 $xArr = Array($charInf[0],$charInf[2],$charInf[4],$charInf[6]);
718 $yArr = Array($charInf[1],$charInf[3],$charInf[5],$charInf[7]);
719 $x=max($xArr)-min($xArr);
720 $y=max($yArr)-min($yArr);
722 $x = ($charInf[2]-$charInf[0]);
723 $y = ($charInf[1]-$charInf[7]);
725 if ($spacing ||
$wordSpacing) { // If any kind of spacing applys, we use this function:
727 if (!$spacing && $wordSpacing) {
728 $bits = explode(' ',$theText);
729 while(list(,$word)=each($bits)) {
731 $wordInf = ImageTTFBBox(t3lib_div
::freetypeDpiComp($sF*$conf['fontSize']), $conf['angle'], t3lib_stdGraphic
::prependAbsolutePath($conf['fontFile']), $word);
732 $wordW = ($wordInf[2]-$wordInf[0]);
733 $x+
=$wordW+
$wordSpacing;
736 $utf8Chars = $this->singleChars($theText);
737 // For each UTF-8 char, do:
738 foreach($utf8Chars as $char) {
739 $charInf = ImageTTFBBox(t3lib_div
::freetypeDpiComp($sF*$conf['fontSize']), $conf['angle'], t3lib_stdGraphic
::prependAbsolutePath($conf['fontFile']), $char);
740 $charW = ($charInf[2]-$charInf[0]);
741 $x+
=$charW+
(($char==' ')?
$wordSpacing:$spacing);
749 if (is_array($theBBoxInfo)) {
751 while(list($key,$val)=each($theBBoxInfo)) {
752 $theBBoxInfo[$key]=ceil($theBBoxInfo[$key]/$sF);
756 return Array($x,$y,$theBBoxInfo);
760 * Adds an <area> tag to the internal variable $this->map which is used to accumulate the content for an ImageMap
762 * @param array Coordinates for a polygon image map as created by ->calcTextCordsForMap()
763 * @param array Configuration for "imgMap." property of a TEXT GIFBUILDER object.
766 * @see makeText(), calcTextCordsForMap()
768 function addToMap($cords,$conf) {
769 $JS = $conf['noBlur'] ?
'' : ' onfocus="blurLink(this);"';
773 ' coords="'.implode($cords,',').'"'.
774 ' href="'.htmlspecialchars($conf['url']).'"'.
775 ($conf['target'] ?
' target="'.htmlspecialchars($conf['target']).'"' : '').
777 (strlen($conf['titleText']) ?
' title="'.htmlspecialchars($conf['titleText']).'"' : '').
778 ' alt="'.htmlspecialchars($conf['altText']).'" />';
782 * Calculating the coordinates for a TEXT string on an image map. Used in an <area> tag
784 * @param array Coordinates (from BBOX array)
785 * @param array Offset array
786 * @param array Configuration for "imgMap." property of a TEXT GIFBUILDER object.
789 * @see makeText(), calcTextCordsForMap()
791 function calcTextCordsForMap($cords,$offset, $conf) {
792 $pars = t3lib_div
::intExplode(',',$conf['explode'].',');
794 $newCords[0] = $cords[0]+
$offset[0]-$pars[0];
795 $newCords[1] = $cords[1]+
$offset[1]+
$pars[1];
796 $newCords[2] = $cords[2]+
$offset[0]+
$pars[0];
797 $newCords[3] = $cords[3]+
$offset[1]+
$pars[1];
798 $newCords[4] = $cords[4]+
$offset[0]+
$pars[0];
799 $newCords[5] = $cords[5]+
$offset[1]-$pars[1];
800 $newCords[6] = $cords[6]+
$offset[0]-$pars[0];
801 $newCords[7] = $cords[7]+
$offset[1]-$pars[1];
807 * Printing text onto an image like the PHP function imageTTFText does but in addition it offers options for spacing of letters and words.
808 * Spacing is done by printing one char at a time and this means that the spacing is rather uneven and probably not very nice.
811 * @param pointer (See argument for PHP function imageTTFtext())
812 * @param integer (See argument for PHP function imageTTFtext())
813 * @param integer (See argument for PHP function imageTTFtext())
814 * @param integer (See argument for PHP function imageTTFtext())
815 * @param integer (See argument for PHP function imageTTFtext())
816 * @param integer (See argument for PHP function imageTTFtext())
817 * @param string (See argument for PHP function imageTTFtext())
818 * @param string (See argument for PHP function imageTTFtext()). UTF-8 string, possibly with entities in.
819 * @param integer The spacing of letters in pixels
820 * @param integer The spacing of words in pixels
824 function SpacedImageTTFText(&$im, $fontSize, $angle, $x, $y, $Fcolor, $fontFile, $text, $spacing, $wordSpacing) {
825 if (!$spacing && $wordSpacing) {
826 $bits = explode(' ',$text);
828 while(list(,$word)=each($bits)) {
831 $wordInf = ImageTTFBBox(t3lib_div
::freetypeDpiComp($fontSize), $angle, t3lib_stdGraphic
::prependAbsolutePath($fontFile), $word);
832 $wordW = ($wordInf[2]-$wordInf[0]);
833 ImageTTFText($im, t3lib_div
::freetypeDpiComp($fontSize), $angle, $x, $y, $Fcolor, t3lib_stdGraphic
::prependAbsolutePath($fontFile), $word);
834 $x+
=$wordW+
$wordSpacing;
837 $utf8Chars = $this->singleChars($text);
838 // For each UTF-8 char, do:
839 foreach($utf8Chars as $char) {
840 $charInf = ImageTTFBBox(t3lib_div
::freetypeDpiComp($fontSize), $angle, t3lib_stdGraphic
::prependAbsolutePath($fontFile), $char);
841 $charW = ($charInf[2]-$charInf[0]);
842 ImageTTFText($im, t3lib_div
::freetypeDpiComp($fontSize), $angle, $x, $y, $Fcolor, t3lib_stdGraphic
::prependAbsolutePath($fontFile), $char);
843 $x+
=$charW+
(($char==' ')?
$wordSpacing:$spacing);
849 * Function that finds the right fontsize that will render the textstring within a certain width
851 * @param array The TypoScript properties of the TEXT GIFBUILDER object
852 * @return integer The new fontSize
854 * @author Rene Fritz <r.fritz@colorcube.de>
855 * @see tslib_gifBuilder::start()
857 function fontResize($conf) {
858 // you have to use +calc options like [10.h] in 'offset' to get the right position of your text-image, if you use +calc in XY height!!!!
859 $maxWidth = intval($conf['maxWidth']);
861 if ($spacing ||
$wordSpacing) { // If any kind of spacing applys, we use this function:
862 return $conf['fontSize'];
863 // ################ no calc for spacing yet !!!!!!
865 $fontSize = $conf['fontSize'];
867 $conf['fontSize'] = $fontSize;
868 // determine bounding box.
869 $bounds = ImageTTFBBox(t3lib_div
::freetypeDpiComp($conf['fontSize']), $conf['angle'], t3lib_stdGraphic
::prependAbsolutePath($conf['fontFile']), $this->recodeString($conf['text']));
870 if ($conf['angle']< 0) {
871 $pixelWidth = abs($bounds[4]-$bounds[0]);
872 } elseif ($conf['angle'] > 0) {
873 $pixelWidth = abs($bounds[2]-$bounds[6]);
875 $pixelWidth = abs($bounds[4]-$bounds[6]);
877 // This is a very raw calculation but it makes it in one step
878 $fontSize=(int)($maxWidth*$fontSize/$pixelWidth);
879 if ($fontSize >= $conf['fontSize']) {
880 $fontSize = $conf['fontSize']-1;
882 } while ($pixelWidth > $maxWidth);
885 return $conf['fontSize'];
903 /*********************************************
905 * Other GIFBUILDER objects related to TEXT
907 *********************************************/
910 * Implements the "OUTLINE" GIFBUILDER object / property for the TEXT object
912 * @param pointer GDlib image pointer
913 * @param array TypoScript array with configuration for the GIFBUILDER object.
914 * @param array The current working area coordinates.
915 * @param array TypoScript array with configuration for the associated TEXT GIFBUILDER object.
917 * @see tslib_gifBuilder::make(), makeText()
919 function makeOutline(&$im,$conf,$workArea,$txtConf) {
920 $thickness = intval($conf['thickness']);
922 $txtConf['fontColor'] = $conf['color'];
923 $outLineDist = t3lib_div
::intInRange($thickness,1,2);
924 for ($b=1;$b<=$outLineDist;$b++
) {
930 $outL = $this->circleOffset($b, $it);
931 for ($a=0;$a<$it;$a++
) {
932 $this->makeText($im,$txtConf,$this->applyOffset($workArea,$outL[$a]));
939 * Creates some offset values in an array used to simulate a circularly applied outline around TEXT
943 * @param integer Distance
944 * @param integer Iterations.
948 function circleOffset($distance, $iterations) {
950 if ($distance && $iterations) {
951 for ($a=0;$a<$iterations;$a++
) {
952 $yOff = round(sin(2*pi()/$iterations*($a+
1))*100*$distance);
953 if ($yOff) {$yOff = intval(ceil(abs($yOff/100))*($yOff/abs($yOff)));}
954 $xOff = round(cos(2*pi()/$iterations*($a+
1))*100*$distance);
955 if ($xOff) {$xOff = intval(ceil(abs($xOff/100))*($xOff/abs($xOff)));}
956 $res[$a] = Array($xOff,$yOff);
963 * Implements the "EMBOSS" GIFBUILDER object / property for the TEXT object
965 * @param pointer GDlib image pointer
966 * @param array TypoScript array with configuration for the GIFBUILDER object.
967 * @param array The current working area coordinates.
968 * @param array TypoScript array with configuration for the associated TEXT GIFBUILDER object.
970 * @see tslib_gifBuilder::make(), makeShadow()
972 function makeEmboss(&$im,$conf,$workArea,$txtConf) {
973 $conf['color']=$conf['highColor'];
974 $this->makeShadow($im,$conf,$workArea,$txtConf);
975 $newOffset = t3lib_div
::intExplode(',',$conf['offset']);
978 $conf['offset']=implode($newOffset,',');
979 $conf['color']=$conf['lowColor'];
980 $this->makeShadow($im,$conf,$workArea,$txtConf);
984 * Implements the "SHADOW" GIFBUILDER object / property for the TEXT object
985 * The operation involves ImageMagick for combining.
987 * @param pointer GDlib image pointer
988 * @param array TypoScript array with configuration for the GIFBUILDER object.
989 * @param array The current working area coordinates.
990 * @param array TypoScript array with configuration for the associated TEXT GIFBUILDER object.
992 * @see tslib_gifBuilder::make(), makeText(), makeEmboss()
994 function makeShadow(&$im,$conf,$workArea,$txtConf) {
995 $workArea = $this->applyOffset($workArea,t3lib_div
::intExplode(',',$conf['offset']));
996 $blurRate = t3lib_div
::intInRange(intval($conf['blur']),0,99);
998 if (!$blurRate ||
$this->NO_IM_EFFECTS
) { // No effects if ImageMagick ver. 5+
999 $txtConf['fontColor'] = $conf['color'];
1000 $this->makeText($im,$txtConf,$workArea);
1004 $blurBorder= 3; // area around the blur used for cropping something
1005 $tmpStr = $this->randomName();
1006 $fileMenu = $tmpStr.'_menu.'.$this->gifExtension
;
1007 $fileColor = $tmpStr.'_color.'.$this->gifExtension
;
1008 $fileMask = $tmpStr.'_mask.'.$this->gifExtension
;
1010 // BlurColor Image laves
1011 $blurColImg = imagecreate($w,$h);
1012 $bcols=$this->convertColor($conf['color']);
1013 ImageColorAllocate($blurColImg, $bcols[0],$bcols[1],$bcols[2]);
1014 $this->ImageGif($blurColImg, $fileColor);
1015 ImageDestroy($blurColImg);
1017 // The mask is made: BlurTextImage
1018 $blurTextImg = imagecreate($w+
$blurBorder*2,$h+
$blurBorder*2);
1019 ImageColorAllocate($blurTextImg, 0,0,0); // black background
1020 $txtConf['fontColor'] = 'white';
1021 $blurBordArr = Array($blurBorder,$blurBorder);
1022 $this->makeText($blurTextImg,$txtConf, $this->applyOffset($workArea,$blurBordArr));
1023 $this->ImageGif($blurTextImg, $fileMask); // dump to temporary file
1024 ImageDestroy($blurTextImg); // destroy
1028 $command.=$this->maskNegate
;
1030 if ($this->V5_EFFECTS
) {
1031 $command.=$this->v5_blur($blurRate+
1);
1033 // Blurring of the mask
1034 $times = ceil($blurRate/10); // How many blur-commands that is executed. Min = 1;
1035 $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.
1036 $newBlurRate = t3lib_div
::intInRange($newBlurRate,1,99);
1037 for ($a=0;$a<$times;$a++
) { // Building blur-command
1038 $command.=' -blur '.$blurRate;
1042 $this->imageMagickExec($fileMask,$fileMask,$command);
1044 $blurTextImg_tmp = $this->imageCreateFromGif($fileMask); // the mask is loaded again
1045 if ($blurTextImg_tmp) { // if nothing went wrong we continue with the blurred mask
1047 // cropping the border from the mask
1048 $blurTextImg = imagecreate($w,$h);
1049 $this->imagecopyresized($blurTextImg, $blurTextImg_tmp, 0, 0, $blurBorder, $blurBorder, $w, $h, $w, $h);
1050 ImageDestroy($blurTextImg_tmp); // Destroy the temporary mask
1054 if ($conf['intensity']) {
1055 $intensity = t3lib_div
::intInRange($conf['intensity'],0,100);
1057 $intensity = ceil(255-($intensity/100*255));
1058 $this->inputLevels($blurTextImg,0,$intensity,$this->maskNegate
);
1060 $opacity = t3lib_div
::intInRange(intval($conf['opacity']),0,100);
1061 if ($opacity && $opacity<100) {
1062 $high = ceil(255*$opacity/100);
1063 $this->outputLevels($blurTextImg,0,$high,$this->maskNegate
); // reducing levels as the opacity demands
1066 $this->ImageGif($blurTextImg, $fileMask); // Dump the mask again
1067 ImageDestroy($blurTextImg); // Destroy the mask
1069 // The pictures are combined
1070 $this->ImageGif($im, $fileMenu); // The main pictures is saved temporarily
1072 $this->combineExec($fileMenu,$fileColor,$fileMask,$fileMenu);
1074 $backIm = $this->imageCreateFromGif($fileMenu); // The main image is loaded again...
1075 if ($backIm) { // ... and if nothing went wrong we load it onto the old one.
1076 ImageColorTransparent($backIm,-1);
1080 // Deleting temporary files;
1081 if (!$this->dontUnlinkTempFiles
) {
1109 /****************************
1111 * Other GIFBUILDER objects
1113 ****************************/
1116 * Implements the "BOX" GIFBUILDER object
1118 * @param pointer GDlib image pointer
1119 * @param array TypoScript array with configuration for the GIFBUILDER object.
1120 * @param array The current working area coordinates.
1122 * @see tslib_gifBuilder::make()
1124 function makeBox(&$im,$conf,$workArea) {
1125 $cords = t3lib_div
::intExplode(',',$conf['dimensions'].',,,');
1126 $conf['offset']=$cords[0].','.$cords[1];
1127 $cords = $this->objPosition($conf,$workArea,Array($cords[2],$cords[3]));
1128 $cols=$this->convertColor($conf['color']);
1129 $this->reduceColors($im,256, 255);
1130 $tmpColor = ImageColorAllocate($im, $cols[0],$cols[1],$cols[2]);
1131 imagefilledrectangle($im, $cords[0], $cords[1], $cords[0]+
$cords[2]-1, $cords[1]+
$cords[3]-1, $tmpColor);
1135 * Implements the "EFFECT" GIFBUILDER object
1136 * The operation involves ImageMagick for applying effects
1138 * @param pointer GDlib image pointer
1139 * @param array TypoScript array with configuration for the GIFBUILDER object.
1141 * @see tslib_gifBuilder::make(), applyImageMagickToPHPGif()
1143 function makeEffect(&$im, $conf) {
1144 $commands = $this->IMparams($conf['value']);
1146 $this->applyImageMagickToPHPGif($im, $commands);
1151 * Creating ImageMagick paramters from TypoScript property
1153 * @param string A string with effect keywords=value pairs separated by "|"
1154 * @return string ImageMagick prepared parameters.
1158 function IMparams($setup) {
1159 if (!trim($setup)){return '';}
1160 $effects = explode('|', $setup);
1162 while(list(,$val)=each($effects)) {
1163 $pairs=explode('=',$val,2);
1164 $value = trim($pairs[1]);
1165 $effect = strtolower(trim($pairs[0]));
1168 $commands.=' -gamma '.doubleval($value);
1171 if (!$this->NO_IM_EFFECTS
) {
1172 if ($this->V5_EFFECTS
) {
1173 $commands.=$this->v5_blur($value);
1175 $commands.=' -blur '.t3lib_div
::intInRange($value,1,99);
1180 if (!$this->NO_IM_EFFECTS
) {
1181 if ($this->V5_EFFECTS
) {
1182 $commands.=$this->v5_sharpen($value);
1184 $commands.=' -sharpen '.t3lib_div
::intInRange($value,1,99);
1189 $commands.=' -rotate '.t3lib_div
::intInRange($value,0,360);
1192 $commands.=' -solarize '.t3lib_div
::intInRange($value,0,99);
1195 $commands.=' -swirl '.t3lib_div
::intInRange($value,0,1000);
1198 $params = t3lib_div
::intExplode(',',$value);
1199 $commands.=' -wave '.t3lib_div
::intInRange($params[0],0,99).'x'.t3lib_div
::intInRange($params[1],0,99);
1202 $commands.=' -charcoal '.t3lib_div
::intInRange($value,0,100);
1205 $commands.=' -colorspace GRAY';
1208 $commands.=' -edge '.t3lib_div
::intInRange($value,0,99);
1211 $commands.=' -emboss';
1214 $commands.=' -flip';
1217 $commands.=' -flop';
1220 $commands.=' -colors '.t3lib_div
::intInRange($value,2,255);
1223 $commands.=' -shear '.t3lib_div
::intInRange($value,-90,90);
1226 $commands.=' -negate';
1234 * Implements the "ADJUST" GIFBUILDER object
1236 * @param pointer GDlib image pointer
1237 * @param array TypoScript array with configuration for the GIFBUILDER object.
1239 * @see tslib_gifBuilder::make(), autoLevels(), outputLevels(), inputLevels()
1241 function adjust(&$im, $conf) {
1242 $setup = $conf['value'];
1243 if (!trim($setup)){return '';}
1244 $effects = explode('|', $setup);
1245 while(list(,$val)=each($effects)) {
1246 $pairs=explode('=',$val,2);
1247 $value = trim($pairs[1]);
1248 $effect = strtolower(trim($pairs[0]));
1250 case 'inputlevels': // low,high
1251 $params = t3lib_div
::intExplode(',',$value);
1252 $this->inputLevels($im,$params[0],$params[1]);
1254 case 'outputlevels':
1255 $params = t3lib_div
::intExplode(',',$value);
1256 $this->outputLevels($im,$params[0],$params[1]);
1259 $this->autoLevels($im);
1266 * Implements the "CROP" GIFBUILDER object
1268 * @param pointer GDlib image pointer
1269 * @param array TypoScript array with configuration for the GIFBUILDER object.
1271 * @see tslib_gifBuilder::make()
1273 function crop(&$im,$conf) {
1274 $this->setWorkArea(''); // clears workArea to total image
1275 $cords = t3lib_div
::intExplode(',',$conf['crop'].',,,');
1276 $conf['offset']=$cords[0].','.$cords[1];
1277 $cords = $this->objPosition($conf,$this->workArea
,Array($cords[2],$cords[3]));
1279 $newIm = imagecreate($cords[2],$cords[3]);
1280 $cols=$this->convertColor($conf['backColor']?
$conf['backColor']:$this->setup
['backColor']);
1281 ImageColorAllocate($newIm, $cols[0],$cols[1],$cols[2]);
1284 $workArea = Array(0,0,$cords[2],$cords[3]);
1285 if ($cords[0]<0) {$workArea[0]=abs($cords[0]);} else {$newConf['offset']=-$cords[0];}
1286 if ($cords[1]<0) {$workArea[1]=abs($cords[1]);} else {$newConf['offset'].=','.-$cords[1];}
1288 $this->copyGifOntoGif($newIm,$im,$newConf,$workArea);
1290 $this->w
= imagesx($im);
1291 $this->h
= imagesy($im);
1292 $this->setWorkArea(''); // clears workArea to total image
1296 * Implements the "SCALE" GIFBUILDER object
1298 * @param pointer GDlib image pointer
1299 * @param array TypoScript array with configuration for the GIFBUILDER object.
1301 * @see tslib_gifBuilder::make()
1303 function scale(&$im,$conf) {
1304 if ($conf['width'] ||
$conf['height'] ||
$conf['params']) {
1305 $tmpStr = $this->randomName();
1306 $theFile = $tmpStr.'.'.$this->gifExtension
;
1307 $this->ImageGif($im, $theFile);
1308 $theNewFile = $this->imageMagickConvert($theFile,$this->gifExtension
,$conf['width'],$conf['height'],$conf['params'],'','');
1309 $tmpImg = $this->imageCreateFromGif($theNewFile[3]);
1313 $this->w
= imagesx($im);
1314 $this->h
= imagesy($im);
1315 $this->setWorkArea(''); // clears workArea to total image
1317 if (!$this->dontUnlinkTempFiles
) {
1319 if ($theNewFile[3] && $theNewFile[3]!=$theFile) {
1320 unlink($theNewFile[3]);
1327 * Implements the "WORKAREA" GIFBUILDER object when setting it
1328 * Setting internal working area boundaries (->workArea)
1330 * @param string Working area dimensions, comma separated
1333 * @see tslib_gifBuilder::make()
1335 function setWorkArea($workArea) {
1336 $this->workArea
= t3lib_div
::intExplode(',',$workArea);
1337 $this->workArea
= $this->applyOffset($this->workArea
,$this->OFFSET
);
1338 if (!$this->workArea
[2]) {$this->workArea
[2]=$this->w
;}
1339 if (!$this->workArea
[3]) {$this->workArea
[3]=$this->h
;}
1364 /*************************
1366 * Adjustment functions
1368 ************************/
1371 * Apply auto-levels to input image pointer
1373 * @param integer GDlib Image Pointer
1376 function autolevels(&$im) {
1377 $totalCols = ImageColorsTotal($im);
1380 for ($c=0; $c<$totalCols; $c++
) {
1381 $cols = ImageColorsForIndex($im,$c);
1382 $grayArr[] = round(($cols['red']+
$cols['green']+
$cols['blue'])/3);
1388 for ($c=0; $c<$totalCols; $c++
) {
1389 $cols = ImageColorsForIndex($im,$c);
1390 $cols['red'] = floor(($cols['red']-$min)/$delta*255);
1391 $cols['green'] = floor(($cols['green']-$min)/$delta*255);
1392 $cols['blue'] = floor(($cols['blue']-$min)/$delta*255);
1393 ImageColorSet($im,$c,$cols['red'],$cols['green'],$cols['blue']);
1399 * Apply output levels to input image pointer (decreasing contrast)
1401 * @param integer GDlib Image Pointer
1402 * @param integer The "low" value (close to 0)
1403 * @param integer The "high" value (close to 255)
1404 * @param boolean If swap, then low and high are swapped. (Useful for negated masks...)
1407 function outputLevels(&$im,$low,$high,$swap='') {
1409 $low = t3lib_div
::intInRange($low,0,255);
1410 $high = t3lib_div
::intInRange($high,0,255);
1418 $delta = $high-$low;
1419 $totalCols = ImageColorsTotal($im);
1420 for ($c=0; $c<$totalCols; $c++
) {
1421 $cols = ImageColorsForIndex($im,$c);
1422 $cols['red'] = $low+
floor($cols['red']/255*$delta);
1423 $cols['green'] = $low+
floor($cols['green']/255*$delta);
1424 $cols['blue'] = $low+
floor($cols['blue']/255*$delta);
1425 ImageColorSet($im,$c,$cols['red'],$cols['green'],$cols['blue']);
1431 * Apply input levels to input image pointer (increasing contrast)
1433 * @param integer GDlib Image Pointer
1434 * @param integer The "low" value (close to 0)
1435 * @param integer The "high" value (close to 255)
1436 * @param boolean If swap, then low and high are swapped. (Useful for negated masks...)
1439 function inputLevels(&$im,$low,$high,$swap='') {
1441 $low = t3lib_div
::intInRange($low,0,255);
1442 $high = t3lib_div
::intInRange($high,0,255);
1450 $delta = $high-$low;
1451 $totalCols = ImageColorsTotal($im);
1452 for ($c=0; $c<$totalCols; $c++
) {
1453 $cols = ImageColorsForIndex($im,$c);
1454 $cols['red'] = t3lib_div
::intInRange(($cols['red']-$low)/$delta*255, 0,255);
1455 $cols['green'] = t3lib_div
::intInRange(($cols['green']-$low)/$delta*255, 0,255);
1456 $cols['blue'] = t3lib_div
::intInRange(($cols['blue']-$low)/$delta*255, 0,255);
1457 ImageColorSet($im,$c,$cols['red'],$cols['green'],$cols['blue']);
1463 * Reduce colors in image
1465 * @param integer GDlib Image Pointer
1466 * @param integer The max number of colors in the image before a reduction will happen; basically this means that IF the GD image current has the same amount or more colors than $limit define, THEN a reduction is performed.
1467 * @param integer Number of colors to reduce the image to.
1470 function reduceColors(&$im,$limit, $cols) {
1471 if (ImageColorsTotal($im)>=$limit) {
1472 $this->makeEffect($im, Array('value'=>'colors='.$cols) );
1494 /*********************************
1496 * GIFBUILDER Helper functions
1498 *********************************/
1501 * Checks if the $fontFile is already at an absolute path and if not, prepends the correct path.
1502 * Use PATH_site unless we are in the backend.
1503 * Call it by t3lib_stdGraphic::prependAbsolutePath()
1505 * @param string The font file
1506 * @return string The font file with absolute path.
1508 function prependAbsolutePath($fontFile) {
1509 $absPath = defined('PATH_typo3') ?
dirname(PATH_thisScript
).'/' :PATH_site
;
1510 $fontFile = t3lib_div
::isAbsPath($fontFile) ?
$fontFile : $absPath.$fontFile;
1515 * Returns the IM command for sharpening with ImageMagick 5 (when $this->V5_EFFECTS is set).
1516 * Uses $this->im5fx_sharpenSteps for translation of the factor to an actual command.
1518 * @param integer The sharpening factor, 0-100 (effectively in 10 steps)
1519 * @return string The sharpening command, eg. " -sharpen 3x4"
1520 * @see makeText(), IMparams(), v5_blur()
1522 function v5_sharpen($factor) {
1523 $factor = t3lib_div
::intInRange(ceil($factor/10),0,10);
1525 $sharpenArr=explode(',',','.$this->im5fx_sharpenSteps
);
1526 $sharpenF= trim($sharpenArr[$factor]);
1528 $cmd = ' -sharpen '.$sharpenF;
1534 * Returns the IM command for blurring with ImageMagick 5 (when $this->V5_EFFECTS is set).
1535 * Uses $this->im5fx_blurSteps for translation of the factor to an actual command.
1537 * @param integer The blurring factor, 0-100 (effectively in 10 steps)
1538 * @return string The blurring command, eg. " -blur 3x4"
1539 * @see makeText(), IMparams(), v5_sharpen()
1541 function v5_blur($factor) {
1542 $factor = t3lib_div
::intInRange(ceil($factor/10),0,10);
1544 $blurArr=explode(',',','.$this->im5fx_blurSteps
);
1545 $blurF= trim($blurArr[$factor]);
1547 $cmd=' -blur '.$blurF;
1553 * Returns a random filename prefixed with "temp_" and then 32 char md5 hash (without extension) from $this->tempPath.
1554 * Used by functions in this class to create truely temporary files for the on-the-fly processing. These files will most likely be deleted right away.
1558 function randomName() {
1559 $this->createTempSubDir('temp/');
1560 return $this->tempPath
.'temp/'.md5(uniqid(''));
1564 * Applies offset value to coordinated in $cords.
1565 * Basically the value of key 0/1 of $OFFSET is added to keys 0/1 of $cords
1567 * @param array Integer coordinates in key 0/1
1568 * @param array Offset values in key 0/1
1569 * @return array Modified $cords array
1571 function applyOffset($cords,$OFFSET) {
1572 $cords[0] = intval($cords[0])+
intval($OFFSET[0]);
1573 $cords[1] = intval($cords[1])+
intval($OFFSET[1]);
1578 * Converts a "HTML-color" TypoScript datatype to RGB-values.
1581 * @param string "HTML-color" data type string, eg. 'red', '#ffeedd' or '255,0,255'. You can also add a modifying operator afterwards. There are two options: "255,0,255 : 20" - will add 20 to values, result is "255,20,255". Or "255,0,255 : *1.23" which will multiply all RGB values with 1.23
1582 * @return array RGB values in key 0/1/2 of the array
1584 function convertColor($string) {
1586 $cParts = explode(':',$string,2);
1588 // Finding the RGB definitions of the color:
1590 if (strstr($string,'#')) {
1591 $string = ereg_replace('[^A-Fa-f0-9]*','',$string);
1592 $col[]=HexDec(substr($string,0,2));
1593 $col[]=HexDec(substr($string,2,2));
1594 $col[]=HexDec(substr($string,4,2));
1595 } elseif (strstr($string,',')) {
1596 $string = ereg_replace('[^,0-9]*','',$string);
1597 $strArr = explode(',',$string);
1598 $col[]=intval($strArr[0]);
1599 $col[]=intval($strArr[1]);
1600 $col[]=intval($strArr[2]);
1602 $string = strtolower(trim($string));
1603 if ($this->colMap
[$string]) {
1604 $col = $this->colMap
[$string];
1606 $col = Array(0,0,0);
1609 // ... and possibly recalculating the value
1610 if (trim($cParts[1])) {
1611 $cParts[1]=trim($cParts[1]);
1612 if (substr($cParts[1],0,1)=='*') {
1613 $val=doubleval(substr($cParts[1],1));
1614 $col[0]=t3lib_div
::intInRange($col[0]*$val,0,255);
1615 $col[1]=t3lib_div
::intInRange($col[1]*$val,0,255);
1616 $col[2]=t3lib_div
::intInRange($col[2]*$val,0,255);
1618 $val=intval($cParts[1]);
1619 $col[0]=t3lib_div
::intInRange($col[0]+
$val,0,255);
1620 $col[1]=t3lib_div
::intInRange($col[1]+
$val,0,255);
1621 $col[2]=t3lib_div
::intInRange($col[2]+
$val,0,255);
1629 * Used with text strings for fonts when languages has other character sets.
1631 * @param string The text to recode
1632 * @return string The recoded string. Should be UTF-8 output. MAY contain entities (eg. { or &#quot; which should render as real chars).
1634 function recodeString($string) {
1635 // Recode string to UTF-8 from $this->nativeCharset:
1636 if ($this->nativeCharset
&& $this->nativeCharset
!='utf-8') {
1637 $string = $this->csConvObj
->utf8_encode($string,$this->nativeCharset
); // Convert to UTF-8
1640 // Recode string accoding to TTFLocaleConv. Depreciated.
1641 if ($this->TTFLocaleConv
) {
1642 $string = recode_string($this->TTFLocaleConv
,$string);
1649 * Split a string into an array of individual characters
1650 * The function will look at $this->nativeCharset and if that is set, the input string is expected to be UTF-8 encoded, possibly with entities in it. Otherwise the string is supposed to be a single-byte charset which is just splitted by a for-loop.
1652 * @param string The text string to spli
1653 * @return array Numerical array with a char as each value.
1655 function singleChars($theText) {
1656 if ($this->nativeCharset
) {
1657 return $this->csConvObj
->utf8_to_numberarray($theText,1,1); // Get an array of separated UTF-8 chars
1660 $c=strlen($theText);
1661 for($a=0;$a<$c;$a++
) {
1662 $output[]=substr($theText,$a,1);
1669 * Create an array with object position/boundaries based on input TypoScript configuration (such as the "align" property is used), the work area definition and $BB array
1671 * @param array TypoScript configuration for a GIFBUILDER object
1672 * @param array Workarea definition
1673 * @param array BB (Bounding box) array. Not just used for TEXT objects but also for others
1674 * @return array [0]=x, [1]=y, [2]=w, [3]=h
1676 * @see copyGifOntoGif(), makeBox(), crop()
1678 function objPosition($conf,$workArea,$BB) {
1679 // offset, align, valign, workarea
1681 $result[2] = $BB[0];
1682 $result[3] = $BB[1];
1686 $align = explode(',',$conf['align']);
1687 $align[0] = strtolower(substr(trim($align[0]),0,1));
1688 $align[1] = strtolower(substr(trim($align[1]),0,1));
1692 $result[0]=$w-$result[2];
1695 $result[0] = round(($w-$result[2])/2);
1703 $result[1] = $h-$result[3]; // y pos
1706 $result[1] = round(($h-$result[3])/2);
1712 $result = $this->applyOffset($result,t3lib_div
::intExplode(',',$conf['offset']));
1713 $result = $this->applyOffset($result,$workArea);
1737 /***********************************
1739 * Scaling, Dimensions of images
1741 ***********************************/
1744 * Converts $imagefile to another file in temp-dir of type $newExt (extension).
1746 * @param string The image filepath
1747 * @param string New extension, eg. "gif", "png", "jpg", "tif". If $newExt is NOT set, the new imagefile will be of the original format. If newExt = 'WEB' then one of the web-formats is applied.
1748 * @param string Width. $w / $h is optional. If only one is given the image is scaled proportionally. If an 'm' exists in the $w or $h and if both are present the $w and $h is regarded as the Maximum w/h and the proportions will be kept
1749 * @param string Height. See $w
1750 * @param string Additional ImageMagick parameters.
1751 * @param string Refers to which frame-number to select in the image. '' or 0 will select the first frame, 1 will select the next and so on...
1752 * @param array An array with options passed to getImageScale (see this function).
1753 * @param boolean If set, then another image than the input imagefile MUST be returned. Otherwise you can risk that the input image is good enough regarding messures etc and is of course not rendered to a new, temporary file in typo3temp/. But this option will force it to.
1754 * @return array [0]/[1] is w/h, [2] is file extension and [3] is the filename.
1755 * @see getImageScale(), typo3/show_item.php, fileList_ext::renderImage(), tslib_cObj::getImgResource(), SC_tslib_showpic::show(), maskImageOntoImage(), copyImageOntoImage(), scale()
1757 function imageMagickConvert($imagefile,$newExt='',$w='',$h='',$params='',$frame='',$options='',$mustCreate=0) {
1758 if ($this->NO_IMAGE_MAGICK
) {
1759 // Returning file info right away
1760 return $this->getImageDimensions($imagefile);
1763 if($info=$this->getImageDimensions($imagefile)) {
1764 $newExt=strtolower(trim($newExt));
1765 if (!$newExt) { // If no extension is given the original extension is used
1768 if ($newExt=='web') {
1769 if (t3lib_div
::inList($this->webImageExt
,$info[2])) {
1772 $newExt = $this->gif_or_jpg($info[2],$info[0],$info[1]);
1774 $params = $this->cmds
[$newExt];
1778 if (t3lib_div
::inList($this->imageFileExt
,$newExt)) {
1779 if (strstr($w.$h, 'm')) {$max=1;} else {$max=0;}
1781 $data = $this->getImageScale($info,$w,$h,$options);
1785 // if no convertion should be performed
1786 $wh_noscale = (!$w && !$h) ||
($data[0]==$info[0] && $data[1]==$info[1]); // this flag is true if the width / height does NOT dictate the image to be scaled!! (that is if no w/h is given or if the destination w/h matches the original image-dimensions....
1788 if ($wh_noscale && !$params && !$frame && $newExt==$info[2] && !$mustCreate) {
1789 $info[3] = $imagefile;
1795 $frame = $this->noFramePrepended ?
'' : '['.intval($frame).']';
1798 $params = $this->cmds
[$newExt];
1801 $command = $this->scalecmd
.' '.$info[0].'x'.$info[1].'! '.$params.' ';
1803 if ($this->alternativeOutputKey
) {
1804 $theOutputName = t3lib_div
::shortMD5($command.basename($imagefile).$this->alternativeOutputKey
.$frame);
1806 $theOutputName = t3lib_div
::shortMD5($command.$imagefile.filemtime($imagefile).$frame);
1808 if ($this->imageMagickConvert_forceFileNameBody
) {
1809 $theOutputName = $this->imageMagickConvert_forceFileNameBody
;
1810 $this->imageMagickConvert_forceFileNameBody
='';
1813 // Making the temporary filename:
1814 $this->createTempSubDir('pics/');
1815 $output = $this->tempPath
.'pics/'.$this->filenamePrefix
.$theOutputName.'.'.$newExt;
1817 // Register temporary filename:
1818 $GLOBALS['TEMP_IMAGES_ON_PAGE'][] = $output;
1820 if (!$this->file_exists_typo3temp_file($output,$imagefile) ||
$this->dontCheckForExistingTempFile
) {
1821 $this->imageMagickExec($imagefile.$frame,$output,$command);
1823 if (@file_exists
($output)) {
1826 if ($params) { // params could realisticly change som imagedata!
1827 $info=$this->getImageDimensions($info[3]);
1829 if ($info[2]==$this->gifExtension
&& !$this->dontCompress
) {
1830 t3lib_div
::gif_compress($info[3],''); // Compress with IM (lzw) or GD (rle) (Workaround for the absence of lzw-compression in GD)
1839 * Gets the input image dimensions.
1841 * @param string The image filepath
1842 * @return array Returns an array where [0]/[1] is w/h, [2] is extension and [3] is the filename.
1843 * @see imageMagickConvert(), tslib_cObj::getImgResource()
1845 function getImageDimensions($imageFile) {
1846 ereg('([^\.]*)$',$imageFile,$reg);
1847 if (@file_exists
($imageFile) && t3lib_div
::inList($this->imageFileExt
,strtolower($reg[0]))) {
1848 if ($returnArr = $this->getCachedImageDimensions($imageFile)) {
1851 if ($temp = @getImageSize
($imageFile)) {
1852 $returnArr = Array($temp[0], $temp[1], strtolower($reg[0]), $imageFile);
1854 $returnArr = $this->imageMagickIdentify($imageFile);
1857 $this->cacheImageDimensions($returnArr);
1866 * Cache the result of the getImageDimensions function into the database. Does not check if the
1869 * @param array $identifyResult: Result of the getImageDimensions function
1870 * @return boolean True if operation was successful
1871 * @author Michael Stucki <mundaun@gmx.ch> / Robert Lemke <rl@robertlemke.de>
1873 function cacheImageDimensions($identifyResult) {
1875 // Create a md5 hash of the filename
1876 if (function_exists('md5_file')) {
1877 $md5Hash = md5_file($identifyResult[3]);
1879 $md5Hash = md5 (t3lib_div
::getURL($identifyResult[3]));
1883 'md5hash' => $md5Hash,
1884 'md5filename' => md5($identifyResult[3]),
1886 'filename' => $identifyResult[3],
1887 'imagewidth' => $identifyResult[0],
1888 'imageheight' => $identifyResult[1],
1890 $TYPO3_DB->exec_INSERTquery('cache_imagesizes', $fieldArr);
1891 if (!$err = $TYPO3_DB->sql_error()) {
1899 * Fetch the cached imageDimensions from the MySQL database. Does not check if the image file exists!
1901 * @param string The image filepath
1902 * @return array Returns an array where [0]/[1] is w/h, [2] is extension and [3] is the filename.
1903 * @author Michael Stucki <mundaun@gmx.ch> / Robert Lemke <rl@robertlemke.de>
1905 function getCachedImageDimensions($imageFile) {
1907 // Create a md5 hash of the filename
1908 if(function_exists('md5_file')) {
1909 $md5Hash = md5_file($imageFile);
1911 $md5Hash = md5(t3lib_div
::getURL ($imageFile));
1913 ereg('([^\.]*)$',$imageFile,$reg);
1914 $res = $TYPO3_DB->exec_SELECTquery ('md5hash, imagewidth, imageheight', 'cache_imagesizes', 'md5filename="'.md5($imageFile).'"');
1916 if ($row = $TYPO3_DB->sql_fetch_assoc($res)) {
1917 if ($row['md5hash']!=$md5Hash) {
1918 // file has changed, delete the row
1919 $TYPO3_DB->exec_DELETEquery ('cache_imagesizes', 'md5hash="'.$TYPO3_DB->quoteStr($row['md5hash'], 'cache_imagesizes').'"');
1921 return (array($row['imagewidth'], $row['imageheight'], strtolower($reg[0]), $imageFile));
1929 * Get numbers for scaling the image based on input
1931 * @param array Current image information: Width, Height etc.
1932 * @param integer "required" width
1933 * @param integer "required" height
1934 * @param array Options: Keys are like "maxW", "maxH", "minW", "minH"
1937 * @see imageMagickConvert()
1939 function getImageScale($info,$w,$h,$options) {
1940 if (strstr($w.$h, 'm')) {$max=1;} else {$max=0;}
1943 // if there are max-values...
1944 if ($options['maxW']) {
1945 if ($w) { // if width is given...
1946 if ($w>$options['maxW']) {
1947 $w=$options['maxW'];
1948 $max=1; // height should follow
1951 if ($info[0]>$options['maxW']) {
1952 $w=$options['maxW'];
1953 $max=1; // height should follow
1957 if ($options['maxH']) {
1958 if ($h) { // if height is given...
1959 if ($h>$options['maxH']) {
1960 $h=$options['maxH'];
1961 $max=1; // height should follow
1964 if ($info[1]>$options['maxH']) { // Changed [0] to [1] 290801
1965 $h=$options['maxH'];
1966 $max=1; // height should follow
1974 if (!$this->mayScaleUp
) {
1975 if ($w>$info[0]){$w=$info[0];}
1976 if ($h>$info[1]){$h=$info[1];}
1978 if ($w ||
$h) { // if scaling should be performed
1980 $info[1] = ceil($info[1]*($w/$info[0]));
1984 $info[0] = ceil($info[0]*($h/$info[1]));
1989 $ratio = $info[0]/$info[1];
1990 if ($h*$ratio > $w) {
1991 $h = round($w/$ratio);
1993 $w = round($h*$ratio);
2002 // Set minimum-measures!
2003 if ($options['minW'] && $out[0]<$options['minW']) {
2004 if ($max && $out[0]) {
2005 $out[1]= round($out[1]*$options['minW']/$out[0]);
2007 $out[0]=$options['minW'];
2009 if ($options['minH'] && $out[1]<$options['minH']) {
2010 if ($max && $out[1]) {
2011 $out[0]= round($out[0]*$options['minH']/$out[1]);
2013 $out[1]=$options['minH'];
2020 * Used to check if a certain process of scaling an image is already being carried out (can be logged in the SQL database)
2022 * @param string Output imagefile
2023 * @param string Original basis file
2024 * @return boolean Returns true if the file is already being made; thus "true" means "Don't render the image again"
2027 function file_exists_typo3temp_file($output,$orig='') {
2028 if ($this->enable_typo3temp_db_tracking
) {
2029 if (@file_exists
($output)) { // If file exists, then we return immediately
2031 } else { // If not, we look up in the cache_typo3temp_log table to see if there is a image being rendered right now.
2032 $md5Hash=md5($output);
2033 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('md5hash', 'cache_typo3temp_log', 'md5hash="'.$GLOBALS['TYPO3_DB']->quoteStr($md5Hash, 'cache_typo3temp_log').'" AND tstamp>'.(time()-30));
2034 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { // If there was a record, the image is being generated by another proces (we assume)
2035 if (is_object($GLOBALS['TSFE'])) $GLOBALS['TSFE']->set_no_cache(); // ...so we set no_cache, because we dont want this page (which will NOT display an image...!) to be cached! (Only a page with the correct image on...)
2036 if (is_object($GLOBALS['TT'])) $GLOBALS['TT']->setTSlogMessage('typo3temp_log: Assume this file is being rendered now: '.$output);
2037 return 2; // Return 'success - 2'
2038 } else { // If the current time is more than 30 seconds since this record was written, we clear the record, write a new and render the image.
2040 $insertFields = array(
2041 'md5hash' => $md5Hash,
2043 'filename' => $output,
2044 'orig_filename' => $orig
2046 $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_typo3temp_log', 'md5hash="'.$GLOBALS['TYPO3_DB']->quoteStr($md5Hash, 'cache_typo3temp_log').'"');
2047 $GLOBALS['TYPO3_DB']->exec_INSERTquery('cache_typo3temp_log', $insertFields);
2049 if (is_object($GLOBALS['TT'])) $GLOBALS['TT']->setTSlogMessage('typo3temp_log: The row did not exist, so a new is written and file is being processed: '.$output);
2054 return @file_exists
($output);
2075 /***********************************
2077 * ImageMagick API functions
2079 ***********************************/
2082 * Returns an array where [0]/[1] is w/h, [2] is extension and [3] is the filename.
2085 * @param string The absolute image filepath
2088 function imageMagickIdentify($imagefile) {
2089 if (!$this->NO_IMAGE_MAGICK
) {
2090 $frame = $this->noFramePrepended?
'':'[0]';
2091 $cmd = $this->imageMagickPath
.'identify '.$this->wrapFileName($imagefile).$frame;
2092 exec($cmd, $returnVal);
2093 $splitstring=$returnVal[0];
2094 $this->IM_commands
[] = Array ('identify',$cmd,$returnVal[0]);
2096 ereg('([^\.]*)$',$imagefile,$reg);
2097 $splitinfo = explode(' ', $splitstring);
2098 while (list($key,$val) = each($splitinfo)) {
2100 if ($val) {$temp = explode('x', $val);}
2101 if (intval($temp[0]) && intval($temp[1])) {
2106 if ($dim[0] && $dim[1]) {
2107 return Array($dim[0], $dim[1], strtolower($reg[0]), $imagefile);
2114 * Executes a ImageMagick "convert" on two filenames, $input and $output using $params before them.
2115 * Can be used for many things, mostly scaling and effects.
2117 * @param string The absolute image filepath, input file (read from)
2118 * @param string The absolute image filepath, output filename (written to)
2119 * @param string ImageMagick parameters
2120 * @return string The result of a call to PHP function "exec()"
2122 function imageMagickExec($input,$output,$params) {
2123 if (!$this->NO_IMAGE_MAGICK
) {
2124 $cmd = $this->imageMagickPath
.'convert '.$params.' '.$this->wrapFileName($input).' '.$this->wrapFileName($output);
2125 $this->IM_commands
[] = Array ($output,$cmd);
2131 * Executes a ImageMagick "combine" (or composite in newer times) on four filenames - $input, $overlay and $mask as input files and $output as the output filename (written to)
2132 * Can be used for many things, mostly scaling and effects.
2134 * @param string The absolute image filepath, bottom file
2135 * @param string The absolute image filepath, overlay file (top)
2136 * @param string The absolute image filepath, the mask file (grayscale)
2137 * @param string The absolute image filepath, output filename (written to)
2140 function combineExec($input,$overlay,$mask,$output) {
2141 if (!$this->NO_IMAGE_MAGICK
) {
2142 $cmd = $this->imageMagickPath
.$this->combineScript
.' -compose over '.$this->wrapFileName($input).' '.$this->wrapFileName($overlay).' '.$this->wrapFileName($mask).' '.$this->wrapFileName($output);
2143 $this->IM_commands
[] = Array ($output,$cmd);
2149 * Wrapping the input filename in double-quotes
2151 * @param string Input filename
2152 * @return string The output wrapped in "" (if there are spaces in the filepath)
2155 function wrapFileName($inputName) {
2156 if (strstr($inputName,' ')) {
2157 $inputName='"'.$inputName.'"';
2184 /***********************************
2186 * Various IO functions
2188 ***********************************/
2191 * Returns true if the input file existed
2193 * @param string Input file to check
2194 * @return string Returns the filename if the file existed, otherwise empty.
2196 function checkFile($file) {
2197 if (@is_file
($file)) {
2205 * Creates subdirectory in typo3temp/ if not already found.
2207 function createTempSubDir($dirName) {
2208 // Making the temporary filename:
2209 if (!@is_dir
(PATH_site
.$this->tempPath
.$dirName)) {
2210 return t3lib_div
::mkdir(PATH_site
.$this->tempPath
.$dirName);
2215 * Applies an ImageMagick parameter to a GDlib image pointer resource by writing the resource to file, performing an IM operation upon it and reading back the result into the ImagePointer.
2217 * @param pointer The image pointer (reference)
2218 * @param string The ImageMagick parameters. Like effects, scaling etc.
2221 function applyImageMagickToPHPGif(&$im, $command) {
2222 $tmpStr = $this->randomName();
2223 $theFile = $tmpStr.'.'.$this->gifExtension
;
2224 $this->ImageGif($im, $theFile);
2225 $this->imageMagickExec($theFile,$theFile,$command);
2226 $tmpImg = $this->imageCreateFromGif($theFile);
2230 $this->w
= imagesx($im);
2231 $this->h
= imagesy($im);
2233 if (!$this->dontUnlinkTempFiles
) {
2239 * Returns an image extension for an output image based on the number of pixels of the output and the file extension of the original file.
2240 * For example: If the number of pixels exceeds $this->pixelLimitGif (normally 10000) then it will be a "jpg" string in return.
2242 * @param string The file extension, lowercase.
2243 * @param integer The width of the output image.
2244 * @param integer The height of the output image.
2245 * @return string The filename, either "jpg" or "gif"/"png" (whatever $this->gifExtension is set to.)
2247 function gif_or_jpg($type,$w,$h) {
2248 if ($type=='ai' ||
$w*$h < $this->pixelLimitGif
) {
2249 return $this->gifExtension
;
2256 * Writing the internal image pointer, $this->im, to file based on the extension of the input filename
2257 * Used in GIFBUILDER
2258 * Uses $this->setup['reduceColors'] for gif/png images and $this->setup['quality'] for jpg images to reduce size/quality if needed.
2260 * @param string The filename to write to.
2261 * @return string Returns input filename
2262 * @see tslib_gifBuilder::gifBuild()
2264 function output($file) {
2266 ereg('([^\.]*)$',$file,$reg);
2267 $ext=strtolower($reg[0]);
2269 case $this->gifExtension
:
2270 if ($this->ImageGif($this->im
, $file)) {
2271 // ImageMagick operations
2272 if($this->setup
['reduceColors']) {
2273 $this->imageMagickExec($file,$file,' -colors '.t3lib_div
::intInRange($this->setup
['reduceColors'],2,255));
2274 t3lib_div
::gif_compress($file,''); // Compress with IM (lzw) or GD (rle) (Workaround for the absence of lzw-compression in GD)
2276 t3lib_div
::gif_compress($file, 'IM'); // Compress with IM! (adds extra compression, LZW from ImageMagick) (Workaround for the absence of lzw-compression in GD)
2282 $tmpStr = $this->randomName();
2283 $theFile = $tmpStr.'.'.$this->gifExtension
;
2284 if ($this->ImageGif($this->im
, $theFile)) {
2285 // ImageMagick operations
2287 if($this->setup
['quality']) {
2288 $operations.=' -quality '.t3lib_div
::intInRange($this->setup
['quality'],10,100);
2290 $this->imageMagickExec($theFile,$file,$operations);
2291 if (!$this->dontUnlinkTempFiles
) {
2297 $GLOBALS['TEMP_IMAGES_ON_PAGE'][]=$file;
2303 * Destroy internal image pointer, $this->im
2306 * @see tslib_gifBuilder::gifBuild()
2308 function destroy() {
2309 ImageDestroy($this->im
);
2313 * Returns Image Tag for input image information array.
2315 * @param array Image information array, key 0/1 is width/height and key 3 is the src value
2316 * @return string Image tag for the input image information array.
2318 function imgTag ($imgInfo) {
2319 return '<img src="'.$imgInfo[3].'" width="'.$imgInfo[0].'" height="'.$imgInfo[1].'" border="0" alt="" />';
2323 * Writes the input GDlib image pointer to file
2325 * @param pointer The GDlib image resource pointer
2326 * @param string The filename to write to
2327 * @return mixed The output of either imageGif or imagePng based on whether the $this->gifExtension was set to "gif" or "png"
2328 * @see maskImageOntoImage(), scale(), output()
2330 function ImageGif($destImg, $theImage) {
2331 imageinterlace ($destImg,0);
2332 if ($this->gifExtension
=='gif') {
2333 return ImageGif($destImg, $theImage);
2335 if ($this->gifExtension
=='png') {
2336 return ImagePng($destImg, $theImage);
2341 * Creates a new GDlib image resource based on the input image filename.
2342 * If it fails creating a image from the input file a blank gray image with the dimensions of the input image will be created instead.
2344 * @param string Image filename
2345 * @return pointer Image Resource pointer
2347 function imageCreateFromGif($sourceImg) {
2348 $imgInf = pathinfo($sourceImg);
2349 $ext = strtolower($imgInf['extension']);
2351 // if ($ext=='gif' && (ImageTypes() & IMG_GIF)) {
2352 if ($ext=='gif' && function_exists('imagecreatefromgif')) {
2353 return imageCreateFromGif($sourceImg);
2355 // if ($ext=='png' && (ImageTypes() & IMG_PNG)) {
2356 if ($ext=='png' && function_exists('imagecreatefrompng')) {
2357 return imageCreateFromPng($sourceImg);
2359 // if (($ext=='jpg' || $ext=='jpeg') && (ImageTypes() & IMG_JPG)) {
2360 if (($ext=='jpg' ||
$ext=='jpeg') && function_exists('imagecreatefromjpeg')) {
2361 return imageCreateFromJpeg($sourceImg);
2364 // If non of the above:
2365 $i = @getimagesize
($sourceImg);
2366 $im = imagecreate($i[0],$i[1]);
2367 ImageColorAllocate($im, 128,128,128);
2373 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_stdgraphic.php']) {
2374 include_once($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_stdgraphic.php']);