Fixed bug #10086: Core uses deprecated function t3lib_db->sql()
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_stdgraphic.php
index f57ccae..c81b4b9 100644 (file)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2006 Kasper Skaarhoj (kasperYYYY@typo3.com)
+*  (c) 1999-2008 Kasper Skaarhoj (kasperYYYY@typo3.com)
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -219,7 +219,11 @@ class t3lib_stdGraphic     {
                'white' => Array(255,255,255)
        );
 
-               // Charset conversion object:
+       /**
+        * Charset conversion object:
+        *
+        * @var t3lib_cs
+        */
        var $csConvObj;
        var $nativeCharset='';          // Is set to the native character set of the input strings.
 
@@ -303,7 +307,7 @@ class t3lib_stdGraphic      {
 
                        $this->cmds['jpg'] = $this->cmds['jpeg'] = '-colorspace RGB -quality '.$this->jpegQuality;
                }
-                       // ... but if 'im_v5effects' is set, dont care about 'im_no_effects'
+                       // ... but if 'im_v5effects' is set, don't care about 'im_no_effects'
                if ($gfxConf['im_v5effects'])   {
                        $this->NO_IM_EFFECTS = 0;
                        $this->V5_EFFECTS = 1;
@@ -2006,7 +2010,8 @@ class t3lib_stdGraphic    {
 
                        // Recode string accoding to TTFLocaleConv. Deprecated.
                if ($this->TTFLocaleConv)       {
-                       $string = recode_string($this->TTFLocaleConv,$string);
+                       list($from, $to) = t3lib_div::trimExplode('..', $this->TTFLocaleConv, true);
+                       $string = $this->csConvObj->conv($string, $from, $to);
                }
 
                return $string;
@@ -2014,7 +2019,7 @@ class t3lib_stdGraphic    {
 
        /**
         * Split a string into an array of individual characters
-        * The function will look at  $this->nativeCharset and if that is set, the input string is expected to be UTF-8 encoded, possibly with entities in it. Otherwise the string is supposed to be a single-byte charset which is just splitted by a for-loop.
+        * The function will look at $this->nativeCharset and if that is set, the input string is expected to be UTF-8 encoded, possibly with entities in it. Otherwise the string is supposed to be a single-byte charset which is just splitted by a for-loop.
         *
         * @param       string          The text string to split
         * @param       boolean         Return Unicode numbers instead of chars.
@@ -2153,7 +2158,7 @@ class t3lib_stdGraphic    {
                                        // 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 && !$params && !$frame && $newExt==$info[2] && !$mustCreate) {
+                               if ($wh_noscale && !$data['crs'] && !$params && !$frame && $newExt==$info[2] && !$mustCreate) {
                                        $info[3] = $imagefile;
                                        return $info;
                                }
@@ -2166,6 +2171,15 @@ class t3lib_stdGraphic   {
                                        $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'] : '');
 
@@ -2186,34 +2200,10 @@ class t3lib_stdGraphic  {
                                        // Register temporary filename:
                                $GLOBALS['TEMP_IMAGES_ON_PAGE'][] = $output;
 
-                               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.$frame, $output, $command);
                                }
-                               if (@file_exists($output))      {
+                               if (file_exists($output))       {
                                        $info[3] = $output;
                                        $info[2] = $newExt;
                                        if ($params)    {       // params could realisticly change some imagedata!
@@ -2237,7 +2227,7 @@ class t3lib_stdGraphic    {
         */
        function getImageDimensions($imageFile) {
                ereg('([^\.]*)$',$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))   {
                                return $returnArr;
                        } else {
@@ -2266,11 +2256,7 @@ class t3lib_stdGraphic   {
        function cacheImageDimensions($identifyResult)  {
                global $TYPO3_DB;
                        // Create a md5 hash of the filename
-               if (function_exists('md5_file')) {
-                       $md5Hash = md5_file($identifyResult[3]);
-               } else {
-                       $md5Hash = md5 (t3lib_div::getURL($identifyResult[3]));
-               }
+               $md5Hash = md5_file($identifyResult[3]);
                if ($md5Hash) {
                        $fieldArr = array (
                                'md5hash' => $md5Hash,
@@ -2298,11 +2284,7 @@ class t3lib_stdGraphic   {
        function getCachedImageDimensions($imageFile)   {
                global $TYPO3_DB;
                        // Create a md5 hash of the filename
-               if(function_exists('md5_file')) {
-                       $md5Hash = md5_file($imageFile);
-               } else {
-                       $md5Hash = md5(t3lib_div::getURL ($imageFile));
-               }
+               $md5Hash = md5_file($imageFile);
                ereg('([^\.]*)$',$imageFile,$reg);
                $res = $TYPO3_DB->exec_SELECTquery ('md5hash, imagewidth, imageheight', 'cache_imagesizes', 'md5filename='.$TYPO3_DB->fullQuoteStr(md5($imageFile),'cache_imagesizes'));
                if ($res) {
@@ -2437,7 +2419,7 @@ 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);
@@ -2462,7 +2444,7 @@ class t3lib_stdGraphic    {
                                }
                        }
                } else {
-                       return @file_exists($output);
+                       return file_exists($output);
                }
        }
 
@@ -2764,49 +2746,53 @@ 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
         * @see maskImageOntoImage(), scale(), output()
         */
-       function ImageWrite($destImg, $theImage)        {
+       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'))       {
-                                       return imageJpeg($destImg, $theImage, $this->jpegQuality);
-                               }
-                       break;
-                       case 'gif':
-                               if (function_exists('imageGif'))        {
+               $ext = strtolower(substr($theImage, strrpos($theImage, '.')+1));
+               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);
+                                       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 since TYPO3 4.0
       */
+       function imageGif($destImg, $theImage)  {
+               return $this->imageWrite($destImg, $theImage);
        }
 
        /**
@@ -2815,7 +2801,7 @@ class t3lib_stdGraphic    {
         *
         * @param       string          Image filename
         * @return      pointer         Image Resource pointer
-        * @deprecated
+        * @deprecated since TYPO3 4.0
         */
        function imageCreateFromGif($sourceImg) {
                return $this->imageCreateFromFile($sourceImg);
@@ -2951,4 +2937,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