Index: t3lib/class.t3lib_stdgraphic.php =================================================================== --- t3lib/class.t3lib_stdgraphic.php (revision 9431) +++ t3lib/class.t3lib_stdgraphic.php (revision ) @@ -1,29 +1,29 @@ '', @@ -185,41 +171,41 @@ var $mayScaleUp = 1; // Variables for testing, alternative usage etc. - var $filenamePrefix=''; // Filename prefix for images scaled in imageMagickConvert() + var $filenamePrefix = ''; // Filename prefix for images scaled in imageMagickConvert() - var $imageMagickConvert_forceFileNameBody=''; // Forcing the output filename of imageMagickConvert() to this value. However after calling imageMagickConvert() it will be set blank again. + var $imageMagickConvert_forceFileNameBody = ''; // Forcing the output filename of imageMagickConvert() to this value. However after calling imageMagickConvert() it will be set blank again. - 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. + 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. - var $dontCompress=0; // Prevents imageMagickConvert() from compressing the gif-files with t3lib_div::gif_compress() + var $dontCompress = 0; // Prevents imageMagickConvert() from compressing the gif-files with t3lib_div::gif_compress() - var $dontUnlinkTempFiles=0; // For debugging ONLY! + var $dontUnlinkTempFiles = 0; // For debugging ONLY! - 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... + 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... // Internal: - var $IM_commands = Array(); // All ImageMagick commands executed is stored in this array for tracking. Used by the Install Tools Image section - var $workArea = Array(); + var $IM_commands = array(); // All ImageMagick commands executed is stored in this array for tracking. Used by the Install Tools Image section + var $workArea = array(); // Constants: - 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. + 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. - var $absPrefix = ''; // Prefix for relative paths. Used in "show_item.php" script. Is prefixed the output file name IN imageMagickConvert() + var $absPrefix = ''; // Prefix for relative paths. Used in "show_item.php" script. Is prefixed the output file name IN imageMagickConvert() - var $scalecmd = '-geometry'; // ImageMagick scaling command; "-geometry" eller "-sample". Used in makeText() and imageMagickConvert() + var $scalecmd = '-geometry'; // ImageMagick scaling command; "-geometry" eller "-sample". Used in makeText() and imageMagickConvert() - var $im5fx_blurSteps='1x2,2x2,3x2,4x3,5x3,5x4,6x4,7x5,8x5,9x5'; // Used by v5_blur() to simulate 10 continuous steps of blurring + var $im5fx_blurSteps = '1x2,2x2,3x2,4x3,5x3,5x4,6x4,7x5,8x5,9x5'; // Used by v5_blur() to simulate 10 continuous steps of blurring - var $im5fx_sharpenSteps='1x2,2x2,3x2,2x3,3x3,4x3,3x4,4x4,4x5,5x5'; // Used by v5_sharpen() to simulate 10 continuous steps of sharpening. + var $im5fx_sharpenSteps = '1x2,2x2,3x2,2x3,3x3,4x3,3x4,4x4,4x5,5x5'; // Used by v5_sharpen() to simulate 10 continuous steps of sharpening. - 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 + 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 - var $colMap = Array ( // Array mapping HTML color names to RGB values. - 'aqua' => Array(0,255,255), - 'black' => Array(0,0,0), - 'blue' => Array(0,0,255), - 'fuchsia' => Array(255,0,255), - 'gray' => Array(128,128,128), - 'green' => Array(0,128,0), - 'lime' => Array(0,255,0), - 'maroon' => Array(128,0,0), - 'navy' => Array(0,0,128), - 'olive' => Array(128,128,0), - 'purple' => Array(128,0,128), - 'red' => Array(255,0,0), - 'silver' => Array(192,192,192), - 'teal' => Array(0,128,128), - 'yellow' => Array(255,255,0), - 'white' => Array(255,255,255) + var $colMap = array( // Array mapping HTML color names to RGB values. + 'aqua' => array(0, 255, 255), + 'black' => array(0, 0, 0), + 'blue' => array(0, 0, 255), + 'fuchsia' => array(255, 0, 255), + 'gray' => array(128, 128, 128), + 'green' => array(0, 128, 0), + 'lime' => array(0, 255, 0), + 'maroon' => array(128, 0, 0), + 'navy' => array(0, 0, 128), + 'olive' => array(128, 128, 0), + 'purple' => array(128, 0, 128), + 'red' => array(255, 0, 0), + 'silver' => array(192, 192, 192), + 'teal' => array(0, 128, 128), + 'yellow' => array(255, 255, 0), + 'white' => array(255, 255, 255) ); /** @@ -228,34 +214,31 @@ * @var t3lib_cs */ var $csConvObj; - var $nativeCharset=''; // Is set to the native character set of the input strings. + var $nativeCharset = ''; // Is set to the native character set of the input strings. - - - /** * Init function. Must always call this when using the class. * This function will read the configuration information from $GLOBALS['TYPO3_CONF_VARS']['GFX'] can set some values in internal variables. * * @return void */ - function init() { + function init() { $gfxConf = $GLOBALS['TYPO3_CONF_VARS']['GFX']; - if (function_exists('imagecreatefromjpeg')&&function_exists('imagejpeg')) { + if (function_exists('imagecreatefromjpeg') && function_exists('imagejpeg')) { $this->gdlibExtensions .= ',jpg,jpeg'; } - if (function_exists('imagecreatefrompng')&&function_exists('imagepng')) { + if (function_exists('imagecreatefrompng') && function_exists('imagepng')) { $this->gdlibExtensions .= ',png'; } - if (function_exists('imagecreatefromgif')&&function_exists('imagegif')) { + if (function_exists('imagecreatefromgif') && function_exists('imagegif')) { $this->gdlibExtensions .= ',gif'; } - if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['png_truecolor']) { + if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['png_truecolor']) { $this->png_truecolor = true; } - if (!$gfxConf['im_version_5']) { + if (!$gfxConf['im_version_5']) { t3lib_div::deprecationLog('The option $TYPO3_CONF_VARS[\'GFX\'][\'im_version_5\'] is not set, ImageMagic 4 is assumed. This is deprecated since TYPO3 4.5, support will be removed in TYPO3 4.6. Make sure to upgrade to ImageMagick version 6 or GraphichsMagick.'); $this->im_version_4 = true; } elseif ($gfxConf['im_version_5'] === 'im5') { @@ -270,17 +253,21 @@ // Setting default JPG parameters: $this->jpegQuality = t3lib_div::intInRange($gfxConf['jpg_quality'], 10, 100, 75); - $this->cmds['jpg'] = $this->cmds['jpeg'] = '-colorspace RGB -sharpen 50 -quality '.$this->jpegQuality; + $this->cmds['jpg'] = $this->cmds['jpeg'] = '-colorspace RGB -sharpen 50 -quality ' . $this->jpegQuality; - if ($gfxConf['im_combine_filename']) $this->combineScript=$gfxConf['im_combine_filename']; - if ($gfxConf['im_noFramePrepended']) $this->noFramePrepended=1; + if ($gfxConf['im_combine_filename']) { + $this->combineScript = $gfxConf['im_combine_filename']; + } + if ($gfxConf['im_noFramePrepended']) { + $this->noFramePrepended = 1; + } // kept for backwards compatibility, can be turned on manually through localconf.php, // but not through the installer anymore $this->imagecopyresized_fix = ($gfxConf['gdlib_2'] === 'no_imagecopyresized_fix' ? 0 : 1); - if ($gfxConf['gdlib_png']) { + if ($gfxConf['gdlib_png']) { - $this->gifExtension='png'; + $this->gifExtension = 'png'; } if ($gfxConf['TTFLocaleConv']) { $this->TTFLocaleConv = $gfxConf['TTFLocaleConv']; @@ -292,64 +279,50 @@ $this->imageFileExt = $gfxConf['imagefile_ext']; // This should be set if ImageMagick ver. 5+ is used. - if ($gfxConf['im_negate_mask']) { + if ($gfxConf['im_negate_mask']) { // Boolean. Indicates if the mask images should be inverted first. // This depends of the ImageMagick version. Below ver. 5.1 this should be false. // Above ImageMagick version 5.2+ it should be true. // Just set the flag if the masks works opposite the intension! $this->maskNegate = ' -negate'; } - if ($gfxConf['im_no_effects']) { + if ($gfxConf['im_no_effects']) { // Boolean. This is necessary if using ImageMagick 5+. // Effects in Imagemagick 5+ tends to render very slowly!! // - therefore must be disabled in order not to perform sharpen, blurring and such. $this->NO_IM_EFFECTS = 1; - $this->cmds['jpg'] = $this->cmds['jpeg'] = '-colorspace RGB -quality '.$this->jpegQuality; + $this->cmds['jpg'] = $this->cmds['jpeg'] = '-colorspace RGB -quality ' . $this->jpegQuality; } // ... but if 'im_v5effects' is set, don't care about 'im_no_effects' - if ($gfxConf['im_v5effects']) { + if ($gfxConf['im_v5effects']) { $this->NO_IM_EFFECTS = 0; $this->V5_EFFECTS = 1; - if ($gfxConf['im_v5effects']>0) { + if ($gfxConf['im_v5effects'] > 0) { - $this->cmds['jpg'] = $this->cmds['jpeg'] = '-colorspace RGB -quality '.intval($gfxConf['jpg_quality']).$this->v5_sharpen(10); + $this->cmds['jpg'] = $this->cmds['jpeg'] = '-colorspace RGB -quality ' . intval($gfxConf['jpg_quality']) . $this->v5_sharpen(10); } } - if (!$gfxConf['im']) { + if (!$gfxConf['im']) { $this->NO_IMAGE_MAGICK = 1; } // Secures that images are not scaled up. if ($gfxConf['im_noScaleUp']) { - $this->mayScaleUp=0; + $this->mayScaleUp = 0; } - if (TYPO3_MODE=='FE') { + if (TYPO3_MODE == 'FE') { $this->csConvObj = $GLOBALS['TSFE']->csConvObj; - } elseif(is_object($GLOBALS['LANG'])) { // BE assumed: + } elseif (is_object($GLOBALS['LANG'])) { // BE assumed: $this->csConvObj = $GLOBALS['LANG']->csConvObj; - } else { // The object may not exist yet, so we need to create it now. Happens in the Install Tool for example. + } else { // The object may not exist yet, so we need to create it now. Happens in the Install Tool for example. $this->csConvObj = t3lib_div::makeInstance('t3lib_cs'); } $this->nativeCharset = $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset']; } - - - - - - - - - - - - - - /************************************************* * * Layering images / "IMAGE" GIFBUILDER object @@ -367,59 +340,59 @@ * @return void * @see tslib_gifBuilder::make() */ - function maskImageOntoImage(&$im,$conf,$workArea) { + function maskImageOntoImage(&$im, $conf, $workArea) { - if ($conf['file'] && $conf['mask']) { + if ($conf['file'] && $conf['mask']) { $imgInf = pathinfo($conf['file']); $imgExt = strtolower($imgInf['extension']); - if (!t3lib_div::inList($this->gdlibExtensions, $imgExt)) { + if (!t3lib_div::inList($this->gdlibExtensions, $imgExt)) { - $BBimage = $this->imageMagickConvert($conf['file'],$this->gifExtension,'','','','',''); + $BBimage = $this->imageMagickConvert($conf['file'], $this->gifExtension, '', '', '', '', ''); - } else { + } else { $BBimage = $this->getImageDimensions($conf['file']); } $maskInf = pathinfo($conf['mask']); $maskExt = strtolower($maskInf['extension']); - if (!t3lib_div::inList($this->gdlibExtensions, $maskExt)) { + if (!t3lib_div::inList($this->gdlibExtensions, $maskExt)) { - $BBmask = $this->imageMagickConvert($conf['mask'],$this->gifExtension,'','','','',''); + $BBmask = $this->imageMagickConvert($conf['mask'], $this->gifExtension, '', '', '', '', ''); - } else { + } else { $BBmask = $this->getImageDimensions($conf['mask']); } - if ($BBimage && $BBmask) { + if ($BBimage && $BBmask) { $w = imagesx($im); $h = imagesy($im); $tmpStr = $this->randomName(); - $theImage = $tmpStr.'_img.'.$this->gifExtension; + $theImage = $tmpStr . '_img.' . $this->gifExtension; - $theDest = $tmpStr.'_dest.'.$this->gifExtension; + $theDest = $tmpStr . '_dest.' . $this->gifExtension; - $theMask = $tmpStr.'_mask.'.$this->gifExtension; + $theMask = $tmpStr . '_mask.' . $this->gifExtension; - // prepare overlay image + // prepare overlay image $cpImg = $this->imageCreateFromFile($BBimage[3]); $destImg = imagecreatetruecolor($w, $h); - $Bcolor = ImageColorAllocate($destImg, 0,0,0); + $Bcolor = ImageColorAllocate($destImg, 0, 0, 0); ImageFilledRectangle($destImg, 0, 0, $w, $h, $Bcolor); - $this->copyGifOntoGif($destImg,$cpImg,$conf,$workArea); + $this->copyGifOntoGif($destImg, $cpImg, $conf, $workArea); $this->ImageWrite($destImg, $theImage); imageDestroy($cpImg); imageDestroy($destImg); - // prepare mask image + // prepare mask image $cpImg = $this->imageCreateFromFile($BBmask[3]); $destImg = imagecreatetruecolor($w, $h); $Bcolor = ImageColorAllocate($destImg, 0, 0, 0); ImageFilledRectangle($destImg, 0, 0, $w, $h, $Bcolor); - $this->copyGifOntoGif($destImg,$cpImg,$conf,$workArea); + $this->copyGifOntoGif($destImg, $cpImg, $conf, $workArea); $this->ImageWrite($destImg, $theMask); imageDestroy($cpImg); imageDestroy($destImg); // mask the images $this->ImageWrite($im, $theDest); - $this->combineExec($theDest,$theImage,$theMask,$theDest, true); // Let combineExec handle maskNegation + $this->combineExec($theDest, $theImage, $theMask, $theDest, TRUE); // Let combineExec handle maskNegation - $backIm = $this->imageCreateFromFile($theDest); // The main image is loaded again... + $backIm = $this->imageCreateFromFile($theDest); // The main image is loaded again... - if ($backIm) { // ... and if nothing went wrong we load it onto the old one. + if ($backIm) { // ... and if nothing went wrong we load it onto the old one. - ImageColorTransparent($backIm,-1); + ImageColorTransparent($backIm, -1); $im = $backIm; } // unlink files from process - if (!$this->dontUnlinkTempFiles) { + if (!$this->dontUnlinkTempFiles) { unlink($theDest); unlink($theImage); unlink($theMask); @@ -437,14 +410,14 @@ * @return void * @see tslib_gifBuilder::make(), maskImageOntoImage() */ - function copyImageOntoImage(&$im,$conf,$workArea) { + function copyImageOntoImage(&$im, $conf, $workArea) { - if ($conf['file']) { + if ($conf['file']) { - if (!t3lib_div::inList($this->gdlibExtensions, $conf['BBOX'][2])) { + if (!t3lib_div::inList($this->gdlibExtensions, $conf['BBOX'][2])) { - $conf['BBOX']=$this->imageMagickConvert($conf['BBOX'][3],$this->gifExtension,'','','','',''); + $conf['BBOX'] = $this->imageMagickConvert($conf['BBOX'][3], $this->gifExtension, '', '', '', '', ''); - $conf['file']=$conf['BBOX'][3]; + $conf['file'] = $conf['BBOX'][3]; } $cpImg = $this->imageCreateFromFile($conf['file']); - $this->copyGifOntoGif($im,$cpImg,$conf,$workArea); + $this->copyGifOntoGif($im, $cpImg, $conf, $workArea); imageDestroy($cpImg); } } @@ -459,48 +432,48 @@ * @return void Works on the $im image pointer * @access private */ - function copyGifOntoGif(&$im,$cpImg,$conf,$workArea) { + function copyGifOntoGif(&$im, $cpImg, $conf, $workArea) { $cpW = imagesx($cpImg); $cpH = imagesy($cpImg); - $tile = t3lib_div::intExplode(',',$conf['tile']); + $tile = t3lib_div::intExplode(',', $conf['tile']); - $tile[0] = t3lib_div::intInRange($tile[0],1,20); + $tile[0] = t3lib_div::intInRange($tile[0], 1, 20); - $tile[1] = t3lib_div::intInRange($tile[1],1,20); + $tile[1] = t3lib_div::intInRange($tile[1], 1, 20); - $cpOff = $this->objPosition($conf,$workArea,Array($cpW*$tile[0],$cpH*$tile[1])); + $cpOff = $this->objPosition($conf, $workArea, array($cpW * $tile[0], $cpH * $tile[1])); - for ($xt=0;$xt<$tile[0];$xt++) { + for ($xt = 0; $xt < $tile[0]; $xt++) { - $Xstart=$cpOff[0]+$cpW*$xt; + $Xstart = $cpOff[0] + $cpW * $xt; - if ($Xstart+$cpW > $workArea[0]) { // if this image is inside of the workArea, then go on + if ($Xstart + $cpW > $workArea[0]) { // if this image is inside of the workArea, then go on // X: - if ($Xstart < $workArea[0]) { + if ($Xstart < $workArea[0]) { - $cpImgCutX = $workArea[0]-$Xstart; + $cpImgCutX = $workArea[0] - $Xstart; $Xstart = $workArea[0]; } else { $cpImgCutX = 0; } - $w = $cpW-$cpImgCutX; + $w = $cpW - $cpImgCutX; - if ($Xstart > $workArea[0]+$workArea[2]-$w) { + if ($Xstart > $workArea[0] + $workArea[2] - $w) { - $w = $workArea[0]+$workArea[2]-$Xstart; + $w = $workArea[0] + $workArea[2] - $Xstart; } - if ($Xstart < $workArea[0]+$workArea[2]) { // if this image is inside of the workArea, then go on + if ($Xstart < $workArea[0] + $workArea[2]) { // if this image is inside of the workArea, then go on // Y: - for ($yt=0;$yt<$tile[1];$yt++) { + for ($yt = 0; $yt < $tile[1]; $yt++) { - $Ystart=$cpOff[1]+$cpH*$yt; + $Ystart = $cpOff[1] + $cpH * $yt; - if ($Ystart+$cpH > $workArea[1]) { // if this image is inside of the workArea, then go on + if ($Ystart + $cpH > $workArea[1]) { // if this image is inside of the workArea, then go on - if ($Ystart < $workArea[1]) { + if ($Ystart < $workArea[1]) { - $cpImgCutY = $workArea[1]-$Ystart; + $cpImgCutY = $workArea[1] - $Ystart; $Ystart = $workArea[1]; } else { $cpImgCutY = 0; } - $h = $cpH-$cpImgCutY; + $h = $cpH - $cpImgCutY; - if ($Ystart > $workArea[1]+$workArea[3]-$h) { + if ($Ystart > $workArea[1] + $workArea[3] - $h) { - $h = $workArea[1]+$workArea[3]-$Ystart; + $h = $workArea[1] + $workArea[3] - $Ystart; } - if ($Ystart < $workArea[1]+$workArea[3]) { // if this image is inside of the workArea, then go on + if ($Ystart < $workArea[1] + $workArea[3]) { // if this image is inside of the workArea, then go on $this->imagecopyresized($im, $cpImg, $Xstart, $Ystart, $cpImgCutX, $cpImgCutY, $w, $h, $w, $h); } } - } // Y: + } // Y: } } } @@ -514,11 +487,11 @@ * With GD2 only the palette of the dest-image is used which mostly results in totally black images when trying to * copy a color-ful image onto the destination. * The GD2-fix is to - * 1) Create a blank TRUE-COLOR image + * 1) Create a blank TRUE-COLOR image - * 2) Copy the destination image onto that one + * 2) Copy the destination image onto that one - * 3) Then do the actual operation; Copying the source (top image) onto that + * 3) Then do the actual operation; Copying the source (top image) onto that - * 4) ... and return the result pointer. + * 4) ... and return the result pointer. - * 5) Reduce colors (if we do not, the result may become strange!) + * 5) Reduce colors (if we do not, the result may become strange!) * It works, but the resulting images is now a true-color PNG which may be very large. * So, why not use 'imagetruecolortopalette ($im, TRUE, 256)' - well because it does NOT WORK! So simple is that. * @@ -538,14 +511,14 @@ * @access private * @see t3lib_iconWorks::imagecopyresized() */ - function imagecopyresized(&$im, $cpImg, $Xstart, $Ystart, $cpImgCutX, $cpImgCutY, $w, $h, $w, $h) { + function imagecopyresized(&$im, $cpImg, $Xstart, $Ystart, $cpImgCutX, $cpImgCutY, $w, $h, $w, $h) { - if ($this->imagecopyresized_fix) { + if ($this->imagecopyresized_fix) { - $im_base = imagecreatetruecolor(imagesx($im), imagesy($im)); // Make true color image + $im_base = imagecreatetruecolor(imagesx($im), imagesy($im)); // Make true color image - imagecopyresized($im_base, $im, 0,0,0,0, imagesx($im),imagesy($im),imagesx($im),imagesy($im)); // Copy the source image onto that + imagecopyresized($im_base, $im, 0, 0, 0, 0, imagesx($im), imagesy($im), imagesx($im), imagesy($im)); // Copy the source image onto that - imagecopyresized($im_base, $cpImg, $Xstart, $Ystart, $cpImgCutX, $cpImgCutY, $w, $h, $w, $h); // Then copy the $cpImg onto that (the actual operation!) + imagecopyresized($im_base, $cpImg, $Xstart, $Ystart, $cpImgCutX, $cpImgCutY, $w, $h, $w, $h); // Then copy the $cpImg onto that (the actual operation!) - $im = $im_base; // Set pointer + $im = $im_base; // Set pointer - if (!$this->truecolor) { + if (!$this->truecolor) { - $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! + $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! } } else { imagecopyresized($im, $cpImg, $Xstart, $Ystart, $cpImgCutX, $cpImgCutY, $w, $h, $w, $h); @@ -553,26 +526,6 @@ } - - - - - - - - - - - - - - - - - - - - /******************************** * * Text / "TEXT" GIFBUILDER object @@ -588,58 +541,58 @@ * @return void * @see tslib_gifBuilder::make() */ - function makeText(&$im,$conf,$workArea) { + function makeText(&$im, $conf, $workArea) { // Spacing - list($spacing,$wordSpacing) = $this->calcWordSpacing($conf); + list($spacing, $wordSpacing) = $this->calcWordSpacing($conf); // Position - $txtPos = $this->txtPosition($conf,$workArea,$conf['BBOX']); + $txtPos = $this->txtPosition($conf, $workArea, $conf['BBOX']); $theText = $this->recodeString($conf['text']); - if ($conf['imgMap'] && is_array($conf['imgMap.'])) { + if ($conf['imgMap'] && is_array($conf['imgMap.'])) { - $this->addToMap($this->calcTextCordsForMap($conf['BBOX'][2],$txtPos, $conf['imgMap.']), $conf['imgMap.']); + $this->addToMap($this->calcTextCordsForMap($conf['BBOX'][2], $txtPos, $conf['imgMap.']), $conf['imgMap.']); } - if (!$conf['hideButCreateMap']) { + if (!$conf['hideButCreateMap']) { // Font Color: - $cols=$this->convertColor($conf['fontColor']); + $cols = $this->convertColor($conf['fontColor']); // NiceText is calculated if (!$conf['niceText']) { // Font Color is reserved: - if (!$this->truecolor) { + if (!$this->truecolor) { $reduce = t3lib_div::intInRange($this->setup['reduceColors'], 256, $this->truecolorColors, 256); - $this->reduceColors($im, $reduce-49, $reduce-50); // If "reduce-49" colors (or more) are used reduce them to "reduce-50" + $this->reduceColors($im, $reduce - 49, $reduce - 50); // If "reduce-49" colors (or more) are used reduce them to "reduce-50" } - $Fcolor = ImageColorAllocate($im, $cols[0],$cols[1],$cols[2]); + $Fcolor = ImageColorAllocate($im, $cols[0], $cols[1], $cols[2]); // antiAliasing is setup: $Fcolor = ($conf['antiAlias']) ? $Fcolor : -$Fcolor; - for ($a=0; $a<$conf['iterations']; $a++) { + for ($a = 0; $a < $conf['iterations']; $a++) { - if ($spacing || $wordSpacing) { // If any kind of spacing applys, we use this function: + if ($spacing || $wordSpacing) { // If any kind of spacing applys, we use this function: $this->SpacedImageTTFText($im, $conf['fontSize'], $conf['angle'], $txtPos[0], $txtPos[1], $Fcolor, t3lib_stdGraphic::prependAbsolutePath($conf['fontFile']), $theText, $spacing, $wordSpacing, $conf['splitRendering.']); } else { $this->renderTTFText($im, $conf['fontSize'], $conf['angle'], $txtPos[0], $txtPos[1], $Fcolor, $conf['fontFile'], $theText, $conf['splitRendering.'], $conf); } } - } else { // NICETEXT:: + } else { // NICETEXT:: // options anti_aliased and iterations is NOT available when doing this!! $w = imagesx($im); $h = imagesy($im); $tmpStr = $this->randomName(); - $fileMenu = $tmpStr.'_menuNT.'.$this->gifExtension; + $fileMenu = $tmpStr . '_menuNT.' . $this->gifExtension; - $fileColor = $tmpStr.'_colorNT.'.$this->gifExtension; + $fileColor = $tmpStr . '_colorNT.' . $this->gifExtension; - $fileMask = $tmpStr.'_maskNT.'.$this->gifExtension; + $fileMask = $tmpStr . '_maskNT.' . $this->gifExtension; // Scalefactor - $sF = t3lib_div::intInRange($conf['niceText.']['scaleFactor'],2,5); + $sF = t3lib_div::intInRange($conf['niceText.']['scaleFactor'], 2, 5); - $newW = ceil($sF*imagesx($im)); + $newW = ceil($sF * imagesx($im)); - $newH = ceil($sF*imagesy($im)); + $newH = ceil($sF * imagesy($im)); // Make mask $maskImg = imagecreatetruecolor($newW, $newH); - $Bcolor = ImageColorAllocate($maskImg, 255,255,255); + $Bcolor = ImageColorAllocate($maskImg, 255, 255, 255); ImageFilledRectangle($maskImg, 0, 0, $newW, $newH, $Bcolor); - $Fcolor = ImageColorAllocate($maskImg, 0,0,0); + $Fcolor = ImageColorAllocate($maskImg, 0, 0, 0); - if ($spacing || $wordSpacing) { // If any kind of spacing applys, we use this function: + if ($spacing || $wordSpacing) { // If any kind of spacing applys, we use this function: - $this->SpacedImageTTFText($maskImg, $conf['fontSize'], $conf['angle'], $txtPos[0], $txtPos[1], $Fcolor, t3lib_stdGraphic::prependAbsolutePath($conf['fontFile']), $theText, $spacing, $wordSpacing, $conf['splitRendering.'],$sF); + $this->SpacedImageTTFText($maskImg, $conf['fontSize'], $conf['angle'], $txtPos[0], $txtPos[1], $Fcolor, t3lib_stdGraphic::prependAbsolutePath($conf['fontFile']), $theText, $spacing, $wordSpacing, $conf['splitRendering.'], $sF); } else { $this->renderTTFText($maskImg, $conf['fontSize'], $conf['angle'], $txtPos[0], $txtPos[1], $Fcolor, $conf['fontFile'], $theText, $conf['splitRendering.'], $conf, $sF); } @@ -647,49 +600,49 @@ ImageDestroy($maskImg); // Downscales the mask - if ($this->NO_IM_EFFECTS) { + if ($this->NO_IM_EFFECTS) { - if ($this->maskNegate) { + if ($this->maskNegate) { - $command = trim($this->scalecmd.' '.$w.'x'.$h.'!'); // Negate 2 times makes no negate... + $command = trim($this->scalecmd . ' ' . $w . 'x' . $h . '!'); // Negate 2 times makes no negate... } else { - $command = trim($this->scalecmd.' '.$w.'x'.$h.'! -negate'); + $command = trim($this->scalecmd . ' ' . $w . 'x' . $h . '! -negate'); } } else { - if ($this->maskNegate) { + if ($this->maskNegate) { - $command = trim($conf['niceText.']['before'].' '.$this->scalecmd.' '.$w.'x'.$h.'! '.$conf['niceText.']['after']); + $command = trim($conf['niceText.']['before'] . ' ' . $this->scalecmd . ' ' . $w . 'x' . $h . '! ' . $conf['niceText.']['after']); } else { - $command = trim($conf['niceText.']['before'].' '.$this->scalecmd.' '.$w.'x'.$h.'! '.$conf['niceText.']['after'].' -negate'); + $command = trim($conf['niceText.']['before'] . ' ' . $this->scalecmd . ' ' . $w . 'x' . $h . '! ' . $conf['niceText.']['after'] . ' -negate'); } if ($conf['niceText.']['sharpen']) { - if ($this->V5_EFFECTS) { + if ($this->V5_EFFECTS) { - $command.=$this->v5_sharpen($conf['niceText.']['sharpen']); + $command .= $this->v5_sharpen($conf['niceText.']['sharpen']); } else { - $command.=' -sharpen '.t3lib_div::intInRange($conf['niceText.']['sharpen'],1,99); + $command .= ' -sharpen ' . t3lib_div::intInRange($conf['niceText.']['sharpen'], 1, 99); } } } - $this->imageMagickExec($fileMask,$fileMask,$command); + $this->imageMagickExec($fileMask, $fileMask, $command); // Make the color-file $colorImg = imagecreatetruecolor($w, $h); - $Ccolor = ImageColorAllocate($colorImg, $cols[0],$cols[1],$cols[2]); + $Ccolor = ImageColorAllocate($colorImg, $cols[0], $cols[1], $cols[2]); ImageFilledRectangle($colorImg, 0, 0, $w, $h, $Ccolor); $this->ImageWrite($colorImg, $fileColor); ImageDestroy($colorImg); // The mask is applied - $this->ImageWrite($im, $fileMenu); // The main pictures is saved temporarily + $this->ImageWrite($im, $fileMenu); // The main pictures is saved temporarily - $this->combineExec($fileMenu,$fileColor,$fileMask, $fileMenu); + $this->combineExec($fileMenu, $fileColor, $fileMask, $fileMenu); - $backIm = $this->imageCreateFromFile($fileMenu); // The main image is loaded again... + $backIm = $this->imageCreateFromFile($fileMenu); // The main image is loaded again... - if ($backIm) { // ... and if nothing went wrong we load it onto the old one. + if ($backIm) { // ... and if nothing went wrong we load it onto the old one. - ImageColorTransparent($backIm,-1); + ImageColorTransparent($backIm, -1); $im = $backIm; } // Deleting temporary files; - if (!$this->dontUnlinkTempFiles) { + if (!$this->dontUnlinkTempFiles) { unlink($fileMenu); unlink($fileColor); unlink($fileMask); @@ -708,49 +661,49 @@ * @access private * @see makeText() */ - function txtPosition($conf,$workArea,$BB) { + function txtPosition($conf, $workArea, $BB) { $bbox = $BB[2]; - $angle=intval($conf['angle'])/180*pi(); + $angle = intval($conf['angle']) / 180 * pi(); - $conf['angle']=0; + $conf['angle'] = 0; $straightBB = $this->calcBBox($conf); // offset, align, valign, workarea - $result=Array(); // [0]=x, [1]=y, [2]=w, [3]=h + $result = array(); // [0]=x, [1]=y, [2]=w, [3]=h $result[2] = $BB[0]; $result[3] = $BB[1]; - $w=$workArea[2]; + $w = $workArea[2]; - $h=$workArea[3]; + $h = $workArea[3]; - switch($conf['align']) { + switch ($conf['align']) { case 'right': case 'center': - $factor=abs(cos($angle)); + $factor = abs(cos($angle)); - $sign=(cos($angle)<0)?-1:1; + $sign = (cos($angle) < 0) ? -1 : 1; - $len1 = $sign*$factor*$straightBB[0]; + $len1 = $sign * $factor * $straightBB[0]; - $len2= $sign*$BB[0]; + $len2 = $sign * $BB[0]; - $result[0] = $w-ceil($len2*$factor+(1-$factor)*$len1); + $result[0] = $w - ceil($len2 * $factor + (1 - $factor) * $len1); - $factor=abs(sin($angle)); + $factor = abs(sin($angle)); - $sign=(sin($angle)<0)?-1:1; + $sign = (sin($angle) < 0) ? -1 : 1; - $len1= $sign*$factor*$straightBB[0]; + $len1 = $sign * $factor * $straightBB[0]; - $len2= $sign*$BB[1]; + $len2 = $sign * $BB[1]; - $result[1]=ceil($len2*$factor+(1-$factor)*$len1); + $result[1] = ceil($len2 * $factor + (1 - $factor) * $len1); break; } - switch($conf['align']) { + switch ($conf['align']) { case 'right': break; case 'center': - $result[0] = round(($result[0])/2); + $result[0] = round(($result[0]) / 2); - $result[1] = round(($result[1])/2); + $result[1] = round(($result[1]) / 2); break; default: - $result[0]=0; + $result[0] = 0; - $result[1]=0; + $result[1] = 0; break; } - $result = $this->applyOffset($result,t3lib_div::intExplode(',',$conf['offset'])); + $result = $this->applyOffset($result, t3lib_div::intExplode(',', $conf['offset'])); - $result = $this->applyOffset($result,$workArea); + $result = $this->applyOffset($result, $workArea); return $result; } @@ -762,42 +715,42 @@ * @access private * @see txtPosition(), tslib_gifBuilder::start() */ - function calcBBox($conf) { + function calcBBox($conf) { $sF = $this->getTextScalFactor($conf); - list($spacing,$wordSpacing) = $this->calcWordSpacing($conf, $sF); + list($spacing, $wordSpacing) = $this->calcWordSpacing($conf, $sF); $theText = $this->recodeString($conf['text']); - $charInf = $this->ImageTTFBBoxWrapper($conf['fontSize'], $conf['angle'], $conf['fontFile'], $theText, $conf['splitRendering.'],$sF); + $charInf = $this->ImageTTFBBoxWrapper($conf['fontSize'], $conf['angle'], $conf['fontFile'], $theText, $conf['splitRendering.'], $sF); $theBBoxInfo = $charInf; - if ($conf['angle']) { + if ($conf['angle']) { - $xArr = Array($charInf[0],$charInf[2],$charInf[4],$charInf[6]); - $yArr = Array($charInf[1],$charInf[3],$charInf[5],$charInf[7]); + $xArr = array($charInf[0], $charInf[2], $charInf[4], $charInf[6]); + $yArr = array($charInf[1], $charInf[3], $charInf[5], $charInf[7]); - $x=max($xArr)-min($xArr); + $x = max($xArr) - min($xArr); - $y=max($yArr)-min($yArr); + $y = max($yArr) - min($yArr); } else { - $x = ($charInf[2]-$charInf[0]); + $x = ($charInf[2] - $charInf[0]); - $y = ($charInf[1]-$charInf[7]); + $y = ($charInf[1] - $charInf[7]); } // Set original lineHeight (used by line breaks): $theBBoxInfo['lineHeight'] = $y; - if ($spacing || $wordSpacing) { // If any kind of spacing applys, we use this function: + if ($spacing || $wordSpacing) { // If any kind of spacing applys, we use this function: - $x=0; + $x = 0; - if (!$spacing && $wordSpacing) { + if (!$spacing && $wordSpacing) { - $bits = explode(' ',$theText); + $bits = explode(' ', $theText); foreach ($bits as $word) { - $word.=' '; + $word .= ' '; - $wordInf = $this->ImageTTFBBoxWrapper($conf['fontSize'], $conf['angle'], $conf['fontFile'], $word, $conf['splitRendering.'],$sF); + $wordInf = $this->ImageTTFBBoxWrapper($conf['fontSize'], $conf['angle'], $conf['fontFile'], $word, $conf['splitRendering.'], $sF); - $wordW = ($wordInf[2]-$wordInf[0]); + $wordW = ($wordInf[2] - $wordInf[0]); - $x+=$wordW+$wordSpacing; + $x += $wordW + $wordSpacing; } } else { $utf8Chars = $this->singleChars($theText); // For each UTF-8 char, do: - foreach($utf8Chars as $char) { + foreach ($utf8Chars as $char) { - $charInf = $this->ImageTTFBBoxWrapper($conf['fontSize'], $conf['angle'], $conf['fontFile'], $char, $conf['splitRendering.'],$sF); + $charInf = $this->ImageTTFBBoxWrapper($conf['fontSize'], $conf['angle'], $conf['fontFile'], $char, $conf['splitRendering.'], $sF); - $charW = ($charInf[2]-$charInf[0]); + $charW = ($charInf[2] - $charInf[0]); - $x+=$charW+(($char==' ')?$wordSpacing:$spacing); + $x += $charW + (($char == ' ') ? $wordSpacing : $spacing); } } } elseif (isset($conf['breakWidth']) && $conf['breakWidth'] && $this->getRenderedTextWidth($conf['text'], $conf) > $conf['breakWidth']) { @@ -811,10 +764,10 @@ foreach ($wordPairs as $index => $wordPair) { $wordWidth = $this->getRenderedTextWidth($wordPair, $conf); if ($index == 0 || $currentWidth + $wordWidth <= $breakWidth) { - $currentWidth+= $wordWidth; + $currentWidth += $wordWidth; } else { $maxWidth = max($maxWidth, $currentWidth); - $y+= $breakSpace; + $y += $breakSpace; // Restart: $currentWidth = $wordWidth; } @@ -825,7 +778,7 @@ if ($sF > 1) { $x = ceil($x / $sF); $y = ceil($y / $sF); - if (is_array($theBBoxInfo)) { + if (is_array($theBBoxInfo)) { foreach ($theBBoxInfo as &$value) { $value = ceil($value / $sF); } @@ -843,17 +796,17 @@ * @access private * @see makeText(), calcTextCordsForMap() */ - function addToMap($cords,$conf) { + function addToMap($cords, $conf) { $JS = $conf['noBlur'] ? '' : ' onfocus="blurLink(this);"'; - $this->map.='map .= ''; + ' alt="' . htmlspecialchars($conf['altText']) . '" />'; } /** @@ -866,17 +819,17 @@ * @access private * @see makeText(), calcTextCordsForMap() */ - function calcTextCordsForMap($cords,$offset, $conf) { + function calcTextCordsForMap($cords, $offset, $conf) { - $pars = t3lib_div::intExplode(',',$conf['explode'].','); + $pars = t3lib_div::intExplode(',', $conf['explode'] . ','); - $newCords[0] = $cords[0]+$offset[0]-$pars[0]; + $newCords[0] = $cords[0] + $offset[0] - $pars[0]; - $newCords[1] = $cords[1]+$offset[1]+$pars[1]; + $newCords[1] = $cords[1] + $offset[1] + $pars[1]; - $newCords[2] = $cords[2]+$offset[0]+$pars[0]; + $newCords[2] = $cords[2] + $offset[0] + $pars[0]; - $newCords[3] = $cords[3]+$offset[1]+$pars[1]; + $newCords[3] = $cords[3] + $offset[1] + $pars[1]; - $newCords[4] = $cords[4]+$offset[0]+$pars[0]; + $newCords[4] = $cords[4] + $offset[0] + $pars[0]; - $newCords[5] = $cords[5]+$offset[1]-$pars[1]; + $newCords[5] = $cords[5] + $offset[1] - $pars[1]; - $newCords[6] = $cords[6]+$offset[0]-$pars[0]; + $newCords[6] = $cords[6] + $offset[0] - $pars[0]; - $newCords[7] = $cords[7]+$offset[1]-$pars[1]; + $newCords[7] = $cords[7] + $offset[1] - $pars[1]; return $newCords; } @@ -901,28 +854,28 @@ * @return void * @access private */ - function SpacedImageTTFText(&$im, $fontSize, $angle, $x, $y, $Fcolor, $fontFile, $text, $spacing, $wordSpacing, $splitRenderingConf, $sF=1) { + function SpacedImageTTFText(&$im, $fontSize, $angle, $x, $y, $Fcolor, $fontFile, $text, $spacing, $wordSpacing, $splitRenderingConf, $sF = 1) { - $spacing*=$sF; + $spacing *= $sF; - $wordSpacing*=$sF; + $wordSpacing *= $sF; - if (!$spacing && $wordSpacing) { + if (!$spacing && $wordSpacing) { - $bits = explode(' ',$text); + $bits = explode(' ', $text); foreach ($bits as $word) { - $word.=' '; + $word .= ' '; - $wordInf = $this->ImageTTFBBoxWrapper($fontSize, $angle, $fontFile, $word, $splitRenderingConf ,$sF); + $wordInf = $this->ImageTTFBBoxWrapper($fontSize, $angle, $fontFile, $word, $splitRenderingConf, $sF); - $wordW = ($wordInf[2]-$wordInf[0]); + $wordW = ($wordInf[2] - $wordInf[0]); $this->ImageTTFTextWrapper($im, $fontSize, $angle, $x, $y, $Fcolor, $fontFile, $word, $splitRenderingConf, $sF); - $x+=$wordW+$wordSpacing; + $x += $wordW + $wordSpacing; } } else { $utf8Chars = $this->singleChars($text); // For each UTF-8 char, do: - foreach($utf8Chars as $char) { + foreach ($utf8Chars as $char) { $charInf = $this->ImageTTFBBoxWrapper($fontSize, $angle, $fontFile, $char, $splitRenderingConf, $sF); - $charW = ($charInf[2]-$charInf[0]); + $charW = ($charInf[2] - $charInf[0]); $this->ImageTTFTextWrapper($im, $fontSize, $angle, $x, $y, $Fcolor, $fontFile, $char, $splitRenderingConf, $sF); - $x+=$charW+(($char==' ')?$wordSpacing:$spacing); + $x += $charW + (($char == ' ') ? $wordSpacing : $spacing); } } } @@ -937,34 +890,35 @@ * @see tslib_gifBuilder::start() */ function fontResize($conf) { - // 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!!!! + // 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!!!! $maxWidth = intval($conf['maxWidth']); - list($spacing,$wordSpacing) = $this->calcWordSpacing($conf); + list($spacing, $wordSpacing) = $this->calcWordSpacing($conf); - if ($maxWidth) { + if ($maxWidth) { - if ($spacing || $wordSpacing) { // If any kind of spacing applys, we use this function: + if ($spacing || $wordSpacing) { // If any kind of spacing applys, we use this function: return $conf['fontSize']; - // ################ no calc for spacing yet !!!!!! + // ################ no calc for spacing yet !!!!!! } else { do { // determine bounding box. $bounds = $this->ImageTTFBBoxWrapper($conf['fontSize'], $conf['angle'], $conf['fontFile'], $this->recodeString($conf['text']), $conf['splitRendering.']); - if ($conf['angle']< 0) { + if ($conf['angle'] < 0) { - $pixelWidth = abs($bounds[4]-$bounds[0]); + $pixelWidth = abs($bounds[4] - $bounds[0]); } elseif ($conf['angle'] > 0) { - $pixelWidth = abs($bounds[2]-$bounds[6]); + $pixelWidth = abs($bounds[2] - $bounds[6]); } else { - $pixelWidth = abs($bounds[4]-$bounds[6]); + $pixelWidth = abs($bounds[4] - $bounds[6]); } // Size is fine, exit: - if ($pixelWidth <= $maxWidth) { + if ($pixelWidth <= $maxWidth) { break; } else { $conf['fontSize']--; } - } while ($conf['fontSize']>1); + } while ($conf['fontSize'] > 1); - }//if spacing - } + } + //if spacing + } return $conf['fontSize']; } @@ -979,32 +933,32 @@ * @param integer Scale factor * @return array Information array. */ - function ImageTTFBBoxWrapper($fontSize, $angle, $fontFile, $string, $splitRendering, $sF=1) { + function ImageTTFBBoxWrapper($fontSize, $angle, $fontFile, $string, $splitRendering, $sF = 1) { // Initialize: $offsetInfo = array(); - $stringParts = $this->splitString($string,$splitRendering,$fontSize,$fontFile); + $stringParts = $this->splitString($string, $splitRendering, $fontSize, $fontFile); // Traverse string parts: - foreach($stringParts as $strCfg) { + foreach ($stringParts as $strCfg) { $fontFile = t3lib_stdGraphic::prependAbsolutePath($strCfg['fontFile']); if (is_readable($fontFile)) { // Calculate Bounding Box for part: - $calc = ImageTTFBBox(t3lib_div::freetypeDpiComp($sF*$strCfg['fontSize']), $angle, $fontFile, $strCfg['str']); + $calc = ImageTTFBBox(t3lib_div::freetypeDpiComp($sF * $strCfg['fontSize']), $angle, $fontFile, $strCfg['str']); // Calculate offsets: - if (!count($offsetInfo)) { + if (!count($offsetInfo)) { - $offsetInfo = $calc; // First run, just copy over. + $offsetInfo = $calc; // First run, just copy over. } else { - $offsetInfo[2]+=$calc[2]-$calc[0]+intval($splitRendering['compX'])+intval($strCfg['xSpaceBefore'])+intval($strCfg['xSpaceAfter']); + $offsetInfo[2] += $calc[2] - $calc[0] + intval($splitRendering['compX']) + intval($strCfg['xSpaceBefore']) + intval($strCfg['xSpaceAfter']); - $offsetInfo[3]+=$calc[3]-$calc[1]-intval($splitRendering['compY'])-intval($strCfg['ySpaceBefore'])-intval($strCfg['ySpaceAfter']); + $offsetInfo[3] += $calc[3] - $calc[1] - intval($splitRendering['compY']) - intval($strCfg['ySpaceBefore']) - intval($strCfg['ySpaceAfter']); - $offsetInfo[4]+=$calc[4]-$calc[6]+intval($splitRendering['compX'])+intval($strCfg['xSpaceBefore'])+intval($strCfg['xSpaceAfter']); + $offsetInfo[4] += $calc[4] - $calc[6] + intval($splitRendering['compX']) + intval($strCfg['xSpaceBefore']) + intval($strCfg['xSpaceAfter']); - $offsetInfo[5]+=$calc[5]-$calc[7]-intval($splitRendering['compY'])-intval($strCfg['ySpaceBefore'])-intval($strCfg['ySpaceAfter']); + $offsetInfo[5] += $calc[5] - $calc[7] - intval($splitRendering['compY']) - intval($strCfg['ySpaceBefore']) - intval($strCfg['ySpaceAfter']); } } else { - debug('cannot read file: '.$fontFile, 't3lib_stdGraphic::ImageTTFBBoxWrapper()'); + debug('cannot read file: ' . $fontFile, 't3lib_stdGraphic::ImageTTFBBoxWrapper()'); } } @@ -1026,45 +980,45 @@ * @param integer Scale factor * @return void */ - function ImageTTFTextWrapper($im, $fontSize, $angle, $x, $y, $color, $fontFile, $string, $splitRendering,$sF=1) { + function ImageTTFTextWrapper($im, $fontSize, $angle, $x, $y, $color, $fontFile, $string, $splitRendering, $sF = 1) { // Initialize: - $stringParts = $this->splitString($string,$splitRendering,$fontSize,$fontFile); + $stringParts = $this->splitString($string, $splitRendering, $fontSize, $fontFile); - $x = ceil($sF*$x); + $x = ceil($sF * $x); - $y = ceil($sF*$y); + $y = ceil($sF * $y); // Traverse string parts: - foreach($stringParts as $i => $strCfg) { + foreach ($stringParts as $i => $strCfg) { // Initialize: $colorIndex = $color; // Set custom color if any (only when niceText is off): - if ($strCfg['color'] && $sF==1) { + if ($strCfg['color'] && $sF == 1) { $cols = $this->convertColor($strCfg['color']); - $colorIndex = ImageColorAllocate($im, $cols[0],$cols[1],$cols[2]); + $colorIndex = ImageColorAllocate($im, $cols[0], $cols[1], $cols[2]); $colorIndex = $color >= 0 ? $colorIndex : -$colorIndex; } // Setting xSpaceBefore - if ($i) { + if ($i) { - $x+= intval($strCfg['xSpaceBefore']); + $x += intval($strCfg['xSpaceBefore']); - $y-= intval($strCfg['ySpaceBefore']); + $y -= intval($strCfg['ySpaceBefore']); } $fontFile = t3lib_stdGraphic::prependAbsolutePath($strCfg['fontFile']); if (is_readable($fontFile)) { // Render part: - ImageTTFText($im, t3lib_div::freetypeDpiComp($sF*$strCfg['fontSize']), $angle, $x, $y, $colorIndex, $fontFile, $strCfg['str']); + ImageTTFText($im, t3lib_div::freetypeDpiComp($sF * $strCfg['fontSize']), $angle, $x, $y, $colorIndex, $fontFile, $strCfg['str']); // Calculate offset to apply: - $wordInf = ImageTTFBBox(t3lib_div::freetypeDpiComp($sF*$strCfg['fontSize']), $angle, t3lib_stdGraphic::prependAbsolutePath($strCfg['fontFile']), $strCfg['str']); + $wordInf = ImageTTFBBox(t3lib_div::freetypeDpiComp($sF * $strCfg['fontSize']), $angle, t3lib_stdGraphic::prependAbsolutePath($strCfg['fontFile']), $strCfg['str']); - $x+= $wordInf[2]-$wordInf[0]+intval($splitRendering['compX'])+intval($strCfg['xSpaceAfter']); + $x += $wordInf[2] - $wordInf[0] + intval($splitRendering['compX']) + intval($strCfg['xSpaceAfter']); - $y+= $wordInf[5]-$wordInf[7]-intval($splitRendering['compY'])-intval($strCfg['ySpaceAfter']); + $y += $wordInf[5] - $wordInf[7] - intval($splitRendering['compY']) - intval($strCfg['ySpaceAfter']); } else { - debug('cannot read file: '.$fontFile, 't3lib_stdGraphic::ImageTTFTextWrapper()'); + debug('cannot read file: ' . $fontFile, 't3lib_stdGraphic::ImageTTFTextWrapper()'); } } @@ -1079,7 +1033,7 @@ * @param string Current font file * @return array Array with input string splitted according to configuration */ - function splitString($string,$splitRendering,$fontSize,$fontFile) { + function splitString($string, $splitRendering, $fontSize, $fontFile) { // Initialize by setting the whole string and default configuration as the first entry. $result = array(); @@ -1091,28 +1045,28 @@ // Traverse the split-rendering configuration: // Splitting will create more entries in $result with individual configurations. - if (is_array($splitRendering)) { + if (is_array($splitRendering)) { $sKeyArray = t3lib_TStemplate::sortedKeyList($splitRendering); // Traverse configured options: - foreach($sKeyArray as $key) { + foreach ($sKeyArray as $key) { - $cfg = $splitRendering[$key.'.']; + $cfg = $splitRendering[$key . '.']; // Process each type of split rendering keyword: - switch((string)$splitRendering[$key]) { + switch ((string) $splitRendering[$key]) { case 'highlightWord': - if (strlen($cfg['value'])) { + if (strlen($cfg['value'])) { $newResult = array(); // Traverse the current parts of the result array: - foreach($result as $part) { + foreach ($result as $part) { // Explode the string value by the word value to highlight: - $explodedParts = explode($cfg['value'],$part['str']); + $explodedParts = explode($cfg['value'], $part['str']); - foreach($explodedParts as $c => $expValue) { + foreach ($explodedParts as $c => $expValue) { - if (strlen($expValue)) { + if (strlen($expValue)) { - $newResult[] = array_merge($part,array('str' => $expValue)); + $newResult[] = array_merge($part, array('str' => $expValue)); } - if ($c+1 < count($explodedParts)) { + if ($c + 1 < count($explodedParts)) { $newResult[] = array( 'str' => $cfg['value'], 'fontSize' => $cfg['fontSize'] ? $cfg['fontSize'] : $part['fontSize'], @@ -1128,24 +1082,26 @@ } // Set the new result as result array: - if (count($newResult)) { + if (count($newResult)) { $result = $newResult; } } break; case 'charRange': - if (strlen($cfg['value'])) { + if (strlen($cfg['value'])) { // Initialize range: - $ranges = t3lib_div::trimExplode(',',$cfg['value'],1); + $ranges = t3lib_div::trimExplode(',', $cfg['value'], 1); - foreach($ranges as $i => $rangeDef) { + foreach ($ranges as $i => $rangeDef) { - $ranges[$i] = t3lib_div::intExplode('-',$ranges[$i]); + $ranges[$i] = t3lib_div::intExplode('-', $ranges[$i]); - if (!isset($ranges[$i][1])) $ranges[$i][1] = $ranges[$i][0]; + if (!isset($ranges[$i][1])) { + $ranges[$i][1] = $ranges[$i][0]; - } + } + } $newResult = array(); // Traverse the current parts of the result array: - foreach($result as $part) { + foreach ($result as $part) { // Initialize: $currentState = -1; @@ -1153,24 +1109,26 @@ // Explode the string value by the word value to highlight: $utf8Chars = $this->singleChars($part['str']); - foreach($utf8Chars as $utfChar) { + foreach ($utf8Chars as $utfChar) { // Find number and evaluate position: $uNumber = $this->csConvObj->utf8CharToUnumber($utfChar); $inRange = 0; - foreach($ranges as $rangeDef) { + foreach ($ranges as $rangeDef) { if ($uNumber >= $rangeDef[0] && (!$rangeDef[1] || $uNumber <= $rangeDef[1])) { $inRange = 1; break; } } - if ($currentState==-1) $currentState = $inRange; // Initialize first char + if ($currentState == -1) { + $currentState = $inRange; + } // Initialize first char // Switch bank: - if ($inRange != $currentState && !t3lib_div::inList('32,10,13,9',$uNumber)) { + if ($inRange != $currentState && !t3lib_div::inList('32,10,13,9', $uNumber)) { // Set result: - if (strlen($bankAccum)) { + if (strlen($bankAccum)) { $newResult[] = array( 'str' => $bankAccum, 'fontSize' => $currentState && $cfg['fontSize'] ? $cfg['fontSize'] : $part['fontSize'], @@ -1189,11 +1147,11 @@ } // Add char to bank: - $bankAccum.=$utfChar; + $bankAccum .= $utfChar; } // Set result for FINAL part: - if (strlen($bankAccum)) { + if (strlen($bankAccum)) { $newResult[] = array( 'str' => $bankAccum, 'fontSize' => $currentState && $cfg['fontSize'] ? $cfg['fontSize'] : $part['fontSize'], @@ -1208,7 +1166,7 @@ } // Set the new result as result array: - if (count($newResult)) { + if (count($newResult)) { $result = $newResult; } } @@ -1229,16 +1187,16 @@ * @access private * @see calcBBox() */ - function calcWordSpacing($conf, $scaleFactor=1) { + function calcWordSpacing($conf, $scaleFactor = 1) { $spacing = intval($conf['spacing']); $wordSpacing = intval($conf['wordSpacing']); - $wordSpacing = $wordSpacing?$wordSpacing:$spacing*2; + $wordSpacing = $wordSpacing ? $wordSpacing : $spacing * 2; - $spacing*=$scaleFactor; + $spacing *= $scaleFactor; - $wordSpacing*=$scaleFactor; + $wordSpacing *= $scaleFactor; - return array($spacing,$wordSpacing); + return array($spacing, $wordSpacing); } /** @@ -1251,8 +1209,8 @@ function getTextScalFactor($conf) { if (!$conf['niceText']) { $sF = 1; - } else { // NICETEXT:: + } else { // NICETEXT:: - $sF = t3lib_div::intInRange($conf['niceText.']['scaleFactor'],2,5); + $sF = t3lib_div::intInRange($conf['niceText.']['scaleFactor'], 2, 5); } return $sF; } @@ -1286,13 +1244,13 @@ foreach ($wordPairs as $index => $wordPair) { $wordWidth = $this->getRenderedTextWidth($wordPair, $conf); if ($index == 0 || $currentWidth + $wordWidth <= $breakWidth) { - $currentWidth+= $wordWidth; + $currentWidth += $wordWidth; - $phrase.= $wordPair; + $phrase .= $wordPair; } else { // Render the current phrase that is below breakWidth: $this->ImageTTFTextWrapper($im, $fontSize, $angle, $x, $y, $color, $fontFile, $phrase, $splitRendering, $sF); // Calculate the news height offset: - $y+= $breakSpace; + $y += $breakSpace; // Restart the phrase: $currentWidth = $wordWidth; $phrase = $wordPair; @@ -1316,9 +1274,9 @@ protected function getWordPairsForLineBreak($string) { $wordPairs = array(); - $wordsArray = preg_split('#([- .,!:]+)#', $string, -1, PREG_SPLIT_DELIM_CAPTURE); + $wordsArray = preg_split('#([- .,!:]+)#', $string, -1, PREG_SPLIT_DELIM_CAPTURE); $wordsCount = count($wordsArray); - for ($index=0; $index < $wordsCount; $index+= 2) { + for ($index = 0; $index < $wordsCount; $index += 2) { $wordPairs[] = $wordsArray[$index] . $wordsArray[$index + 1]; } @@ -1334,12 +1292,12 @@ */ protected function getRenderedTextWidth($text, $conf) { $bounds = $this->ImageTTFBBoxWrapper($conf['fontSize'], $conf['angle'], $conf['fontFile'], $this->recodeString($text), $conf['splitRendering.']); - if ($conf['angle']< 0) { + if ($conf['angle'] < 0) { - $pixelWidth = abs($bounds[4]-$bounds[0]); + $pixelWidth = abs($bounds[4] - $bounds[0]); } elseif ($conf['angle'] > 0) { - $pixelWidth = abs($bounds[2]-$bounds[6]); + $pixelWidth = abs($bounds[2] - $bounds[6]); } else { - $pixelWidth = abs($bounds[4]-$bounds[6]); + $pixelWidth = abs($bounds[4] - $bounds[6]); } return $pixelWidth; } @@ -1367,15 +1325,6 @@ } - - - - - - - - - /********************************************* * * Other GIFBUILDER objects related to TEXT @@ -1392,20 +1341,20 @@ * @return void * @see tslib_gifBuilder::make(), makeText() */ - function makeOutline(&$im,$conf,$workArea,$txtConf) { + function makeOutline(&$im, $conf, $workArea, $txtConf) { $thickness = intval($conf['thickness']); - if ($thickness) { + if ($thickness) { $txtConf['fontColor'] = $conf['color']; - $outLineDist = t3lib_div::intInRange($thickness,1,2); + $outLineDist = t3lib_div::intInRange($thickness, 1, 2); - for ($b=1;$b<=$outLineDist;$b++) { + for ($b = 1; $b <= $outLineDist; $b++) { - if ($b==1) { + if ($b == 1) { $it = 8; } else { $it = 16; } $outL = $this->circleOffset($b, $it); - for ($a=0;$a<$it;$a++) { + for ($a = 0; $a < $it; $a++) { - $this->makeText($im,$txtConf,$this->applyOffset($workArea,$outL[$a])); + $this->makeText($im, $txtConf, $this->applyOffset($workArea, $outL[$a])); } } } @@ -1421,17 +1370,21 @@ * @return array * @see makeOutline() */ - function circleOffset($distance, $iterations) { + function circleOffset($distance, $iterations) { - $res = Array(); + $res = array(); - if ($distance && $iterations) { + if ($distance && $iterations) { - for ($a=0;$a<$iterations;$a++) { + for ($a = 0; $a < $iterations; $a++) { - $yOff = round(sin(2*pi()/$iterations*($a+1))*100*$distance); + $yOff = round(sin(2 * pi() / $iterations * ($a + 1)) * 100 * $distance); - if ($yOff) {$yOff = intval(ceil(abs($yOff/100))*($yOff/abs($yOff)));} + if ($yOff) { + $yOff = intval(ceil(abs($yOff / 100)) * ($yOff / abs($yOff))); + } - $xOff = round(cos(2*pi()/$iterations*($a+1))*100*$distance); + $xOff = round(cos(2 * pi() / $iterations * ($a + 1)) * 100 * $distance); - if ($xOff) {$xOff = intval(ceil(abs($xOff/100))*($xOff/abs($xOff)));} - $res[$a] = Array($xOff,$yOff); + if ($xOff) { + $xOff = intval(ceil(abs($xOff / 100)) * ($xOff / abs($xOff))); - } + } + $res[$a] = array($xOff, $yOff); - } + } + } return $res; } @@ -1445,15 +1398,15 @@ * @return void * @see tslib_gifBuilder::make(), makeShadow() */ - function makeEmboss(&$im,$conf,$workArea,$txtConf) { + function makeEmboss(&$im, $conf, $workArea, $txtConf) { - $conf['color']=$conf['highColor']; + $conf['color'] = $conf['highColor']; - $this->makeShadow($im,$conf,$workArea,$txtConf); + $this->makeShadow($im, $conf, $workArea, $txtConf); - $newOffset = t3lib_div::intExplode(',',$conf['offset']); + $newOffset = t3lib_div::intExplode(',', $conf['offset']); - $newOffset[0]*=-1; + $newOffset[0] *= -1; - $newOffset[1]*=-1; + $newOffset[1] *= -1; - $conf['offset']=implode(',',$newOffset); + $conf['offset'] = implode(',', $newOffset); - $conf['color']=$conf['lowColor']; + $conf['color'] = $conf['lowColor']; - $this->makeShadow($im,$conf,$workArea,$txtConf); + $this->makeShadow($im, $conf, $workArea, $txtConf); } /** @@ -1467,96 +1420,96 @@ * @return void * @see tslib_gifBuilder::make(), makeText(), makeEmboss() */ - function makeShadow(&$im,$conf,$workArea,$txtConf) { + function makeShadow(&$im, $conf, $workArea, $txtConf) { - $workArea = $this->applyOffset($workArea,t3lib_div::intExplode(',',$conf['offset'])); + $workArea = $this->applyOffset($workArea, t3lib_div::intExplode(',', $conf['offset'])); - $blurRate = t3lib_div::intInRange(intval($conf['blur']),0,99); + $blurRate = t3lib_div::intInRange(intval($conf['blur']), 0, 99); - if (!$blurRate || $this->NO_IM_EFFECTS) { // No effects if ImageMagick ver. 5+ + if (!$blurRate || $this->NO_IM_EFFECTS) { // No effects if ImageMagick ver. 5+ $txtConf['fontColor'] = $conf['color']; - $this->makeText($im,$txtConf,$workArea); + $this->makeText($im, $txtConf, $workArea); } else { $w = imagesx($im); $h = imagesy($im); - $blurBorder= 3; // area around the blur used for cropping something + $blurBorder = 3; // area around the blur used for cropping something $tmpStr = $this->randomName(); - $fileMenu = $tmpStr.'_menu.'.$this->gifExtension; + $fileMenu = $tmpStr . '_menu.' . $this->gifExtension; - $fileColor = $tmpStr.'_color.'.$this->gifExtension; + $fileColor = $tmpStr . '_color.' . $this->gifExtension; - $fileMask = $tmpStr.'_mask.'.$this->gifExtension; + $fileMask = $tmpStr . '_mask.' . $this->gifExtension; // BlurColor Image laves $blurColImg = imagecreatetruecolor($w, $h); - $bcols=$this->convertColor($conf['color']); + $bcols = $this->convertColor($conf['color']); - $Bcolor = ImageColorAllocate($blurColImg, $bcols[0],$bcols[1],$bcols[2]); + $Bcolor = ImageColorAllocate($blurColImg, $bcols[0], $bcols[1], $bcols[2]); ImageFilledRectangle($blurColImg, 0, 0, $w, $h, $Bcolor); $this->ImageWrite($blurColImg, $fileColor); ImageDestroy($blurColImg); // The mask is made: BlurTextImage $blurTextImg = imagecreatetruecolor($w + $blurBorder * 2, $h + $blurBorder * 2); - $Bcolor = ImageColorAllocate($blurTextImg, 0,0,0); // black background + $Bcolor = ImageColorAllocate($blurTextImg, 0, 0, 0); // black background - ImageFilledRectangle($blurTextImg, 0, 0, $w+$blurBorder*2, $h+$blurBorder*2, $Bcolor); + ImageFilledRectangle($blurTextImg, 0, 0, $w + $blurBorder * 2, $h + $blurBorder * 2, $Bcolor); $txtConf['fontColor'] = 'white'; - $blurBordArr = Array($blurBorder,$blurBorder); + $blurBordArr = array($blurBorder, $blurBorder); - $this->makeText($blurTextImg,$txtConf, $this->applyOffset($workArea,$blurBordArr)); + $this->makeText($blurTextImg, $txtConf, $this->applyOffset($workArea, $blurBordArr)); - $this->ImageWrite($blurTextImg, $fileMask); // dump to temporary file + $this->ImageWrite($blurTextImg, $fileMask); // dump to temporary file - ImageDestroy($blurTextImg); // destroy + ImageDestroy($blurTextImg); // destroy - $command=''; + $command = ''; - $command.=$this->maskNegate; + $command .= $this->maskNegate; - if ($this->V5_EFFECTS) { + if ($this->V5_EFFECTS) { - $command.=$this->v5_blur($blurRate+1); + $command .= $this->v5_blur($blurRate + 1); } else { // Blurring of the mask - $times = ceil($blurRate/10); // How many blur-commands that is executed. Min = 1; + $times = ceil($blurRate / 10); // How many blur-commands that is executed. Min = 1; - $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. + $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. - $newBlurRate = t3lib_div::intInRange($newBlurRate,1,99); + $newBlurRate = t3lib_div::intInRange($newBlurRate, 1, 99); - for ($a=0;$a<$times;$a++) { // Building blur-command + for ($a = 0; $a < $times; $a++) { // Building blur-command - $command.=' -blur '.$blurRate; + $command .= ' -blur ' . $blurRate; } } - $this->imageMagickExec($fileMask,$fileMask,$command.' +matte'); + $this->imageMagickExec($fileMask, $fileMask, $command . ' +matte'); - $blurTextImg_tmp = $this->imageCreateFromFile($fileMask); // the mask is loaded again + $blurTextImg_tmp = $this->imageCreateFromFile($fileMask); // the mask is loaded again - if ($blurTextImg_tmp) { // if nothing went wrong we continue with the blurred mask + if ($blurTextImg_tmp) { // if nothing went wrong we continue with the blurred mask // cropping the border from the mask $blurTextImg = imagecreatetruecolor($w, $h); $this->imagecopyresized($blurTextImg, $blurTextImg_tmp, 0, 0, $blurBorder, $blurBorder, $w, $h, $w, $h); - ImageDestroy($blurTextImg_tmp); // Destroy the temporary mask + ImageDestroy($blurTextImg_tmp); // Destroy the temporary mask // adjust the mask $intensity = 40; - if ($conf['intensity']) { + if ($conf['intensity']) { - $intensity = t3lib_div::intInRange($conf['intensity'],0,100); + $intensity = t3lib_div::intInRange($conf['intensity'], 0, 100); } - $intensity = ceil(255-($intensity/100*255)); + $intensity = ceil(255 - ($intensity / 100 * 255)); - $this->inputLevels($blurTextImg,0,$intensity,$this->maskNegate); + $this->inputLevels($blurTextImg, 0, $intensity, $this->maskNegate); - $opacity = t3lib_div::intInRange(intval($conf['opacity']),0,100); + $opacity = t3lib_div::intInRange(intval($conf['opacity']), 0, 100); - if ($opacity && $opacity<100) { + if ($opacity && $opacity < 100) { - $high = ceil(255*$opacity/100); + $high = ceil(255 * $opacity / 100); - $this->outputLevels($blurTextImg,0,$high,$this->maskNegate); // reducing levels as the opacity demands + $this->outputLevels($blurTextImg, 0, $high, $this->maskNegate); // reducing levels as the opacity demands } - $this->ImageWrite($blurTextImg, $fileMask); // Dump the mask again + $this->ImageWrite($blurTextImg, $fileMask); // Dump the mask again - ImageDestroy($blurTextImg); // Destroy the mask + ImageDestroy($blurTextImg); // Destroy the mask // The pictures are combined - $this->ImageWrite($im, $fileMenu); // The main pictures is saved temporarily + $this->ImageWrite($im, $fileMenu); // The main pictures is saved temporarily - $this->combineExec($fileMenu,$fileColor,$fileMask,$fileMenu); + $this->combineExec($fileMenu, $fileColor, $fileMask, $fileMenu); - $backIm = $this->imageCreateFromFile($fileMenu); // The main image is loaded again... + $backIm = $this->imageCreateFromFile($fileMenu); // The main image is loaded again... - if ($backIm) { // ... and if nothing went wrong we load it onto the old one. + if ($backIm) { // ... and if nothing went wrong we load it onto the old one. - ImageColorTransparent($backIm,-1); + ImageColorTransparent($backIm, -1); $im = $backIm; } } // Deleting temporary files; - if (!$this->dontUnlinkTempFiles) { + if (!$this->dontUnlinkTempFiles) { unlink($fileMenu); unlink($fileColor); unlink($fileMask); @@ -1565,25 +1518,6 @@ } - - - - - - - - - - - - - - - - - - - /**************************** * * Other GIFBUILDER objects @@ -1599,14 +1533,14 @@ * @return void * @see tslib_gifBuilder::make() */ - function makeBox(&$im,$conf,$workArea) { + function makeBox(&$im, $conf, $workArea) { - $cords = t3lib_div::intExplode(',',$conf['dimensions'].',,,'); + $cords = t3lib_div::intExplode(',', $conf['dimensions'] . ',,,'); - $conf['offset']=$cords[0].','.$cords[1]; + $conf['offset'] = $cords[0] . ',' . $cords[1]; - $cords = $this->objPosition($conf,$workArea,Array($cords[2],$cords[3])); + $cords = $this->objPosition($conf, $workArea, array($cords[2], $cords[3])); - $cols=$this->convertColor($conf['color']); + $cols = $this->convertColor($conf['color']); - if (!$this->truecolor) { + if (!$this->truecolor) { $reduce = t3lib_div::intInRange($this->setup['reduceColors'], 256, $this->truecolorColors, 256); - $this->reduceColors($im, $reduce-1, $reduce-2); // If "reduce-1" colors (or more) are used reduce them to "reduce-2" + $this->reduceColors($im, $reduce - 1, $reduce - 2); // If "reduce-1" colors (or more) are used reduce them to "reduce-2" } $opacity = 0; @@ -1619,8 +1553,8 @@ $opacity = round((127 * $opacity) / 100); } - $tmpColor = ImageColorAllocateAlpha($im, $cols[0],$cols[1],$cols[2], $opacity); + $tmpColor = ImageColorAllocateAlpha($im, $cols[0], $cols[1], $cols[2], $opacity); - imagefilledrectangle($im, $cords[0], $cords[1], $cords[0]+$cords[2]-1, $cords[1]+$cords[3]-1, $tmpColor); + imagefilledrectangle($im, $cords[0], $cords[1], $cords[0] + $cords[2] - 1, $cords[1] + $cords[3] - 1, $tmpColor); } /** @@ -1630,11 +1564,11 @@ * file { * XY = 200,200 * format = jpg - * quality = 100 + * quality = 100 * 10 = ELLIPSE - * 10.dimensions = 100,100,50,50 + * 10.dimensions = 100,100,50,50 * 10.color = red - * + * * $workArea = X,Y * $conf['dimensions'] = offset x, offset y, width of ellipse, height of ellipse * @@ -1648,7 +1582,7 @@ $ellipseConfiguration = t3lib_div::intExplode(',', $conf['dimensions'] . ',,,'); $conf['offset'] = $ellipseConfiguration[0] . ',' . $ellipseConfiguration[1]; // ellipse offset inside workArea (x/y) - // @see objPosition + // @see objPosition $imageCoordinates = $this->objPosition($conf, $workArea, array($ellipseConfiguration[2], $ellipseConfiguration[3])); $color = $this->convertColor($conf['color']); @@ -1665,9 +1599,9 @@ * @return void * @see tslib_gifBuilder::make(), applyImageMagickToPHPGif() */ - function makeEffect(&$im, $conf) { + function makeEffect(&$im, $conf) { $commands = $this->IMparams($conf['value']); - if ($commands) { + if ($commands) { $this->applyImageMagickToPHPGif($im, $commands); } } @@ -1680,75 +1614,77 @@ * @access private * @see makeEffect() */ - function IMparams($setup) { + function IMparams($setup) { - if (!trim($setup)){return '';} + if (!trim($setup)) { + return ''; + } $effects = explode('|', $setup); $commands = ''; foreach ($effects as $val) { - $pairs=explode('=',$val,2); + $pairs = explode('=', $val, 2); $value = trim($pairs[1]); $effect = strtolower(trim($pairs[0])); - switch($effect) { + switch ($effect) { case 'gamma': - $commands.=' -gamma '.doubleval($value); + $commands .= ' -gamma ' . doubleval($value); break; case 'blur': - if (!$this->NO_IM_EFFECTS) { + if (!$this->NO_IM_EFFECTS) { - if ($this->V5_EFFECTS) { + if ($this->V5_EFFECTS) { - $commands.=$this->v5_blur($value); + $commands .= $this->v5_blur($value); } else { - $commands.=' -blur '.t3lib_div::intInRange($value,1,99); + $commands .= ' -blur ' . t3lib_div::intInRange($value, 1, 99); } } break; case 'sharpen': - if (!$this->NO_IM_EFFECTS) { + if (!$this->NO_IM_EFFECTS) { - if ($this->V5_EFFECTS) { + if ($this->V5_EFFECTS) { - $commands.=$this->v5_sharpen($value); + $commands .= $this->v5_sharpen($value); } else { - $commands.=' -sharpen '.t3lib_div::intInRange($value,1,99); + $commands .= ' -sharpen ' . t3lib_div::intInRange($value, 1, 99); } } break; case 'rotate': - $commands.=' -rotate '.t3lib_div::intInRange($value,0,360); + $commands .= ' -rotate ' . t3lib_div::intInRange($value, 0, 360); break; case 'solarize': - $commands.=' -solarize '.t3lib_div::intInRange($value,0,99); + $commands .= ' -solarize ' . t3lib_div::intInRange($value, 0, 99); break; case 'swirl': - $commands.=' -swirl '.t3lib_div::intInRange($value,0,1000); + $commands .= ' -swirl ' . t3lib_div::intInRange($value, 0, 1000); break; case 'wave': - $params = t3lib_div::intExplode(',',$value); + $params = t3lib_div::intExplode(',', $value); - $commands.=' -wave '.t3lib_div::intInRange($params[0],0,99).'x'.t3lib_div::intInRange($params[1],0,99); + $commands .= ' -wave ' . t3lib_div::intInRange($params[0], 0, 99) . 'x' . t3lib_div::intInRange($params[1], 0, 99); break; case 'charcoal': - $commands.=' -charcoal '.t3lib_div::intInRange($value,0,100); + $commands .= ' -charcoal ' . t3lib_div::intInRange($value, 0, 100); break; case 'gray': - $commands.=' -colorspace GRAY'; + $commands .= ' -colorspace GRAY'; break; case 'edge': - $commands.=' -edge '.t3lib_div::intInRange($value,0,99); + $commands .= ' -edge ' . t3lib_div::intInRange($value, 0, 99); break; case 'emboss': - $commands.=' -emboss'; + $commands .= ' -emboss'; break; case 'flip': - $commands.=' -flip'; + $commands .= ' -flip'; break; case 'flop': - $commands.=' -flop'; + $commands .= ' -flop'; break; case 'colors': - $commands.=' -colors '.t3lib_div::intInRange($value,2,255); + $commands .= ' -colors ' . t3lib_div::intInRange($value, 2, 255); break; case 'shear': - $commands.=' -shear '.t3lib_div::intInRange($value,-90,90); + $commands .= ' -shear ' . t3lib_div::intInRange($value, -90, 90); break; case 'invert': - $commands.=' -negate'; + $commands .= ' -negate'; break; } } @@ -1763,22 +1699,24 @@ * @return void * @see tslib_gifBuilder::make(), autoLevels(), outputLevels(), inputLevels() */ - function adjust(&$im, $conf) { + function adjust(&$im, $conf) { $setup = $conf['value']; - if (!trim($setup)){return '';} + if (!trim($setup)) { + return ''; + } $effects = explode('|', $setup); foreach ($effects as $val) { - $pairs=explode('=',$val,2); + $pairs = explode('=', $val, 2); $value = trim($pairs[1]); $effect = strtolower(trim($pairs[0])); - switch($effect) { + switch ($effect) { - case 'inputlevels': // low,high + case 'inputlevels': // low,high - $params = t3lib_div::intExplode(',',$value); + $params = t3lib_div::intExplode(',', $value); - $this->inputLevels($im,$params[0],$params[1]); + $this->inputLevels($im, $params[0], $params[1]); break; case 'outputlevels': - $params = t3lib_div::intExplode(',',$value); + $params = t3lib_div::intExplode(',', $value); - $this->outputLevels($im,$params[0],$params[1]); + $this->outputLevels($im, $params[0], $params[1]); break; case 'autolevels': $this->autoLevels($im); @@ -1795,27 +1733,35 @@ * @return void * @see tslib_gifBuilder::make() */ - function crop(&$im,$conf) { + function crop(&$im, $conf) { - $this->setWorkArea(''); // clears workArea to total image + $this->setWorkArea(''); // clears workArea to total image - $cords = t3lib_div::intExplode(',',$conf['crop'].',,,'); + $cords = t3lib_div::intExplode(',', $conf['crop'] . ',,,'); - $conf['offset']=$cords[0].','.$cords[1]; + $conf['offset'] = $cords[0] . ',' . $cords[1]; - $cords = $this->objPosition($conf,$this->workArea,Array($cords[2],$cords[3])); + $cords = $this->objPosition($conf, $this->workArea, array($cords[2], $cords[3])); $newIm = imagecreatetruecolor($cords[2], $cords[3]); - $cols=$this->convertColor($conf['backColor']?$conf['backColor']:$this->setup['backColor']); + $cols = $this->convertColor($conf['backColor'] ? $conf['backColor'] : $this->setup['backColor']); - $Bcolor = ImageColorAllocate($newIm, $cols[0],$cols[1],$cols[2]); + $Bcolor = ImageColorAllocate($newIm, $cols[0], $cols[1], $cols[2]); ImageFilledRectangle($newIm, 0, 0, $cords[2], $cords[3], $Bcolor); - $newConf = Array(); - $workArea = Array(0,0,$cords[2],$cords[3]); - if ($cords[0]<0) {$workArea[0]=abs($cords[0]);} else {$newConf['offset']=-$cords[0];} - if ($cords[1]<0) {$workArea[1]=abs($cords[1]);} else {$newConf['offset'].=','.-$cords[1];} + $newConf = array(); + $workArea = array(0, 0, $cords[2], $cords[3]); + if ($cords[0] < 0) { + $workArea[0] = abs($cords[0]); + } else { + $newConf['offset'] = -$cords[0]; + } + if ($cords[1] < 0) { + $workArea[1] = abs($cords[1]); + } else { + $newConf['offset'] .= ',' . -$cords[1]; + } - $this->copyGifOntoGif($newIm,$im,$newConf,$workArea); + $this->copyGifOntoGif($newIm, $im, $newConf, $workArea); $im = $newIm; $this->w = imagesx($im); $this->h = imagesy($im); - $this->setWorkArea(''); // clears workArea to total image + $this->setWorkArea(''); // clears workArea to total image } /** @@ -1826,23 +1772,23 @@ * @return void * @see tslib_gifBuilder::make() */ - function scale(&$im,$conf) { + function scale(&$im, $conf) { - if ($conf['width'] || $conf['height'] || $conf['params']) { + if ($conf['width'] || $conf['height'] || $conf['params']) { $tmpStr = $this->randomName(); - $theFile = $tmpStr.'.'.$this->gifExtension; + $theFile = $tmpStr . '.' . $this->gifExtension; $this->ImageWrite($im, $theFile); - $theNewFile = $this->imageMagickConvert($theFile,$this->gifExtension,$conf['width'],$conf['height'],$conf['params'],'',''); + $theNewFile = $this->imageMagickConvert($theFile, $this->gifExtension, $conf['width'], $conf['height'], $conf['params'], '', ''); $tmpImg = $this->imageCreateFromFile($theNewFile[3]); - if ($tmpImg) { + if ($tmpImg) { ImageDestroy($im); $im = $tmpImg; $this->w = imagesx($im); $this->h = imagesy($im); - $this->setWorkArea(''); // clears workArea to total image + $this->setWorkArea(''); // clears workArea to total image } - if (!$this->dontUnlinkTempFiles) { + if (!$this->dontUnlinkTempFiles) { unlink($theFile); - if ($theNewFile[3] && $theNewFile[3]!=$theFile) { + if ($theNewFile[3] && $theNewFile[3] != $theFile) { unlink($theNewFile[3]); } } @@ -1858,35 +1804,18 @@ * @access private * @see tslib_gifBuilder::make() */ - function setWorkArea($workArea) { + function setWorkArea($workArea) { - $this->workArea = t3lib_div::intExplode(',',$workArea); + $this->workArea = t3lib_div::intExplode(',', $workArea); - $this->workArea = $this->applyOffset($this->workArea,$this->OFFSET); + $this->workArea = $this->applyOffset($this->workArea, $this->OFFSET); - if (!$this->workArea[2]) {$this->workArea[2]=$this->w;} - if (!$this->workArea[3]) {$this->workArea[3]=$this->h;} + if (!$this->workArea[2]) { + $this->workArea[2] = $this->w; - } + } + if (!$this->workArea[3]) { + $this->workArea[3] = $this->h; + } + } - - - - - - - - - - - - - - - - - - - - - /************************* * * Adjustment functions @@ -1899,24 +1828,24 @@ * @param integer GDlib Image Pointer * @return void */ - function autolevels(&$im) { + function autolevels(&$im) { $totalCols = ImageColorsTotal($im); - $min=255; + $min = 255; - $max=0; + $max = 0; - for ($c=0; $c<$totalCols; $c++) { + for ($c = 0; $c < $totalCols; $c++) { - $cols = ImageColorsForIndex($im,$c); + $cols = ImageColorsForIndex($im, $c); - $grayArr[] = round(($cols['red']+$cols['green']+$cols['blue'])/3); + $grayArr[] = round(($cols['red'] + $cols['green'] + $cols['blue']) / 3); } - $min=min($grayArr); + $min = min($grayArr); - $max=max($grayArr); + $max = max($grayArr); - $delta = $max-$min; + $delta = $max - $min; - if ($delta) { + if ($delta) { - for ($c=0; $c<$totalCols; $c++) { + for ($c = 0; $c < $totalCols; $c++) { - $cols = ImageColorsForIndex($im,$c); + $cols = ImageColorsForIndex($im, $c); - $cols['red'] = floor(($cols['red']-$min)/$delta*255); + $cols['red'] = floor(($cols['red'] - $min) / $delta * 255); - $cols['green'] = floor(($cols['green']-$min)/$delta*255); + $cols['green'] = floor(($cols['green'] - $min) / $delta * 255); - $cols['blue'] = floor(($cols['blue']-$min)/$delta*255); + $cols['blue'] = floor(($cols['blue'] - $min) / $delta * 255); - ImageColorSet($im,$c,$cols['red'],$cols['green'],$cols['blue']); + ImageColorSet($im, $c, $cols['red'], $cols['green'], $cols['blue']); } } } @@ -1930,25 +1859,25 @@ * @param boolean If swap, then low and high are swapped. (Useful for negated masks...) * @return void */ - function outputLevels(&$im,$low,$high,$swap='') { + function outputLevels(&$im, $low, $high, $swap = '') { - if ($low<$high){ + if ($low < $high) { - $low = t3lib_div::intInRange($low,0,255); + $low = t3lib_div::intInRange($low, 0, 255); - $high = t3lib_div::intInRange($high,0,255); + $high = t3lib_div::intInRange($high, 0, 255); - if ($swap) { + if ($swap) { $temp = $low; - $low = 255-$high; + $low = 255 - $high; - $high = 255-$temp; + $high = 255 - $temp; } - $delta = $high-$low; + $delta = $high - $low; $totalCols = ImageColorsTotal($im); - for ($c=0; $c<$totalCols; $c++) { + for ($c = 0; $c < $totalCols; $c++) { - $cols = ImageColorsForIndex($im,$c); + $cols = ImageColorsForIndex($im, $c); - $cols['red'] = $low+floor($cols['red']/255*$delta); + $cols['red'] = $low + floor($cols['red'] / 255 * $delta); - $cols['green'] = $low+floor($cols['green']/255*$delta); + $cols['green'] = $low + floor($cols['green'] / 255 * $delta); - $cols['blue'] = $low+floor($cols['blue']/255*$delta); + $cols['blue'] = $low + floor($cols['blue'] / 255 * $delta); - ImageColorSet($im,$c,$cols['red'],$cols['green'],$cols['blue']); + ImageColorSet($im, $c, $cols['red'], $cols['green'], $cols['blue']); } } } @@ -1962,25 +1891,25 @@ * @param boolean If swap, then low and high are swapped. (Useful for negated masks...) * @return void */ - function inputLevels(&$im,$low,$high,$swap='') { + function inputLevels(&$im, $low, $high, $swap = '') { - if ($low<$high){ + if ($low < $high) { - $low = t3lib_div::intInRange($low,0,255); + $low = t3lib_div::intInRange($low, 0, 255); - $high = t3lib_div::intInRange($high,0,255); + $high = t3lib_div::intInRange($high, 0, 255); - if ($swap) { + if ($swap) { $temp = $low; - $low = 255-$high; + $low = 255 - $high; - $high = 255-$temp; + $high = 255 - $temp; } - $delta = $high-$low; + $delta = $high - $low; $totalCols = ImageColorsTotal($im); - for ($c=0; $c<$totalCols; $c++) { + for ($c = 0; $c < $totalCols; $c++) { - $cols = ImageColorsForIndex($im,$c); + $cols = ImageColorsForIndex($im, $c); - $cols['red'] = t3lib_div::intInRange(($cols['red']-$low)/$delta*255, 0,255); + $cols['red'] = t3lib_div::intInRange(($cols['red'] - $low) / $delta * 255, 0, 255); - $cols['green'] = t3lib_div::intInRange(($cols['green']-$low)/$delta*255, 0,255); + $cols['green'] = t3lib_div::intInRange(($cols['green'] - $low) / $delta * 255, 0, 255); - $cols['blue'] = t3lib_div::intInRange(($cols['blue']-$low)/$delta*255, 0,255); + $cols['blue'] = t3lib_div::intInRange(($cols['blue'] - $low) / $delta * 255, 0, 255); - ImageColorSet($im,$c,$cols['red'],$cols['green'],$cols['blue']); + ImageColorSet($im, $c, $cols['red'], $cols['green'], $cols['blue']); } } } @@ -1995,11 +1924,11 @@ * @return void * @deprecated since TYPO3 4.4, this function will be removed in TYPO3 4.6. */ - function reduceColors(&$im,$limit, $cols) { + function reduceColors(&$im, $limit, $cols) { t3lib_div::logDeprecatedFunction(); - if (!$this->truecolor && ImageColorsTotal($im)>=$limit) { + if (!$this->truecolor && ImageColorsTotal($im) >= $limit) { - $this->makeEffect($im, Array('value'=>'colors='.$cols) ); + $this->makeEffect($im, array('value' => 'colors=' . $cols)); } } @@ -2010,19 +1939,23 @@ * @param integer Number of colors to reduce the image to. * @return string Reduced file */ - function IMreduceColors($file, $cols) { + function IMreduceColors($file, $cols) { $fI = t3lib_div::split_fileref($file); $ext = strtolower($fI['fileext']); - $result = $this->randomName().'.'.$ext; + $result = $this->randomName() . '.' . $ext; - if (($reduce = t3lib_div::intInRange($cols, 0, ($ext=='gif'?256:$this->truecolorColors), 0))>0) { + if (($reduce = t3lib_div::intInRange($cols, 0, ($ext == 'gif' ? 256 : $this->truecolorColors), 0)) > 0) { - $params = ' -colors '.$reduce; + $params = ' -colors ' . $reduce; - if (!$this->im_version_4) { + if (!$this->im_version_4) { // IM4 doesn't have this options but forces them automatically if applicaple (<256 colors in image) - if ($reduce<=256) { $params .= ' -type Palette'; } - if ($ext=='png' && $reduce<=256) { $prefix = 'png8:'; } + if ($reduce <= 256) { + $params .= ' -type Palette'; - } + } + if ($ext == 'png' && $reduce <= 256) { + $prefix = 'png8:'; + } + } - $this->imageMagickExec($file, $prefix.$result, $params); + $this->imageMagickExec($file, $prefix . $result, $params); - if ($result) { + if ($result) { return $result; } } @@ -2030,15 +1963,6 @@ } - - - - - - - - - /********************************* * * GIFBUILDER Helper functions @@ -2053,9 +1977,9 @@ * @param string The font file * @return string The font file with absolute path. */ - function prependAbsolutePath($fontFile) { + function prependAbsolutePath($fontFile) { - $absPath = defined('PATH_typo3') ? dirname(PATH_thisScript).'/' :PATH_site; + $absPath = defined('PATH_typo3') ? dirname(PATH_thisScript) . '/' : PATH_site; - $fontFile = t3lib_div::isAbsPath($fontFile) ? $fontFile : t3lib_div::resolveBackPath($absPath.$fontFile); + $fontFile = t3lib_div::isAbsPath($fontFile) ? $fontFile : t3lib_div::resolveBackPath($absPath . $fontFile); return $fontFile; } @@ -2067,13 +1991,13 @@ * @return string The sharpening command, eg. " -sharpen 3x4" * @see makeText(), IMparams(), v5_blur() */ - function v5_sharpen($factor) { + function v5_sharpen($factor) { - $factor = t3lib_div::intInRange(ceil($factor/10),0,10); + $factor = t3lib_div::intInRange(ceil($factor / 10), 0, 10); - $sharpenArr=explode(',',','.$this->im5fx_sharpenSteps); + $sharpenArr = explode(',', ',' . $this->im5fx_sharpenSteps); - $sharpenF= trim($sharpenArr[$factor]); + $sharpenF = trim($sharpenArr[$factor]); - if ($sharpenF) { + if ($sharpenF) { - $cmd = ' -sharpen '.$sharpenF; + $cmd = ' -sharpen ' . $sharpenF; return $cmd; } } @@ -2086,13 +2010,13 @@ * @return string The blurring command, eg. " -blur 3x4" * @see makeText(), IMparams(), v5_sharpen() */ - function v5_blur($factor) { + function v5_blur($factor) { - $factor = t3lib_div::intInRange(ceil($factor/10),0,10); + $factor = t3lib_div::intInRange(ceil($factor / 10), 0, 10); - $blurArr=explode(',',','.$this->im5fx_blurSteps); + $blurArr = explode(',', ',' . $this->im5fx_blurSteps); - $blurF= trim($blurArr[$factor]); + $blurF = trim($blurArr[$factor]); - if ($blurF) { + if ($blurF) { - $cmd=' -blur '.$blurF; + $cmd = ' -blur ' . $blurF; return $cmd; } } @@ -2103,9 +2027,9 @@ * * @return string */ - function randomName() { + function randomName() { $this->createTempSubDir('temp/'); - return $this->tempPath.'temp/'.md5(uniqid('')); + return $this->tempPath . 'temp/' . md5(uniqid('')); } /** @@ -2116,9 +2040,9 @@ * @param array Offset values in key 0/1 * @return array Modified $cords array */ - function applyOffset($cords,$OFFSET) { + function applyOffset($cords, $OFFSET) { - $cords[0] = intval($cords[0])+intval($OFFSET[0]); + $cords[0] = intval($cords[0]) + intval($OFFSET[0]); - $cords[1] = intval($cords[1])+intval($OFFSET[1]); + $cords[1] = intval($cords[1]) + intval($OFFSET[1]); return $cords; } @@ -2129,44 +2053,44 @@ * @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 * @return array RGB values in key 0/1/2 of the array */ - function convertColor($string) { + function convertColor($string) { - $col=array(); + $col = array(); - $cParts = explode(':',$string,2); + $cParts = explode(':', $string, 2); // Finding the RGB definitions of the color: - $string=$cParts[0]; + $string = $cParts[0]; - if (strstr($string,'#')) { + if (strstr($string, '#')) { - $string = preg_replace('/[^A-Fa-f0-9]*/','',$string); + $string = preg_replace('/[^A-Fa-f0-9]*/', '', $string); - $col[]=HexDec(substr($string,0,2)); + $col[] = HexDec(substr($string, 0, 2)); - $col[]=HexDec(substr($string,2,2)); + $col[] = HexDec(substr($string, 2, 2)); - $col[]=HexDec(substr($string,4,2)); + $col[] = HexDec(substr($string, 4, 2)); - } elseif (strstr($string,',')) { + } elseif (strstr($string, ',')) { - $string = preg_replace('/[^,0-9]*/','',$string); + $string = preg_replace('/[^,0-9]*/', '', $string); - $strArr = explode(',',$string); + $strArr = explode(',', $string); - $col[]=intval($strArr[0]); + $col[] = intval($strArr[0]); - $col[]=intval($strArr[1]); + $col[] = intval($strArr[1]); - $col[]=intval($strArr[2]); + $col[] = intval($strArr[2]); } else { $string = strtolower(trim($string)); - if ($this->colMap[$string]) { + if ($this->colMap[$string]) { $col = $this->colMap[$string]; } else { - $col = Array(0,0,0); + $col = array(0, 0, 0); } } // ... and possibly recalculating the value - if (trim($cParts[1])) { + if (trim($cParts[1])) { - $cParts[1]=trim($cParts[1]); + $cParts[1] = trim($cParts[1]); - if (substr($cParts[1],0,1)=='*') { + if (substr($cParts[1], 0, 1) == '*') { - $val=doubleval(substr($cParts[1],1)); + $val = doubleval(substr($cParts[1], 1)); - $col[0]=t3lib_div::intInRange($col[0]*$val,0,255); + $col[0] = t3lib_div::intInRange($col[0] * $val, 0, 255); - $col[1]=t3lib_div::intInRange($col[1]*$val,0,255); + $col[1] = t3lib_div::intInRange($col[1] * $val, 0, 255); - $col[2]=t3lib_div::intInRange($col[2]*$val,0,255); + $col[2] = t3lib_div::intInRange($col[2] * $val, 0, 255); } else { - $val=intval($cParts[1]); + $val = intval($cParts[1]); - $col[0]=t3lib_div::intInRange($col[0]+$val,0,255); + $col[0] = t3lib_div::intInRange($col[0] + $val, 0, 255); - $col[1]=t3lib_div::intInRange($col[1]+$val,0,255); + $col[1] = t3lib_div::intInRange($col[1] + $val, 0, 255); - $col[2]=t3lib_div::intInRange($col[2]+$val,0,255); + $col[2] = t3lib_div::intInRange($col[2] + $val, 0, 255); } } return $col; @@ -2179,17 +2103,17 @@ * @param string The text to recode * @return string The recoded string. Should be UTF-8 output. MAY contain entities (eg. { or &#quot; which should render as real chars). */ - function recodeString($string) { + function recodeString($string) { // Recode string to UTF-8 from $this->nativeCharset: - if ($this->nativeCharset && $this->nativeCharset!='utf-8') { + if ($this->nativeCharset && $this->nativeCharset != 'utf-8') { - $string = $this->csConvObj->utf8_encode($string,$this->nativeCharset); // Convert to UTF-8 + $string = $this->csConvObj->utf8_encode($string, $this->nativeCharset); // Convert to UTF-8 } // Recode string accoding to TTFLocaleConv. Deprecated. if ($this->TTFLocaleConv) { t3lib_div::deprecationLog('The option $TYPO3_CONF_VARS[\'GFX\'][\'TTFLocaleConv\'] is in use, but deprecated since TYPO3 3.6, will be removed in TYPO3 4.6. Make sure to unset this variable in your typo3conf/localconf.php and use a different way to encode your string.'); - list($from, $to) = t3lib_div::trimExplode('..', $this->TTFLocaleConv, true); + list($from, $to) = t3lib_div::trimExplode('..', $this->TTFLocaleConv, TRUE); $string = $this->csConvObj->conv($string, $from, $to); } @@ -2204,14 +2128,14 @@ * @param boolean Return Unicode numbers instead of chars. * @return array Numerical array with a char as each value. */ - function singleChars($theText,$returnUnicodeNumber=FALSE) { + function singleChars($theText, $returnUnicodeNumber = FALSE) { - if ($this->nativeCharset) { + if ($this->nativeCharset) { - return $this->csConvObj->utf8_to_numberarray($theText,1,$returnUnicodeNumber ? 0 : 1); // Get an array of separated UTF-8 chars + return $this->csConvObj->utf8_to_numberarray($theText, 1, $returnUnicodeNumber ? 0 : 1); // Get an array of separated UTF-8 chars } else { - $output=array(); + $output = array(); - $c=strlen($theText); + $c = strlen($theText); - for($a=0;$a<$c;$a++) { + for ($a = 0; $a < $c; $a++) { - $output[]=substr($theText,$a,1); + $output[] = substr($theText, $a, 1); } return $output; } @@ -2227,65 +2151,46 @@ * @access private * @see copyGifOntoGif(), makeBox(), crop() */ - function objPosition($conf,$workArea,$BB) { + function objPosition($conf, $workArea, $BB) { // offset, align, valign, workarea - $result=Array(); + $result = array(); $result[2] = $BB[0]; $result[3] = $BB[1]; - $w=$workArea[2]; + $w = $workArea[2]; - $h=$workArea[3]; + $h = $workArea[3]; - $align = explode(',',$conf['align']); + $align = explode(',', $conf['align']); - $align[0] = strtolower(substr(trim($align[0]),0,1)); + $align[0] = strtolower(substr(trim($align[0]), 0, 1)); - $align[1] = strtolower(substr(trim($align[1]),0,1)); + $align[1] = strtolower(substr(trim($align[1]), 0, 1)); - switch($align[0]) { + switch ($align[0]) { case 'r': - $result[0]=$w-$result[2]; + $result[0] = $w - $result[2]; break; case 'c': - $result[0] = round(($w-$result[2])/2); + $result[0] = round(($w - $result[2]) / 2); break; default: $result[0] = 0; break; } - switch($align[1]) { + switch ($align[1]) { case 'b': - $result[1] = $h-$result[3]; // y pos + $result[1] = $h - $result[3]; // y pos break; case 'c': - $result[1] = round(($h-$result[3])/2); + $result[1] = round(($h - $result[3]) / 2); break; default: - $result[1]=0; + $result[1] = 0; break; } - $result = $this->applyOffset($result,t3lib_div::intExplode(',',$conf['offset'])); + $result = $this->applyOffset($result, t3lib_div::intExplode(',', $conf['offset'])); - $result = $this->applyOffset($result,$workArea); + $result = $this->applyOffset($result, $workArea); return $result; } - - - - - - - - - - - - - - - - - - - /*********************************** * * Scaling, Dimensions of images @@ -2306,43 +2211,47 @@ * @return array [0]/[1] is w/h, [2] is file extension and [3] is the filename. * @see getImageScale(), typo3/show_item.php, fileList_ext::renderImage(), tslib_cObj::getImgResource(), SC_tslib_showpic::show(), maskImageOntoImage(), copyImageOntoImage(), scale() */ - function imageMagickConvert($imagefile,$newExt='',$w='',$h='',$params='',$frame='',$options='',$mustCreate=0) { + function imageMagickConvert($imagefile, $newExt = '', $w = '', $h = '', $params = '', $frame = '', $options = '', $mustCreate = 0) { - if ($this->NO_IMAGE_MAGICK) { + if ($this->NO_IMAGE_MAGICK) { // Returning file info right away return $this->getImageDimensions($imagefile); } - if($info=$this->getImageDimensions($imagefile)) { + if ($info = $this->getImageDimensions($imagefile)) { - $newExt=strtolower(trim($newExt)); + $newExt = strtolower(trim($newExt)); - if (!$newExt) { // If no extension is given the original extension is used + if (!$newExt) { // If no extension is given the original extension is used $newExt = $info[2]; } - if ($newExt=='web') { + if ($newExt == 'web') { - if (t3lib_div::inList($this->webImageExt,$info[2])) { + if (t3lib_div::inList($this->webImageExt, $info[2])) { $newExt = $info[2]; } else { - $newExt = $this->gif_or_jpg($info[2],$info[0],$info[1]); + $newExt = $this->gif_or_jpg($info[2], $info[0], $info[1]); - if (!$params) { + if (!$params) { $params = $this->cmds[$newExt]; } } } - if (t3lib_div::inList($this->imageFileExt,$newExt)) { + if (t3lib_div::inList($this->imageFileExt, $newExt)) { - if (strstr($w.$h, 'm')) {$max=1;} else {$max=0;} + if (strstr($w . $h, 'm')) { + $max = 1; + } else { + $max = 0; + } - $data = $this->getImageScale($info,$w,$h,$options); + $data = $this->getImageScale($info, $w, $h, $options); - $w=$data['origW']; + $w = $data['origW']; - $h=$data['origH']; + $h = $data['origH']; // if no conversion should be performed - // this flag is true if the width / height does NOT dictate + // this flag is true if the width / height does NOT dictate // the image to be scaled!! (that is if no width / height is // given or if the destination w/h matches the original image // dimensions or if the option to not scale the image is set) $noScale = (!$w && !$h) || ($data[0] == $info[0] && $data[1] == $info[1]) || $options['noScale']; if ($noScale && !$data['crs'] && !$params && !$frame && $newExt == $info[2] && !$mustCreate) { - // set the new width and height before returning, + // set the new width and height before returning, // if the noScale option is set if ($options['noScale']) { $info[0] = $data[0]; @@ -2351,55 +2260,59 @@ $info[3] = $imagefile; return $info; } - $info[0]=$data[0]; + $info[0] = $data[0]; - $info[1]=$data[1]; + $info[1] = $data[1]; $frame = $this->noFramePrepended ? '' : intval($frame); - if (!$params) { + if (!$params) { $params = $this->cmds[$newExt]; } // Cropscaling: if ($data['crs']) { - if (!$data['origW']) { $data['origW'] = $data[0]; } - if (!$data['origH']) { $data['origH'] = $data[1]; } + if (!$data['origW']) { + $data['origW'] = $data[0]; + } + if (!$data['origH']) { + $data['origH'] = $data[1]; + } - $offsetX = intval(($data[0] - $data['origW']) * ($data['cropH']+100)/200); + $offsetX = intval(($data[0] - $data['origW']) * ($data['cropH'] + 100) / 200); - $offsetY = intval(($data[1] - $data['origH']) * ($data['cropV']+100)/200); + $offsetY = intval(($data[1] - $data['origH']) * ($data['cropV'] + 100) / 200); - $params .= ' -crop '.$data['origW'].'x'.$data['origH'].'+'.$offsetX.'+'.$offsetY.' '; + $params .= ' -crop ' . $data['origW'] . 'x' . $data['origH'] . '+' . $offsetX . '+' . $offsetY . ' '; } - $command = $this->scalecmd.' '.$info[0].'x'.$info[1].'! '.$params.' '; + $command = $this->scalecmd . ' ' . $info[0] . 'x' . $info[1] . '! ' . $params . ' '; - $cropscale = ($data['crs'] ? 'crs-V'.$data['cropV'].'H'.$data['cropH'] : ''); + $cropscale = ($data['crs'] ? 'crs-V' . $data['cropV'] . 'H' . $data['cropH'] : ''); - if ($this->alternativeOutputKey) { + if ($this->alternativeOutputKey) { - $theOutputName = t3lib_div::shortMD5($command.$cropscale.basename($imagefile).$this->alternativeOutputKey.'['.$frame.']'); + $theOutputName = t3lib_div::shortMD5($command . $cropscale . basename($imagefile) . $this->alternativeOutputKey . '[' . $frame . ']'); } else { - $theOutputName = t3lib_div::shortMD5($command.$cropscale.$imagefile.filemtime($imagefile).'['.$frame.']'); + $theOutputName = t3lib_div::shortMD5($command . $cropscale . $imagefile . filemtime($imagefile) . '[' . $frame . ']'); } - if ($this->imageMagickConvert_forceFileNameBody) { + if ($this->imageMagickConvert_forceFileNameBody) { $theOutputName = $this->imageMagickConvert_forceFileNameBody; - $this->imageMagickConvert_forceFileNameBody=''; + $this->imageMagickConvert_forceFileNameBody = ''; } // Making the temporary filename: $this->createTempSubDir('pics/'); - $output = $this->absPrefix.$this->tempPath.'pics/'.$this->filenamePrefix.$theOutputName.'.'.$newExt; + $output = $this->absPrefix . $this->tempPath . 'pics/' . $this->filenamePrefix . $theOutputName . '.' . $newExt; // Register temporary filename: $GLOBALS['TEMP_IMAGES_ON_PAGE'][] = $output; - if ($this->dontCheckForExistingTempFile || !$this->file_exists_typo3temp_file($output, $imagefile)) { + if ($this->dontCheckForExistingTempFile || !$this->file_exists_typo3temp_file($output, $imagefile)) { $this->imageMagickExec($imagefile, $output, $command, $frame); } - if (file_exists($output)) { + if (file_exists($output)) { $info[3] = $output; $info[2] = $newExt; - if ($params) { // params could realisticly change some imagedata! + if ($params) { // params could realisticly change some imagedata! - $info=$this->getImageDimensions($info[3]); + $info = $this->getImageDimensions($info[3]); } - if ($info[2]==$this->gifExtension && !$this->dontCompress) { + if ($info[2] == $this->gifExtension && !$this->dontCompress) { - t3lib_div::gif_compress($info[3],''); // Compress with IM (lzw) or GD (rle) (Workaround for the absence of lzw-compression in GD) + t3lib_div::gif_compress($info[3], ''); // Compress with IM (lzw) or GD (rle) (Workaround for the absence of lzw-compression in GD) } return $info; } @@ -2414,14 +2327,14 @@ * @return array Returns an array where [0]/[1] is w/h, [2] is extension and [3] is the filename. * @see imageMagickConvert(), tslib_cObj::getImgResource() */ - function getImageDimensions($imageFile) { + function getImageDimensions($imageFile) { - preg_match('/([^\.]*)$/',$imageFile,$reg); + preg_match('/([^\.]*)$/', $imageFile, $reg); - if (file_exists($imageFile) && t3lib_div::inList($this->imageFileExt,strtolower($reg[0]))) { + if (file_exists($imageFile) && t3lib_div::inList($this->imageFileExt, strtolower($reg[0]))) { - if ($returnArr = $this->getCachedImageDimensions($imageFile)) { + if ($returnArr = $this->getCachedImageDimensions($imageFile)) { return $returnArr; } else { - if ($temp = @getImageSize($imageFile)) { + if ($temp = @getImageSize($imageFile)) { - $returnArr = Array($temp[0], $temp[1], strtolower($reg[0]), $imageFile); + $returnArr = array($temp[0], $temp[1], strtolower($reg[0]), $imageFile); } else { $returnArr = $this->imageMagickIdentify($imageFile); } @@ -2431,7 +2344,7 @@ } } } - return false; + return FALSE; } /** @@ -2442,12 +2355,12 @@ * @return boolean True if operation was successful * @author Michael Stucki / Robert Lemke */ - function cacheImageDimensions($identifyResult) { + function cacheImageDimensions($identifyResult) { global $TYPO3_DB; // Create a md5 hash of the filename $md5Hash = md5_file($identifyResult[3]); if ($md5Hash) { - $fieldArr = array ( + $fieldArr = array( 'md5hash' => $md5Hash, 'md5filename' => md5($identifyResult[3]), 'tstamp' => $GLOBALS['EXEC_TIME'], @@ -2456,11 +2369,11 @@ 'imageheight' => $identifyResult[1], ); $TYPO3_DB->exec_INSERTquery('cache_imagesizes', $fieldArr); - if (!$err = $TYPO3_DB->sql_error()) { + if (!$err = $TYPO3_DB->sql_error()) { - return true; + return TRUE; } } - return false; + return FALSE; } /** @@ -2470,23 +2383,23 @@ * @return array Returns an array where [0]/[1] is w/h, [2] is extension and [3] is the filename. * @author Michael Stucki / Robert Lemke */ - function getCachedImageDimensions($imageFile) { + function getCachedImageDimensions($imageFile) { global $TYPO3_DB; // Create a md5 hash of the filename $md5Hash = md5_file($imageFile); - preg_match('/([^\.]*)$/',$imageFile,$reg); + preg_match('/([^\.]*)$/', $imageFile, $reg); - $res = $TYPO3_DB->exec_SELECTquery ('md5hash, imagewidth, imageheight', 'cache_imagesizes', 'md5filename='.$TYPO3_DB->fullQuoteStr(md5($imageFile),'cache_imagesizes')); + $res = $TYPO3_DB->exec_SELECTquery('md5hash, imagewidth, imageheight', 'cache_imagesizes', 'md5filename=' . $TYPO3_DB->fullQuoteStr(md5($imageFile), 'cache_imagesizes')); if ($res) { if ($row = $TYPO3_DB->sql_fetch_assoc($res)) { - if ($row['md5hash']!=$md5Hash) { + if ($row['md5hash'] != $md5Hash) { // file has changed, delete the row - $TYPO3_DB->exec_DELETEquery ('cache_imagesizes', 'md5hash='.$TYPO3_DB->fullQuoteStr($row['md5hash'],'cache_imagesizes')); + $TYPO3_DB->exec_DELETEquery('cache_imagesizes', 'md5hash=' . $TYPO3_DB->fullQuoteStr($row['md5hash'], 'cache_imagesizes')); } else { return (array((int) $row['imagewidth'], (int) $row['imageheight'], strtolower($reg[0]), $imageFile)); } } } - return false; + return FALSE; } /** @@ -2500,74 +2413,82 @@ * @access private * @see imageMagickConvert() */ - function getImageScale($info,$w,$h,$options) { + function getImageScale($info, $w, $h, $options) { - if (strstr($w.$h, 'm')) {$max=1;} else {$max=0;} + if (strstr($w . $h, 'm')) { + $max = 1; + } else { + $max = 0; + } - if (strstr($w.$h, 'c')) { + if (strstr($w . $h, 'c')) { $out['cropH'] = intval(substr(strstr($w, 'c'), 1)); $out['cropV'] = intval(substr(strstr($h, 'c'), 1)); - $crs = true; + $crs = TRUE; } else { - $crs = false; + $crs = FALSE; } $out['crs'] = $crs; - $w=intval($w); + $w = intval($w); - $h=intval($h); + $h = intval($h); // if there are max-values... - if ($options['maxW']) { + if ($options['maxW']) { - if ($w) { // if width is given... + if ($w) { // if width is given... - if ($w>$options['maxW']) { + if ($w > $options['maxW']) { - $w=$options['maxW']; + $w = $options['maxW']; - $max=1; // height should follow + $max = 1; // height should follow } } else { - if ($info[0]>$options['maxW']) { + if ($info[0] > $options['maxW']) { - $w=$options['maxW']; + $w = $options['maxW']; - $max=1; // height should follow + $max = 1; // height should follow } } } - if ($options['maxH']) { + if ($options['maxH']) { - if ($h) { // if height is given... + if ($h) { // if height is given... - if ($h>$options['maxH']) { + if ($h > $options['maxH']) { - $h=$options['maxH']; + $h = $options['maxH']; - $max=1; // height should follow + $max = 1; // height should follow } } else { - if ($info[1]>$options['maxH']) { // Changed [0] to [1] 290801 + if ($info[1] > $options['maxH']) { // Changed [0] to [1] 290801 - $h=$options['maxH']; + $h = $options['maxH']; - $max=1; // height should follow + $max = 1; // height should follow } } } - $out['origW']=$w; + $out['origW'] = $w; - $out['origH']=$h; + $out['origH'] = $h; $out['max'] = $max; if (!$this->mayScaleUp) { - if ($w>$info[0]){$w=$info[0];} - if ($h>$info[1]){$h=$info[1];} + if ($w > $info[0]) { + $w = $info[0]; - } + } + if ($h > $info[1]) { + $h = $info[1]; + } + } - if ($w || $h) { // if scaling should be performed + if ($w || $h) { // if scaling should be performed - if ($w && !$h) { + if ($w && !$h) { - $info[1] = ceil($info[1]*($w/$info[0])); + $info[1] = ceil($info[1] * ($w / $info[0])); $info[0] = $w; } - if (!$w && $h) { + if (!$w && $h) { - $info[0] = ceil($info[0]*($h/$info[1])); + $info[0] = ceil($info[0] * ($h / $info[1])); $info[1] = $h; } - if ($w && $h) { + if ($w && $h) { - if ($max) { + if ($max) { - $ratio = $info[0]/$info[1]; + $ratio = $info[0] / $info[1]; - if ($h*$ratio > $w) { + if ($h * $ratio > $w) { - $h = round($w/$ratio); + $h = round($w / $ratio); } else { - $w = round($h*$ratio); + $w = round($h * $ratio); } } - if ($crs) { + if ($crs) { $ratio = $info[0] / $info[1]; if ($h * $ratio < $w) { $h = round($w / $ratio); @@ -2579,20 +2500,20 @@ $info[1] = $h; } } - $out[0]=$info[0]; + $out[0] = $info[0]; - $out[1]=$info[1]; + $out[1] = $info[1]; // Set minimum-measures! - if ($options['minW'] && $out[0]<$options['minW']) { + if ($options['minW'] && $out[0] < $options['minW']) { - if (($max || $crs) && $out[0]) { + if (($max || $crs) && $out[0]) { - $out[1]= round($out[1]*$options['minW']/$out[0]); + $out[1] = round($out[1] * $options['minW'] / $out[0]); } - $out[0]=$options['minW']; + $out[0] = $options['minW']; } - if ($options['minH'] && $out[1]<$options['minH']) { + if ($options['minH'] && $out[1] < $options['minH']) { - if (($max || $crs) && $out[1]) { + if (($max || $crs) && $out[1]) { - $out[0]= round($out[0]*$options['minH']/$out[1]); + $out[0] = round($out[0] * $options['minH'] / $out[1]); } - $out[1]=$options['minH']; + $out[1] = $options['minH']; } return $out; @@ -2606,22 +2527,26 @@ * @return boolean Returns true if the file is already being made; thus "true" means "Don't render the image again" * @access private */ - function file_exists_typo3temp_file($output,$orig='') { + function file_exists_typo3temp_file($output, $orig = '') { - if ($this->enable_typo3temp_db_tracking) { + if ($this->enable_typo3temp_db_tracking) { - if (file_exists($output)) { // If file exists, then we return immediately + if (file_exists($output)) { // If file exists, then we return immediately return 1; - } else { // If not, we look up in the cache_typo3temp_log table to see if there is a image being rendered right now. + } else { // If not, we look up in the cache_typo3temp_log table to see if there is a image being rendered right now. - $md5Hash=md5($output); + $md5Hash = md5($output); $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery( 'md5hash', 'cache_typo3temp_log', 'md5hash=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($md5Hash, 'cache_typo3temp_log') . ' AND tstamp>' . ($GLOBALS['EXEC_TIME'] - 30) ); - if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { // If there was a record, the image is being generated by another proces (we assume) + if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { // If there was a record, the image is being generated by another proces (we assume) - 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...) - if (is_object($GLOBALS['TT'])) $GLOBALS['TT']->setTSlogMessage('typo3temp_log: Assume this file is being rendered now: '.$output); + 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...) + if (is_object($GLOBALS['TT'])) { + $GLOBALS['TT']->setTSlogMessage('typo3temp_log: Assume this file is being rendered now: ' . $output); + } - return 2; // Return 'success - 2' + return 2; // Return 'success - 2' - } 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. + } 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. $insertFields = array( 'md5hash' => $md5Hash, @@ -2629,10 +2554,12 @@ 'filename' => $output, 'orig_filename' => $orig ); - $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_typo3temp_log', 'md5hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr($md5Hash, 'cache_typo3temp_log')); + $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_typo3temp_log', 'md5hash=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($md5Hash, 'cache_typo3temp_log')); $GLOBALS['TYPO3_DB']->exec_INSERTquery('cache_typo3temp_log', $insertFields); - 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); + 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); + } return 0; } } @@ -2642,22 +2569,6 @@ } - - - - - - - - - - - - - - - - /*********************************** * * ImageMagick API functions @@ -2671,27 +2582,29 @@ * @param string The relative (to PATH_site) image filepath * @return array */ - function imageMagickIdentify($imagefile) { + function imageMagickIdentify($imagefile) { - if (!$this->NO_IMAGE_MAGICK) { + if (!$this->NO_IMAGE_MAGICK) { - $frame = $this->noFramePrepended?'':'[0]'; + $frame = $this->noFramePrepended ? '' : '[0]'; - $cmd = t3lib_div::imageMagickCommand('identify', $this->wrapFileName($imagefile).$frame); + $cmd = t3lib_div::imageMagickCommand('identify', $this->wrapFileName($imagefile) . $frame); $returnVal = array(); exec($cmd, $returnVal); - $splitstring=$returnVal[0]; + $splitstring = $returnVal[0]; - $this->IM_commands[] = Array ('identify',$cmd,$returnVal[0]); + $this->IM_commands[] = array('identify', $cmd, $returnVal[0]); - if ($splitstring) { + if ($splitstring) { - preg_match('/([^\.]*)$/',$imagefile,$reg); + preg_match('/([^\.]*)$/', $imagefile, $reg); $splitinfo = explode(' ', $splitstring); foreach ($splitinfo as $key => $val) { $temp = ''; - if ($val) {$temp = explode('x', $val);} + if ($val) { + $temp = explode('x', $val); + } - if (intval($temp[0]) && intval($temp[1])) { + if (intval($temp[0]) && intval($temp[1])) { - $dim=$temp; + $dim = $temp; break; } } - if ($dim[0] && $dim[1]) { + if ($dim[0] && $dim[1]) { - return Array($dim[0], $dim[1], strtolower($reg[0]), $imagefile); + return array($dim[0], $dim[1], strtolower($reg[0]), $imagefile); } } } @@ -2720,10 +2633,10 @@ } $cmd = t3lib_div::imageMagickCommand('convert', $params . ' ' . $this->wrapFileName($input) . $frame . ' ' . $this->wrapFileName($output)); - $this->IM_commands[] = array($output,$cmd); + $this->IM_commands[] = array($output, $cmd); $ret = exec($cmd); - t3lib_div::fixPermissions($output); // Change the permissions of the file + t3lib_div::fixPermissions($output); // Change the permissions of the file return $ret; } @@ -2740,23 +2653,23 @@ * @param [type] $handleNegation: ... * @return void */ - function combineExec($input,$overlay,$mask,$output, $handleNegation = false) { + function combineExec($input, $overlay, $mask, $output, $handleNegation = FALSE) { - if (!$this->NO_IMAGE_MAGICK) { + if (!$this->NO_IMAGE_MAGICK) { $params = '-colorspace GRAY +matte'; - if ($handleNegation) { + if ($handleNegation) { - if ($this->maskNegate) { + if ($this->maskNegate) { - $params .= ' '.$this->maskNegate; + $params .= ' ' . $this->maskNegate; } } - $theMask = $this->randomName().'.'.$this->gifExtension; + $theMask = $this->randomName() . '.' . $this->gifExtension; $this->imageMagickExec($mask, $theMask, $params); - $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 + $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 - $this->IM_commands[] = Array ($output,$cmd); + $this->IM_commands[] = array($output, $cmd); $ret = exec($cmd); - t3lib_div::fixPermissions($output); // Change the permissions of the file + t3lib_div::fixPermissions($output); // Change the permissions of the file - if (is_file($theMask)) { + if (is_file($theMask)) { @unlink($theMask); } @@ -2776,27 +2689,6 @@ } - - - - - - - - - - - - - - - - - - - - - /*********************************** * * Various IO functions @@ -2809,8 +2701,8 @@ * @param string Input file to check * @return string Returns the filename if the file existed, otherwise empty. */ - function checkFile($file) { + function checkFile($file) { - if (@is_file($file)) { + if (@is_file($file)) { return $file; } else { return ''; @@ -2823,18 +2715,18 @@ * @param string Name of sub directory * @return boolean Result of t3lib_div::mkdir(), true if it went well. */ - function createTempSubDir($dirName) { + function createTempSubDir($dirName) { // Checking if the this->tempPath is already prefixed with PATH_site and if not, prefix it with that constant. - if (t3lib_div::isFirstPartOfStr($this->tempPath,PATH_site)) { + if (t3lib_div::isFirstPartOfStr($this->tempPath, PATH_site)) { $tmpPath = $this->tempPath; } else { - $tmpPath = PATH_site.$this->tempPath; + $tmpPath = PATH_site . $this->tempPath; } // Making the temporary filename: - if (!@is_dir($tmpPath.$dirName)) { + if (!@is_dir($tmpPath . $dirName)) { - return t3lib_div::mkdir($tmpPath.$dirName); + return t3lib_div::mkdir($tmpPath . $dirName); } } @@ -2845,19 +2737,19 @@ * @param string The ImageMagick parameters. Like effects, scaling etc. * @return void */ - function applyImageMagickToPHPGif(&$im, $command) { + function applyImageMagickToPHPGif(&$im, $command) { $tmpStr = $this->randomName(); - $theFile = $tmpStr.'.'.$this->gifExtension; + $theFile = $tmpStr . '.' . $this->gifExtension; $this->ImageWrite($im, $theFile); - $this->imageMagickExec($theFile,$theFile,$command); + $this->imageMagickExec($theFile, $theFile, $command); $tmpImg = $this->imageCreateFromFile($theFile); - if ($tmpImg) { + if ($tmpImg) { ImageDestroy($im); $im = $tmpImg; $this->w = imagesx($im); $this->h = imagesy($im); } - if (!$this->dontUnlinkTempFiles) { + if (!$this->dontUnlinkTempFiles) { unlink($theFile); } } @@ -2871,8 +2763,8 @@ * @param integer The height of the output image. * @return string The filename, either "jpg" or "gif"/"png" (whatever $this->gifExtension is set to.) */ - function gif_or_jpg($type,$w,$h) { + function gif_or_jpg($type, $w, $h) { - if ($type=='ai' || $w*$h < $this->pixelLimitGif) { + if ($type == 'ai' || $w * $h < $this->pixelLimitGif) { return $this->gifExtension; } else { return 'jpg'; @@ -2888,36 +2780,38 @@ * @return string Returns input filename * @see tslib_gifBuilder::gifBuild() */ - function output($file) { + function output($file) { - if ($file) { + if ($file) { $reg = array(); - preg_match('/([^\.]*)$/',$file,$reg); + preg_match('/([^\.]*)$/', $file, $reg); - $ext=strtolower($reg[0]); + $ext = strtolower($reg[0]); - switch($ext) { + switch ($ext) { case 'gif': case 'png': - if ($this->ImageWrite($this->im, $file)) { + if ($this->ImageWrite($this->im, $file)) { // ImageMagick operations if ($this->setup['reduceColors'] || !$this->png_truecolor) { $reduced = $this->IMreduceColors($file, t3lib_div::intInRange($this->setup['reduceColors'], 256, $this->truecolorColors, 256)); - if ($reduced) { + if ($reduced) { @copy($reduced, $file); @unlink($reduced); } } - t3lib_div::gif_compress($file, 'IM'); // Compress with IM! (adds extra compression, LZW from ImageMagick) (Workaround for the absence of lzw-compression in GD) + t3lib_div::gif_compress($file, 'IM'); // Compress with IM! (adds extra compression, LZW from ImageMagick) (Workaround for the absence of lzw-compression in GD) } break; case 'jpg': case 'jpeg': - $quality = 0; // Use the default + $quality = 0; // Use the default - if($this->setup['quality']) { + if ($this->setup['quality']) { - $quality = t3lib_div::intInRange($this->setup['quality'],10,100); + $quality = t3lib_div::intInRange($this->setup['quality'], 10, 100); } - if ($this->ImageWrite($this->im, $file, $quality)); + if ($this->ImageWrite($this->im, $file, $quality)) { + ; + } break; } - $GLOBALS['TEMP_IMAGES_ON_PAGE'][]=$file; + $GLOBALS['TEMP_IMAGES_ON_PAGE'][] = $file; } return $file; } @@ -2928,7 +2822,7 @@ * @return void * @see tslib_gifBuilder::gifBuild() */ - function destroy() { + function destroy() { ImageDestroy($this->im); } @@ -2938,8 +2832,8 @@ * @param array Image information array, key 0/1 is width/height and key 3 is the src value * @return string Image tag for the input image information array. */ - function imgTag ($imgInfo) { + function imgTag($imgInfo) { - return ''; + return ''; } /** @@ -2951,15 +2845,15 @@ * @return boolean The output of either imageGif, imagePng or imageJpeg based on the filename to write * @see maskImageOntoImage(), scale(), output() */ - function ImageWrite($destImg, $theImage, $quality=0) { + function ImageWrite($destImg, $theImage, $quality = 0) { - imageinterlace ($destImg,0); + imageinterlace($destImg, 0); - $ext = strtolower(substr($theImage, strrpos($theImage, '.')+1)); + $ext = strtolower(substr($theImage, strrpos($theImage, '.') + 1)); $result = FALSE; - switch ($ext) { + switch ($ext) { case 'jpg': case 'jpeg': - if (function_exists('imageJpeg')) { + if (function_exists('imageJpeg')) { - if ($quality == 0) { + if ($quality == 0) { $quality = $this->jpegQuality; } $result = imageJpeg($destImg, $theImage, $quality); @@ -2967,12 +2861,12 @@ break; case 'gif': if (function_exists('imageGif')) { - imagetruecolortopalette($destImg, true, 256); + imagetruecolortopalette($destImg, TRUE, 256); $result = imageGif($destImg, $theImage); } break; case 'png': - if (function_exists('imagePng')) { + if (function_exists('imagePng')) { $result = ImagePng($destImg, $theImage); } break; @@ -2984,7 +2878,6 @@ } - /** * Writes the input GDlib image pointer to file. Now just a wrapper to ImageWrite. * @@ -2994,7 +2887,7 @@ * @see imageWrite() * @deprecated since TYPO3 4.0, this function will be removed in TYPO3 4.6. */ - function imageGif($destImg, $theImage) { + function imageGif($destImg, $theImage) { t3lib_div::logDeprecatedFunction(); return $this->imageWrite($destImg, $theImage); @@ -3008,7 +2901,7 @@ * @return pointer Image Resource pointer * @deprecated since TYPO3 4.0, this function will be removed in TYPO3 4.6. */ - function imageCreateFromGif($sourceImg) { + function imageCreateFromGif($sourceImg) { t3lib_div::logDeprecatedFunction(); return $this->imageCreateFromFile($sourceImg); @@ -3021,33 +2914,33 @@ * @param string Image filename * @return pointer Image Resource pointer */ - function imageCreateFromFile($sourceImg) { + function imageCreateFromFile($sourceImg) { $imgInf = pathinfo($sourceImg); $ext = strtolower($imgInf['extension']); - switch ($ext) { + switch ($ext) { case 'gif': - if (function_exists('imagecreatefromgif')) { + if (function_exists('imagecreatefromgif')) { return imageCreateFromGif($sourceImg); } break; case 'png': - if (function_exists('imagecreatefrompng')) { + if (function_exists('imagecreatefrompng')) { return imageCreateFromPng($sourceImg); } break; case 'jpg': case 'jpeg': - if (function_exists('imagecreatefromjpeg')) { + if (function_exists('imagecreatefromjpeg')) { return imageCreateFromJpeg($sourceImg); } break; } - // If non of the above: + // If non of the above: $i = @getimagesize($sourceImg); $im = imagecreatetruecolor($i[0], $i[1]); - $Bcolor = ImageColorAllocate($im, 128,128,128); + $Bcolor = ImageColorAllocate($im, 128, 128, 128); ImageFilledRectangle($im, 0, 0, $i[0], $i[1], $Bcolor); return $im; } @@ -3076,14 +2969,20 @@ * @param array RGB color array * @return string HEX color value */ - function hexColor($col) { + function hexColor($col) { $r = dechex($col[0]); - if (strlen($r)<2) { $r = '0'.$r; } + if (strlen($r) < 2) { + $r = '0' . $r; + } $g = dechex($col[1]); - if (strlen($g)<2) { $g = '0'.$g; } + if (strlen($g) < 2) { + $g = '0' . $g; + } $b = dechex($col[2]); - if (strlen($b)<2) { $b = '0'.$b; } + if (strlen($b) < 2) { + $b = '0' . $b; + } - return '#'.$r.$g.$b; + return '#' . $r . $g . $b; } /** @@ -3094,44 +2993,44 @@ * @param [type] $closest: ... * @return integer The index of the unified color */ - function unifyColors(&$img, $colArr, $closest = false) { + function unifyColors(&$img, $colArr, $closest = FALSE) { $retCol = -1; - if (is_array($colArr) && count($colArr) && function_exists('imagepng') && function_exists('imagecreatefrompng')) { + if (is_array($colArr) && count($colArr) && function_exists('imagepng') && function_exists('imagecreatefrompng')) { $firstCol = array_shift($colArr); $firstColArr = $this->convertColor($firstCol); - if (count($colArr)>1) { + if (count($colArr) > 1) { - $origName = $preName = $this->randomName().'.png'; + $origName = $preName = $this->randomName() . '.png'; - $postName = $this->randomName().'.png'; + $postName = $this->randomName() . '.png'; $this->imageWrite($img, $preName); $firstCol = $this->hexColor($firstColArr); - foreach ($colArr as $transparentColor) { + foreach ($colArr as $transparentColor) { $transparentColor = $this->convertColor($transparentColor); $transparentColor = $this->hexColor($transparentColor); - $cmd = '-fill "'.$firstCol.'" -opaque "'.$transparentColor.'"'; + $cmd = '-fill "' . $firstCol . '" -opaque "' . $transparentColor . '"'; $this->imageMagickExec($preName, $postName, $cmd); $preName = $postName; } $this->imageMagickExec($postName, $origName, ''); - if (@is_file($origName)) { + if (@is_file($origName)) { $tmpImg = $this->imageCreateFromFile($origName); } - } else { + } else { $tmpImg = $img; } - if ($tmpImg) { + if ($tmpImg) { $img = $tmpImg; - if ($closest) { + if ($closest) { - $retCol = ImageColorClosest ($img, $firstColArr[0], $firstColArr[1], $firstColArr[2]); + $retCol = ImageColorClosest($img, $firstColArr[0], $firstColArr[1], $firstColArr[2]); - } else { + } else { - $retCol = ImageColorExact ($img, $firstColArr[0], $firstColArr[1], $firstColArr[2]); + $retCol = ImageColorExact($img, $firstColArr[0], $firstColArr[1], $firstColArr[2]); } } // unlink files from process - if (!$this->dontUnlinkTempFiles) { + if (!$this->dontUnlinkTempFiles) { - if ($origName) { + if ($origName) { @unlink($origName); } - if ($postName) { + if ($postName) { @unlink($postName); } } @@ -3142,7 +3041,7 @@ } -if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_stdgraphic.php']) { +if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_stdgraphic.php']) { include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_stdgraphic.php']); }