14050_cleaning_t3lib_arraybrowser
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_stdgraphic.php
index 115c0e5..eb39538 100644 (file)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2007 Kasper Skaarhoj (kasperYYYY@typo3.com)
+*  (c) 1999-2010 Kasper Skårhøj (kasperYYYY@typo3.com)
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -28,9 +28,9 @@
  * Standard graphical functions
  *
  * $Id$
- * Revised for TYPO3 3.6 July/2003 by Kasper Skaarhoj
+ * Revised for TYPO3 3.6 July/2003 by Kasper Skårhøj
  *
- * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
+ * @author     Kasper Skårhøj <kasperYYYY@typo3.com>
  */
 /**
  * [CLASS/FUNCTION INDEX of SCRIPT]
  * Class contains a bunch of cool functions for manipulating graphics with GDlib/Freetype and ImageMagick
  * VERY OFTEN used with gifbuilder that extends this class and provides a TypoScript API to using these functions
  *
- * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
+ * With TYPO3 4.4 GDlib 1.x support was dropped, also an option from config_default.php:
+ * $TYPO3_CONF_VARS['GFX']['gdlib_2'] = 0,     // String/Boolean. Set this if you are using the new GDlib 2.0.1+. If you don't set this flag and still use GDlib2, you might encounter strange behaviours like black images etc. This feature might take effect only if ImageMagick is installed and working as well! You can also use the value "no_imagecopyresized_fix" - in that case it will NOT try to fix a known issue where "imagecopyresized" does not work correctly.
+ *
+ * @author     Kasper Skårhøj <kasperYYYY@typo3.com>
  * @package TYPO3
  * @subpackage t3lib
  * @see tslib_gifBuilder
@@ -157,23 +160,23 @@ class t3lib_stdGraphic    {
                // Internal configuration, set in init()
        var $combineScript = 'combine';                         // The ImageMagick filename used for combining two images. This name changed during the versions.
        var $noFramePrepended=0;                                        // If set, there is no frame pointer prepended to the filenames.
-       var $GD2=0;                                                                     // Set, if the GDlib used is version 2.
+       var $GD2 = 1;                                                           // Set, if the GDlib used is version 2. @deprecated as of TYPO3 4.4, as this variables is now always set (GDlib2 always has this method, and PHP recommends to only use imagecreatetruecolor() over imagecreate())
        var $imagecopyresized_fix=0;                            // If set, imagecopyresized will not be called directly. For GD2 (some PHP installs?)
        var $gifExtension = 'gif';                                      // This should be changed to 'png' if you want this class to read/make PNG-files instead!
        var $gdlibExtensions = '';                      // File formats supported by gdlib. This variable get's filled in "init" method
-       var $truecolor = true;                                  // Internal variable which get's used to determine wheter GDlib should use function truecolor pendants
+       var $truecolor = TRUE;                                  // Internal variable which get's used to determine wheter GDlib should use function truecolor pendants, @deprecated as of TYPO3 4.4, as this variables is now always set (GDlib2 always has this method, and PHP recommends to only use imagecreatetruecolor() over imagecreate())
        var $png_truecolor = false;                                     // Set to true if generated png's should be truecolor by default
        var $truecolorColors = 0xffffff;                        // 16777216 Colors is the maximum value for PNG, JPEG truecolor images (24-bit, 8-bit / Channel)
-       var $TTFLocaleConv = '';                                        // Used to recode input to TTF-functions for other charsets.
+       var $TTFLocaleConv = '';                                        // Used to recode input to TTF-functions for other charsets. Deprecated since TYPO3 3.6, will be removed in TYPO3 4.6
        var $enable_typo3temp_db_tracking = 0;          // If set, then all files in typo3temp will be logged in a database table. In addition to being a log of the files with original filenames, it also serves to secure that the same image is not rendered simultaneously by two different processes.
        var $imageFileExt = 'gif,jpg,jpeg,png,tif,bmp,tga,pcx,ai,pdf';  // Commalist of file extensions perceived as images by TYPO3. List should be set to 'gif,png,jpeg,jpg' if IM is not available. Lowercase and no spaces between!
        var $webImageExt = 'gif,jpg,jpeg,png';          // Commalist of web image extensions (can be shown by a webbrowser)
        var $maskNegate = '';                                           // Will be ' -negate' if ImageMagick ver 5.2+. See init();
        var $NO_IM_EFFECTS = '';
-       var $cmds = Array (
+       var $cmds = array(
                'jpg' => '',
                'jpeg' => '',
-               'gif' => '-colors 64',
+               'gif' => '',
                'png' => '-colors 64'
        );
        var $NO_IMAGE_MAGICK = '';
@@ -252,19 +255,17 @@ class t3lib_stdGraphic    {
                if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['png_truecolor'])        {
                        $this->png_truecolor = true;
                }
-               if (!$gfxConf['gdlib_2'] || !function_exists('imagecreatetruecolor'))   {
-                       $this->truecolor = false;
-               }
                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') {
+                       t3lib_div::deprecationLog('The option $TYPO3_CONF_VARS[\'GFX\'][\'im_version_5\'] is set to \'im5\'. 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.');
                }
 
-                       // When GIFBUILDER gets used in truecolor mode (GD2 required)
-               if ($this->truecolor)   {
-                       if ($this->png_truecolor)       {
-                               $this->cmds['png'] = '';        // No colors parameter if we generate truecolor images.
-                       }
-                       $this->cmds['gif'] = '';        // No colors parameter if we generate truecolor images.
+                       // When GIFBUILDER gets used in truecolor mode
+                       // No colors parameter if we generate truecolor images.
+               if ($this->png_truecolor) {
+                       $this->cmds['png'] = '';
                }
 
                        // Setting default JPG parameters:
@@ -274,10 +275,10 @@ class t3lib_stdGraphic    {
                if ($gfxConf['im_combine_filename'])    $this->combineScript=$gfxConf['im_combine_filename'];
                if ($gfxConf['im_noFramePrepended'])    $this->noFramePrepended=1;
 
-               if ($gfxConf['gdlib_2'])        {
-                       $this->GD2 = 1;
-                       $this->imagecopyresized_fix = $gfxConf['gdlib_2']==='no_imagecopyresized_fix' ? 0 : 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'])      {
                        $this->gifExtension='png';
                }
@@ -300,7 +301,6 @@ class t3lib_stdGraphic      {
                }
                if ($gfxConf['im_no_effects'])  {
                                // Boolean. This is necessary if using ImageMagick 5+.
-                               // Approved version for using effects is version 4.2.9.
                                // 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;
@@ -326,9 +326,9 @@ class t3lib_stdGraphic      {
                }
 
                if (TYPO3_MODE=='FE')   {
-                       $this->csConvObj = &$GLOBALS['TSFE']->csConvObj;
+                       $this->csConvObj = $GLOBALS['TSFE']->csConvObj;
                } elseif(is_object($GLOBALS['LANG']))   {       // BE assumed:
-                       $this->csConvObj = &$GLOBALS['LANG']->csConvObj;
+                       $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.
                        $this->csConvObj = t3lib_div::makeInstance('t3lib_cs');
                }
@@ -392,7 +392,7 @@ class t3lib_stdGraphic      {
                                $theMask = $tmpStr.'_mask.'.$this->gifExtension;
                                                // prepare overlay image
                                $cpImg = $this->imageCreateFromFile($BBimage[3]);
-                               $destImg = $this->imagecreate($w,$h);
+                               $destImg = imagecreatetruecolor($w, $h);
                                $Bcolor = ImageColorAllocate($destImg, 0,0,0);
                                ImageFilledRectangle($destImg, 0, 0, $w, $h, $Bcolor);
                                $this->copyGifOntoGif($destImg,$cpImg,$conf,$workArea);
@@ -401,7 +401,7 @@ class t3lib_stdGraphic      {
                                imageDestroy($destImg);
                                                // prepare mask image
                                $cpImg = $this->imageCreateFromFile($BBmask[3]);
-                               $destImg = $this->imagecreate($w,$h);
+                               $destImg = imagecreatetruecolor($w, $h);
                                $Bcolor = ImageColorAllocate($destImg, 0, 0, 0);
                                ImageFilledRectangle($destImg, 0, 0, $w, $h, $Bcolor);
                                $this->copyGifOntoGif($destImg,$cpImg,$conf,$workArea);
@@ -540,7 +540,7 @@ class t3lib_stdGraphic      {
         */
        function imagecopyresized(&$im, $cpImg, $Xstart, $Ystart, $cpImgCutX, $cpImgCutY, $w, $h, $w, $h)       {
                if ($this->imagecopyresized_fix)        {
-                       $im_base = $this->imagecreate(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, $cpImg, $Xstart, $Ystart, $cpImgCutX, $cpImgCutY, $w, $h, $w, $h);   // Then copy the $cpImg onto that (the actual operation!)
                        $im = $im_base; // Set pointer
@@ -616,7 +616,7 @@ class t3lib_stdGraphic      {
                                        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->ImageTTFTextWrapper($im, $conf['fontSize'], $conf['angle'], $txtPos[0], $txtPos[1], $Fcolor, $conf['fontFile'], $theText, $conf['splitRendering.']);
+                                               $this->renderTTFText($im, $conf['fontSize'], $conf['angle'], $txtPos[0], $txtPos[1], $Fcolor, $conf['fontFile'], $theText, $conf['splitRendering.'], $conf);
                                        }
                                }
                        } else {                // NICETEXT::
@@ -634,14 +634,14 @@ class t3lib_stdGraphic    {
                                $newH = ceil($sF*imagesy($im));
 
                                        // Make mask
-                               $maskImg = $this->imagecreate($newW, $newH);
+                               $maskImg = imagecreatetruecolor($newW, $newH);
                                $Bcolor = ImageColorAllocate($maskImg, 255,255,255);
                                ImageFilledRectangle($maskImg, 0, 0, $newW, $newH, $Bcolor);
                                $Fcolor = ImageColorAllocate($maskImg, 0,0,0);
                                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);
                                } else {
-                                       $this->ImageTTFTextWrapper($maskImg, $conf['fontSize'], $conf['angle'], $txtPos[0], $txtPos[1], $Fcolor, $conf['fontFile'], $theText, $conf['splitRendering.'],$sF);
+                                       $this->renderTTFText($maskImg, $conf['fontSize'], $conf['angle'], $txtPos[0], $txtPos[1], $Fcolor, $conf['fontFile'], $theText, $conf['splitRendering.'], $conf, $sF);
                                }
                                $this->ImageWrite($maskImg, $fileMask);
                                ImageDestroy($maskImg);
@@ -671,7 +671,7 @@ class t3lib_stdGraphic      {
                                $this->imageMagickExec($fileMask,$fileMask,$command);
 
                                        // Make the color-file
-                               $colorImg = $this->imagecreate($w,$h);
+                               $colorImg = imagecreatetruecolor($w, $h);
                                $Ccolor = ImageColorAllocate($colorImg, $cols[0],$cols[1],$cols[2]);
                                ImageFilledRectangle($colorImg, 0, 0, $w, $h, $Ccolor);
                                $this->ImageWrite($colorImg, $fileColor);
@@ -778,11 +778,14 @@ class t3lib_stdGraphic    {
                        $x = ($charInf[2]-$charInf[0]);
                        $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:
                        $x=0;
                        if (!$spacing && $wordSpacing)  {
                                $bits = explode(' ',$theText);
-                               while(list(,$word)=each($bits)) {
+                               foreach ($bits as $word) {
                                        $word.=' ';
                                        $wordInf = $this->ImageTTFBBoxWrapper($conf['fontSize'], $conf['angle'], $conf['fontFile'], $word, $conf['splitRendering.'],$sF);
                                        $wordW = ($wordInf[2]-$wordInf[0]);
@@ -797,19 +800,38 @@ class t3lib_stdGraphic    {
                                        $x+=$charW+(($char==' ')?$wordSpacing:$spacing);
                                }
                        }
+               } elseif (isset($conf['breakWidth']) && $conf['breakWidth'] && $this->getRenderedTextWidth($conf['text'], $conf) > $conf['breakWidth']) {
+                       $maxWidth = 0;
+                       $currentWidth = 0;
+                       $breakWidth = $conf['breakWidth'];
+                       $breakSpace = $this->getBreakSpace($conf, $theBBoxInfo);
+
+                       $wordPairs = $this->getWordPairsForLineBreak($conf['text']);
+                               // Iterate through all word pairs:
+                       foreach ($wordPairs as $index => $wordPair) {
+                               $wordWidth = $this->getRenderedTextWidth($wordPair, $conf);
+                               if ($index == 0 || $currentWidth + $wordWidth <= $breakWidth) {
+                                       $currentWidth+= $wordWidth;
+                               } else {
+                                       $maxWidth = max($maxWidth, $currentWidth);
+                                       $y+= $breakSpace;
+                                               // Restart:
+                                       $currentWidth = $wordWidth;
+                               }
+                       }
+                       $x = max($maxWidth, $currentWidth) * $sF;
                }
 
-               if ($sF>1) {
-                       $x = ceil($x/$sF);
-                       $y = ceil($y/$sF);
+               if ($sF > 1) {
+                       $x = ceil($x / $sF);
+                       $y = ceil($y / $sF);
                        if (is_array($theBBoxInfo))     {
-                               reset($theBBoxInfo);
-                               while(list($key,$val)=each($theBBoxInfo))       {
-                                       $theBBoxInfo[$key]=ceil($theBBoxInfo[$key]/$sF);
+                               foreach ($theBBoxInfo as &$value) {
+                                       $value = ceil($value / $sF);
                                }
                        }
                }
-               return array($x,$y,$theBBoxInfo);
+               return array($x, $y, $theBBoxInfo);
        }
 
        /**
@@ -886,10 +908,8 @@ class t3lib_stdGraphic     {
 
                if (!$spacing && $wordSpacing)  {
                        $bits = explode(' ',$text);
-                       reset($bits);
-                       while(list(,$word)=each($bits)) {
+                       foreach ($bits as $word) {
                                $word.=' ';
-                               $word = $word;
                                $wordInf = $this->ImageTTFBBoxWrapper($fontSize, $angle, $fontFile, $word, $splitRenderingConf ,$sF);
                                $wordW = ($wordInf[2]-$wordInf[0]);
                                $this->ImageTTFTextWrapper($im, $fontSize, $angle, $x, $y, $Fcolor, $fontFile, $word, $splitRenderingConf, $sF);
@@ -913,7 +933,7 @@ class t3lib_stdGraphic      {
         * @param       array           The TypoScript properties of the TEXT GIFBUILDER object
         * @return      integer         The new fontSize
         * @access private
-        * @author Rene Fritz <r.fritz@colorcube.de>
+        * @author René Fritz <r.fritz@colorcube.de>
         * @see tslib_gifBuilder::start()
         */
        function fontResize($conf) {
@@ -1237,6 +1257,115 @@ class t3lib_stdGraphic  {
                return $sF;
        }
 
+       /**
+        * Renders a regular text and takes care of a possible line break automatically.
+        *
+        * @param       pointer         (See argument for PHP function imageTTFtext())
+        * @param       integer         (See argument for PHP function imageTTFtext())
+        * @param       integer         (See argument for PHP function imageTTFtext())
+        * @param       integer         (See argument for PHP function imageTTFtext())
+        * @param       integer         (See argument for PHP function imageTTFtext())
+        * @param       integer         (See argument for PHP function imageTTFtext())
+        * @param       string          (See argument for PHP function imageTTFtext())
+        * @param       string          (See argument for PHP function imageTTFtext()). UTF-8 string, possibly with entities in.
+        * @param       array           Split-rendering configuration
+        * @param       integer         Scale factor
+        * @param       array           $conf: The configuration
+        * @return      void
+        */
+       protected function renderTTFText(&$im, $fontSize, $angle, $x, $y, $color, $fontFile, $string, $splitRendering, $conf, $sF = 1) {
+               if (isset($conf['breakWidth']) && $conf['breakWidth'] && $this->getRenderedTextWidth($string, $conf) > $conf['breakWidth']) {
+                       $phrase = '';
+                       $currentWidth = 0;
+
+                       $breakWidth = $conf['breakWidth'];
+                       $breakSpace = $this->getBreakSpace($conf);
+
+                       $wordPairs = $this->getWordPairsForLineBreak($string);
+                               // Iterate through all word pairs:
+                       foreach ($wordPairs as $index => $wordPair) {
+                               $wordWidth = $this->getRenderedTextWidth($wordPair, $conf);
+                               if ($index == 0 || $currentWidth + $wordWidth <= $breakWidth) {
+                                       $currentWidth+= $wordWidth;
+                                       $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;
+                                               // Restart the phrase:
+                                       $currentWidth = $wordWidth;
+                                       $phrase = $wordPair;
+                               }
+                       }
+                               // Render the remaining phrase:
+                       if ($currentWidth) {
+                               $this->ImageTTFTextWrapper($im, $fontSize, $angle, $x, $y, $color, $fontFile, $phrase, $splitRendering, $sF);
+                       }
+               } else {
+                       $this->ImageTTFTextWrapper($im, $fontSize, $angle, $x, $y, $color, $fontFile, $string, $splitRendering, $sF);
+               }
+       }
+
+       /**
+        * Gets the word pairs used for automatic line breaks.
+        *
+        * @param       string          $string
+        * @return      array
+        */
+       protected function getWordPairsForLineBreak($string) {
+               $wordPairs = array();
+
+               $wordsArray = preg_split('#([- .,!:]+)#', $string, -1,  PREG_SPLIT_DELIM_CAPTURE);
+               $wordsCount = count($wordsArray);
+               for ($index=0; $index < $wordsCount; $index+= 2) {
+                       $wordPairs[] = $wordsArray[$index] . $wordsArray[$index + 1];
+               }
+
+               return $wordPairs;
+       }
+
+       /**
+        * Gets the rendered text width.
+        *
+        * @param       string          $text
+        * @param       array           $conf
+        * @param       integer
+        */
+       protected function getRenderedTextWidth($text, $conf) {
+               $bounds = $this->ImageTTFBBoxWrapper($conf['fontSize'], $conf['angle'], $conf['fontFile'], $this->recodeString($text), $conf['splitRendering.']);
+               if ($conf['angle']< 0) {
+                       $pixelWidth = abs($bounds[4]-$bounds[0]);
+               } elseif ($conf['angle'] > 0) {
+                       $pixelWidth = abs($bounds[2]-$bounds[6]);
+               } else {
+                       $pixelWidth = abs($bounds[4]-$bounds[6]);
+               }
+               return $pixelWidth;
+       }
+
+       /**
+        * Gets the break space for each new line.
+        *
+        * @param       array           $conf: TypoScript configuration for the currently rendered object
+        * @param       array           $boundingBox: The bounding box the the currently rendered object
+        * @return      integer         The break space
+        */
+       protected function getBreakSpace($conf, array $boundingBox = NULL) {
+               if (!isset($boundingBox)) {
+                       $boundingBox = $this->calcBBox($conf);
+                       $boundingBox = $boundingBox[2];
+               }
+
+               if (isset($conf['breakSpace']) && $conf['breakSpace']) {
+                       $breakSpace = $boundingBox['lineHeight'] * $conf['breakSpace'];
+               } else {
+                       $breakSpace = $boundingBox['lineHeight'];
+               }
+
+               return $breakSpace;
+       }
+
 
 
 
@@ -1355,7 +1484,7 @@ class t3lib_stdGraphic    {
                        $fileMask = $tmpStr.'_mask.'.$this->gifExtension;
 
                                // BlurColor Image laves
-                       $blurColImg = $this->imagecreate($w,$h);
+                       $blurColImg = imagecreatetruecolor($w, $h);
                        $bcols=$this->convertColor($conf['color']);
                        $Bcolor = ImageColorAllocate($blurColImg, $bcols[0],$bcols[1],$bcols[2]);
                        ImageFilledRectangle($blurColImg, 0, 0, $w, $h, $Bcolor);
@@ -1363,7 +1492,7 @@ class t3lib_stdGraphic    {
                        ImageDestroy($blurColImg);
 
                                // The mask is made: BlurTextImage
-                       $blurTextImg = $this->imagecreate($w+$blurBorder*2,$h+$blurBorder*2);
+                       $blurTextImg = imagecreatetruecolor($w + $blurBorder * 2, $h + $blurBorder * 2);
                        $Bcolor = ImageColorAllocate($blurTextImg, 0,0,0);              // black background
                        ImageFilledRectangle($blurTextImg, 0, 0, $w+$blurBorder*2, $h+$blurBorder*2, $Bcolor);
                        $txtConf['fontColor'] = 'white';
@@ -1394,7 +1523,7 @@ class t3lib_stdGraphic    {
                        if ($blurTextImg_tmp)   {       // if nothing went wrong we continue with the blurred mask
 
                                        // cropping the border from the mask
-                               $blurTextImg = $this->imagecreate($w,$h);
+                               $blurTextImg = imagecreatetruecolor($w, $h);
                                $this->imagecopyresized($blurTextImg, $blurTextImg_tmp, 0, 0, $blurBorder, $blurBorder, $w, $h, $w, $h);
                                ImageDestroy($blurTextImg_tmp); // Destroy the temporary mask
 
@@ -1479,11 +1608,55 @@ class t3lib_stdGraphic  {
                        $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"
                }
-               $tmpColor = ImageColorAllocate($im, $cols[0],$cols[1],$cols[2]);
+
+               $opacity = 0;
+               if (isset($conf['opacity'])) {
+                               // conversion:
+                               // PHP 0 = opaque, 127 = transparent
+                               // TYPO3 100 = opaque, 0 = transparent
+                       $opacity = t3lib_div::intInRange(intval($conf['opacity']), 1, 100, 1);
+                       $opacity = abs($opacity - 100);
+                       $opacity = round((127 * $opacity) / 100);
+               }
+
+               $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);
        }
 
        /**
+        * Implements the "Ellipse" GIFBUILDER object
+        * Example Typoscript:
+        * file  =  GIFBUILDER
+        * file  {
+        * XY  =  200,200
+        * format  =  jpg
+        * quality  =  100
+        * 10  =  ELLIPSE
+        * 10.dimensions  =  100,100,50,50
+        * 10.color  =  red
+        *
+        * $workArea = X,Y
+        * $conf['dimensions'] = offset x, offset y, width of ellipse, height of ellipse
+        *
+        * @param       pointer GDlib image pointer
+        * @param       array $conf TypoScript array with configuration for the GIFBUILDER object.
+        * @param       array $workArea The current working area coordinates.
+        * @return      void
+        * @see tslib_gifBuilder::make()
+        */
+       public function makeEllipse(&$im, array $conf, array $workArea) {
+               $ellipseConfiguration = t3lib_div::intExplode(',', $conf['dimensions'] . ',,,');
+               $conf['offset'] = $ellipseConfiguration[0] . ',' . $ellipseConfiguration[1]; // ellipse offset inside workArea (x/y)
+
+               // @see objPosition
+               $imageCoordinates = $this->objPosition($conf, $workArea, array($ellipseConfiguration[2], $ellipseConfiguration[3]));
+
+               $color = $this->convertColor($conf['color']);
+               $fillingColor = imagecolorallocate($im, $color[0], $color[1], $color[2]);
+               imagefilledellipse($im, $imageCoordinates[0], $imageCoordinates[1], $imageCoordinates[2], $imageCoordinates[3], $fillingColor);
+       }
+
+       /**
         * Implements the "EFFECT" GIFBUILDER object
         * The operation involves ImageMagick for applying effects
         *
@@ -1511,7 +1684,7 @@ class t3lib_stdGraphic    {
                if (!trim($setup)){return '';}
                $effects = explode('|', $setup);
                $commands = '';
-               while(list(,$val)=each($effects))       {
+               foreach ($effects as $val) {
                        $pairs=explode('=',$val,2);
                        $value = trim($pairs[1]);
                        $effect = strtolower(trim($pairs[0]));
@@ -1594,7 +1767,7 @@ class t3lib_stdGraphic    {
                $setup = $conf['value'];
                if (!trim($setup)){return '';}
                $effects = explode('|', $setup);
-               while(list(,$val)=each($effects))       {
+               foreach ($effects as $val) {
                        $pairs=explode('=',$val,2);
                        $value = trim($pairs[1]);
                        $effect = strtolower(trim($pairs[0]));
@@ -1628,7 +1801,7 @@ class t3lib_stdGraphic    {
                $conf['offset']=$cords[0].','.$cords[1];
                $cords = $this->objPosition($conf,$this->workArea,Array($cords[2],$cords[3]));
 
-               $newIm = $this->imagecreate($cords[2],$cords[3]);
+               $newIm = imagecreatetruecolor($cords[2], $cords[3]);
                $cols=$this->convertColor($conf['backColor']?$conf['backColor']:$this->setup['backColor']);
                $Bcolor = ImageColorAllocate($newIm, $cols[0],$cols[1],$cols[2]);
                ImageFilledRectangle($newIm, 0, 0, $cords[2], $cords[3], $Bcolor);
@@ -1814,14 +1987,18 @@ class t3lib_stdGraphic  {
 
        /**
         * Reduce colors in image dependend on the actual amount of colors (Only works if we are not in truecolor mode)
+        * This function is not needed anymore, as truecolor is now always on.
         *
         * @param       integer         GDlib Image Pointer
         * @param       integer         The max number of colors in the image before a reduction will happen; basically this means that IF the GD image current has the same amount or more colors than $limit define, THEN a reduction is performed.
         * @param       integer         Number of colors to reduce the image to.
         * @return      void
+        * @deprecated since TYPO3 4.4, this function will be removed in TYPO3 4.6.
         */
        function reduceColors(&$im,$limit, $cols)       {
-               if (!$this->truecolor && ImageColorsTotal($im)>=$limit) {
+               t3lib_div::logDeprecatedFunction();
+
+               if (!$this->truecolor && ImageColorsTotal($im)>=$limit) {
                        $this->makeEffect($im, Array('value'=>'colors='.$cols) );
                }
        }
@@ -1959,12 +2136,12 @@ class t3lib_stdGraphic  {
                        // Finding the RGB definitions of the color:
                $string=$cParts[0];
                if (strstr($string,'#'))        {
-                       $string = ereg_replace('[^A-Fa-f0-9]*','',$string);
+                       $string = preg_replace('/[^A-Fa-f0-9]*/','',$string);
                        $col[]=HexDec(substr($string,0,2));
                        $col[]=HexDec(substr($string,2,2));
                        $col[]=HexDec(substr($string,4,2));
                } elseif (strstr($string,','))  {
-                       $string = ereg_replace('[^,0-9]*','',$string);
+                       $string = preg_replace('/[^,0-9]*/','',$string);
                        $strArr = explode(',',$string);
                        $col[]=intval($strArr[0]);
                        $col[]=intval($strArr[1]);
@@ -2009,8 +2186,11 @@ class t3lib_stdGraphic   {
                }
 
                        // Recode string accoding to TTFLocaleConv. Deprecated.
-               if ($this->TTFLocaleConv)       {
-                       $string = recode_string($this->TTFLocaleConv,$string);
+               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);
+                       $string = $this->csConvObj->conv($string, $from, $to);
                }
 
                return $string;
@@ -2154,29 +2334,48 @@ class t3lib_stdGraphic  {
                                $w=$data['origW'];
                                $h=$data['origH'];
 
-                                       // if no convertion should be performed
-                               $wh_noscale = (!$w && !$h) || ($data[0]==$info[0] && $data[1]==$info[1]);               // this flag is true if the width / height does NOT dictate the image to be scaled!! (that is if no w/h is given or if the destination w/h matches the original image-dimensions....
-
-                               if ($wh_noscale && !$data['crs'] && !$params && !$frame && $newExt==$info[2] && !$mustCreate) {
+                                       // if no conversion should be performed
+                                       // 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, 
+                                               // if the noScale option is set
+                                       if ($options['noScale']) {
+                                               $info[0] = $data[0];
+                                               $info[1] = $data[1];
+                                       }
                                        $info[3] = $imagefile;
                                        return $info;
                                }
                                $info[0]=$data[0];
                                $info[1]=$data[1];
 
-                               $frame = $this->noFramePrepended ? '' : '['.intval($frame).']';
+                               $frame = $this->noFramePrepended ? '' : intval($frame);
 
                                if (!$params)   {
                                        $params = $this->cmds[$newExt];
                                }
 
+                                       // Cropscaling:
+                               if ($data['crs']) {
+                                       if (!$data['origW']) { $data['origW'] = $data[0]; }
+                                       if (!$data['origH']) { $data['origH'] = $data[1]; }
+                                       $offsetX = intval(($data[0] - $data['origW']) * ($data['cropH']+100)/200);
+                                       $offsetY = intval(($data[1] - $data['origH']) * ($data['cropV']+100)/200);
+                                       $params .= ' -crop '.$data['origW'].'x'.$data['origH'].'+'.$offsetX.'+'.$offsetY.' ';
+                               }
+
                                $command = $this->scalecmd.' '.$info[0].'x'.$info[1].'! '.$params.' ';
                                $cropscale = ($data['crs'] ? 'crs-V'.$data['cropV'].'H'.$data['cropH'] : '');
 
                                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)        {
                                        $theOutputName = $this->imageMagickConvert_forceFileNameBody;
@@ -2190,35 +2389,10 @@ class t3lib_stdGraphic  {
                                        // Register temporary filename:
                                $GLOBALS['TEMP_IMAGES_ON_PAGE'][] = $output;
 
-                                       // Cropscaling:
-                               if ($data['crs'])       {
-                                       if ($this->dontCheckForExistingTempFile || !$this->file_exists_typo3temp_file($output, $imagefile))     {
-                                               $crsOutput = str_replace('pics/', 'pics/crs-', $output);
-                                               $this->imageMagickExec($imagefile.$frame, $crsOutput, $command);
-                                               $gifCreator = t3lib_div::makeInstance('tslib_gifbuilder');
-                                               $gifCreator->init();
-                                               if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib'] !== 0)  {
-                                                       if (!$data['origW']) { $data['origW'] = $data[0]; }
-                                                       if (!$data['origH']) { $data['origH'] = $data[1]; }
-                                                       $ofX = intval(($data['origW'] - $data[0]) * ($data['cropH']+100)/200);
-                                                       $ofY = intval(($data['origH'] - $data[1]) * ($data['cropV']+100)/200);
-                                                       $tmpParm = Array('XY' => intval($data['origW']).','.intval($data['origH']),
-                                                                       '10' => 'IMAGE',
-                                                                       '10.' => array('file'=> $crsOutput, 'offset'=> $ofX.','.$ofY),
-                                                       );
-                                                       $gifCreator->start($tmpParm, array());
-                                                       $newoutput = $gifCreator->gifBuild();
-                                                       if (!copy($newoutput,$output)) {
-                                                               $output = $newoutput;
-                                                       }
-                                               } else {
-                                                       $output = $crsOutput;
-                                               }
-                                       }
-                               } elseif ($this->dontCheckForExistingTempFile || !$this->file_exists_typo3temp_file($output,$imagefile)) {
-                                       $this->imageMagickExec($imagefile.$frame,$output,$command);
+                               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!
@@ -2241,8 +2415,8 @@ class t3lib_stdGraphic    {
         * @see imageMagickConvert(), tslib_cObj::getImgResource()
         */
        function getImageDimensions($imageFile) {
-               ereg('([^\.]*)$',$imageFile,$reg);
-               if (@file_exists($imageFile) && t3lib_div::inList($this->imageFileExt,strtolower($reg[0])))     {
+               preg_match('/([^\.]*)$/',$imageFile,$reg);
+               if (file_exists($imageFile) && t3lib_div::inList($this->imageFileExt,strtolower($reg[0])))      {
                        if ($returnArr = $this->getCachedImageDimensions($imageFile))   {
                                return $returnArr;
                        } else {
@@ -2276,7 +2450,7 @@ class t3lib_stdGraphic    {
                        $fieldArr = array (
                                'md5hash' => $md5Hash,
                                'md5filename' => md5($identifyResult[3]),
-                               'tstamp' => time(),
+                               'tstamp' => $GLOBALS['EXEC_TIME'],
                                'filename' => $identifyResult[3],
                                'imagewidth' => $identifyResult[0],
                                'imageheight' => $identifyResult[1],
@@ -2300,7 +2474,7 @@ class t3lib_stdGraphic    {
                global $TYPO3_DB;
                        // Create a md5 hash of the filename
                $md5Hash = md5_file($imageFile);
-               ereg('([^\.]*)$',$imageFile,$reg);
+               preg_match('/([^\.]*)$/',$imageFile,$reg);
                $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)) {
@@ -2308,7 +2482,7 @@ class t3lib_stdGraphic    {
                                                // file has changed, delete the row
                                        $TYPO3_DB->exec_DELETEquery ('cache_imagesizes', 'md5hash='.$TYPO3_DB->fullQuoteStr($row['md5hash'],'cache_imagesizes'));
                                } else {
-                                       return (array($row['imagewidth'], $row['imageheight'], strtolower($reg[0]), $imageFile));
+                                       return (array((int) $row['imagewidth'], (int) $row['imageheight'], strtolower($reg[0]), $imageFile));
                                }
                        }
                }
@@ -2434,11 +2608,15 @@ class t3lib_stdGraphic  {
         */
        function file_exists_typo3temp_file($output,$orig='')   {
                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.
                                $md5Hash=md5($output);
-                               $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('md5hash', 'cache_typo3temp_log', 'md5hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr($md5Hash, 'cache_typo3temp_log').' AND tstamp>'.(time()-30));
+                               $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 (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);
@@ -2447,7 +2625,7 @@ class t3lib_stdGraphic    {
 
                                        $insertFields = array(
                                                'md5hash' => $md5Hash,
-                                               'tstamp' => time(),
+                                               'tstamp' => $GLOBALS['EXEC_TIME'],
                                                'filename' => $output,
                                                'orig_filename' => $orig
                                        );
@@ -2459,7 +2637,7 @@ class t3lib_stdGraphic    {
                                }
                        }
                } else {
-                       return @file_exists($output);
+                       return file_exists($output);
                }
        }
 
@@ -2502,9 +2680,9 @@ class t3lib_stdGraphic    {
                        $splitstring=$returnVal[0];
                        $this->IM_commands[] = Array ('identify',$cmd,$returnVal[0]);
                        if ($splitstring)       {
-                               ereg('([^\.]*)$',$imagefile,$reg);
+                               preg_match('/([^\.]*)$/',$imagefile,$reg);
                                $splitinfo = explode(' ', $splitstring);
-                               while (list($key,$val) = each($splitinfo))      {
+                               foreach ($splitinfo as $key => $val) {
                                        $temp = '';
                                        if ($val) {$temp = explode('x', $val);}
                                        if (intval($temp[0]) && intval($temp[1]))       {
@@ -2526,15 +2704,26 @@ class t3lib_stdGraphic  {
         * @param       string          The relative (to PATH_site) image filepath, input file (read from)
         * @param       string          The relative (to PATH_site) image filepath, output filename (written to)
         * @param       string          ImageMagick parameters
+        * @param       integer         Optional, refers to which frame-number to select in the image. '' or 0
+        *                              will select the first frame, 1 will select the next and so on...
         * @return      string          The result of a call to PHP function "exec()"
         */
-       function imageMagickExec($input,$output,$params)        {
-               if (!$this->NO_IMAGE_MAGICK)    {
-                       $cmd = t3lib_div::imageMagickCommand('convert', $params.' '.$this->wrapFileName($input).' '.$this->wrapFileName($output));
+       function imageMagickExec($input, $output, $params, $frame = 0) {
+               if (!$this->NO_IMAGE_MAGICK) {
+
+                               // Unless noFramePrepended is set in the Install Tool, a frame number is added to
+                               // select a specific page of the image (by default this will be the first page)
+                       if (!$this->noFramePrepended) {
+                               $frame = '[' . intval($frame) . ']';
+                       } else {
+                               $frame = '';
+                       }
+
+                       $cmd = t3lib_div::imageMagickCommand('convert', $params . ' ' . $this->wrapFileName($input) . $frame . ' ' . $this->wrapFileName($output));
                        $this->IM_commands[] = array($output,$cmd);
 
                        $ret = exec($cmd);
-                       t3lib_div::fixPermissions($this->wrapFileName($output));        // Change the permissions of the file
+                       t3lib_div::fixPermissions($output);     // Change the permissions of the file
 
                        return $ret;
                }
@@ -2565,7 +2754,7 @@ class t3lib_stdGraphic    {
                        $this->IM_commands[] = Array ($output,$cmd);
 
                        $ret = exec($cmd);
-                       t3lib_div::fixPermissions($this->wrapFileName($output));        // Change the permissions of the file
+                       t3lib_div::fixPermissions($output);     // Change the permissions of the file
 
                        if (is_file($theMask))  {
                                @unlink($theMask);
@@ -2576,17 +2765,14 @@ class t3lib_stdGraphic  {
        }
 
        /**
-        * Wrapping the input filename in double-quotes
+        * Escapes a file name so it can safely be used on the command line.
         *
-        * @param       string          Input filename
-        * @return      string          The output wrapped in "" (if there are spaces in the filepath)
-        * @access private
+        * @param string $inputName filename to safeguard, must not be empty
+        *
+        * @return string $inputName escaped as needed
         */
-       function wrapFileName($inputName)       {
-               if (strstr($inputName,' '))     {
-                       $inputName='"'.$inputName.'"';
-               }
-               return $inputName;
+       protected function wrapFileName($inputName) {
+               return escapeshellarg($inputName);
        }
 
 
@@ -2705,14 +2891,14 @@ class t3lib_stdGraphic  {
        function output($file)  {
                if ($file)      {
                        $reg = array();
-                       ereg('([^\.]*)$',$file,$reg);
+                       preg_match('/([^\.]*)$/',$file,$reg);
                        $ext=strtolower($reg[0]);
                        switch($ext)    {
                                case 'gif':
                                case 'png':
                                        if ($this->ImageWrite($this->im, $file))        {
                                                        // ImageMagick operations
-                                               if ($this->setup['reduceColors'] || (!$this->png_truecolor && $this->truecolor))        {
+                                               if ($this->setup['reduceColors'] || !$this->png_truecolor) {
                                                        $reduced = $this->IMreduceColors($file, t3lib_div::intInRange($this->setup['reduceColors'], 256, $this->truecolorColors, 256));
                                                        if ($reduced)   {
                                                                @copy($reduced, $file);
@@ -2762,52 +2948,56 @@ class t3lib_stdGraphic  {
         * @param       pointer         The GDlib image resource pointer
         * @param       string          The filename to write to
         * @param       integer         The image quality (for JPEGs)
-        * @return      mixed           The output of either imageGif, imagePng or imageJpeg based on the filename to write
+        * @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)    {
                imageinterlace ($destImg,0);
-               $ext = strtolower(substr($theImage, strrpos($theImage, '.')+1));
-               switch ($ext)   {
-                       case 'jpg':
-                       case 'jpeg':
-                               if (function_exists('imageJpeg'))       {
+               $ext = strtolower(substr($theImage, strrpos($theImage, '.')+1));
+               $result = FALSE;
+               switch ($ext)   {
+                       case 'jpg':
+                       case 'jpeg':
+                               if (function_exists('imageJpeg'))       {
                                        if ($quality == 0)      {
                                                $quality = $this->jpegQuality;
                                        }
-                                       return imageJpeg($destImg, $theImage, $quality);
-                               }
-                       break;
-                       case 'gif':
-                               if (function_exists('imageGif'))        {
-                                       if ($this->truecolor)   {
-                                               imagetruecolortopalette($destImg, true, 256);
-                                       }
-                                       return imageGif($destImg, $theImage);
-                               }
-                       break;
-                       case 'png':
-                               if (function_exists('imagePng'))        {
-                                       return ImagePng($destImg, $theImage);
-                               }
-                       break;
-               }
-               return false;           // Extension invalid or write-function does not exist
-       }
-
-
-
-       /**
- * Writes the input GDlib image pointer to file. Now just a wrapper to ImageWrite.
- *
- * @param      pointer         The GDlib image resource pointer
- * @param      string          The filename to write to
- * @return     mixed           The output of either imageGif, imagePng or imageJpeg based on the filename to write
- * @see imageWrite()
- * @deprecated
- */
-       function imageGif($destImg, $theImage)  {
-               return $this->imageWrite($destImg, $theImage);
+                                       $result = imageJpeg($destImg, $theImage, $quality);
+                               }
+                       break;
+                       case 'gif':
+                               if (function_exists('imageGif')) {
+                                       imagetruecolortopalette($destImg, true, 256);
+                                       $result = imageGif($destImg, $theImage);
+                               }
+                       break;
+                       case 'png':
+                               if (function_exists('imagePng'))        {
+                                       $result = ImagePng($destImg, $theImage);
+                               }
+                       break;
+               }
+               if ($result) {
+                       t3lib_div::fixPermissions($theImage);
+               }
+               return $result;
+       }
+
+
+
+       /**
+        * Writes the input GDlib image pointer to file. Now just a wrapper to ImageWrite.
+        *
+        * @param       pointer         The GDlib image resource pointer
+        * @param       string          The filename to write to
+        * @return      mixed           The output of either imageGif, imagePng or imageJpeg based on the filename to write
+        * @see imageWrite()
+        * @deprecated since TYPO3 4.0, this function will be removed in TYPO3 4.6.
+        */
+       function imageGif($destImg, $theImage)  {
+               t3lib_div::logDeprecatedFunction();
+
+               return $this->imageWrite($destImg, $theImage);
        }
 
        /**
@@ -2816,9 +3006,11 @@ class t3lib_stdGraphic   {
         *
         * @param       string          Image filename
         * @return      pointer         Image Resource pointer
-        * @deprecated
+        * @deprecated since TYPO3 4.0, this function will be removed in TYPO3 4.6.
         */
        function imageCreateFromGif($sourceImg) {
+               t3lib_div::logDeprecatedFunction();
+
                return $this->imageCreateFromFile($sourceImg);
        }
 
@@ -2854,7 +3046,7 @@ class t3lib_stdGraphic    {
 
                // If non of the above:
                $i = @getimagesize($sourceImg);
-               $im = $this->imagecreate($i[0],$i[1]);
+               $im = imagecreatetruecolor($i[0], $i[1]);
                $Bcolor = ImageColorAllocate($im, 128,128,128);
                ImageFilledRectangle($im, 0, 0, $i[0], $i[1], $Bcolor);
                return $im;
@@ -2862,19 +3054,20 @@ class t3lib_stdGraphic  {
 
 
        /**
-        * Creates a new GD image resource. Wrapper for imagecreate(truecolor) depended if GD2 is used.
+        * Creates a new GD image resource.
+        * Wrapper for imagecreate(truecolor) depended if GD2 is used.
+        * This function however got obsolete, as PHP now recommends to use
+        * imagecreatetruecolor() only.
         *
         * @param       integer         Width of image
         * @param       integer         Height of image
         * @return      pointer         Image Resource pointer
+        * @deprecated since TYPO3 4.4, this function will be removed in TYPO3 4.6.
         */
-       function imagecreate($w, $h)    {
-               if($this->truecolor && function_exists('imagecreatetruecolor')) {
-                       return imagecreatetruecolor($w, $h);
-               } else  {
-                       return imagecreate($w, $h);
-               }
+       function imagecreate($w, $h) {
+               t3lib_div::logDeprecatedFunction();
 
+               return imagecreatetruecolor($w, $h);
        }
 
        /**
@@ -2952,4 +3145,5 @@ class t3lib_stdGraphic    {
 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']);
 }
-?>
+
+?>
\ No newline at end of file