Fixed bug #14117: RuntimeException thrown within the exception handler when wrong...
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_stdgraphic.php
index 8104d89..eb248e6 100644 (file)
@@ -2307,7 +2307,7 @@ class t3lib_stdGraphic    {
                                $info[0]=$data[0];
                                $info[1]=$data[1];
 
-                               $frame = $this->noFramePrepended ? '' : '['.intval($frame).']';
+                               $frame = $this->noFramePrepended ? '' : intval($frame);
 
                                if (!$params)   {
                                        $params = $this->cmds[$newExt];
@@ -2326,9 +2326,9 @@ class t3lib_stdGraphic    {
                                $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;
@@ -2343,7 +2343,7 @@ class t3lib_stdGraphic    {
                                $GLOBALS['TEMP_IMAGES_ON_PAGE'][] = $output;
 
                                if ($this->dontCheckForExistingTempFile || !$this->file_exists_typo3temp_file($output, $imagefile))     {
-                                       $this->imageMagickExec($imagefile.$frame, $output, $command);
+                                       $this->imageMagickExec($imagefile, $output, $command, $frame);
                                }
                                if (file_exists($output))       {
                                        $info[3] = $output;
@@ -2435,7 +2435,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));
                                }
                        }
                }
@@ -2657,15 +2657,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;
                }
@@ -2696,7 +2707,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);
@@ -2707,17 +2718,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);
        }
 
 
@@ -2939,9 +2947,11 @@ class t3lib_stdGraphic   {
         * @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
+        * @deprecated since TYPO3 4.0, this function will be removed in TYPO3 4.5.
         */
        function imageGif($destImg, $theImage)  {
+               t3lib_div::logDeprecatedFunction();
+
                return $this->imageWrite($destImg, $theImage);
        }
 
@@ -2951,9 +2961,11 @@ class t3lib_stdGraphic   {
         *
         * @param       string          Image filename
         * @return      pointer         Image Resource pointer
-        * @deprecated since TYPO3 4.0
+        * @deprecated since TYPO3 4.0, this function will be removed in TYPO3 4.5.
         */
        function imageCreateFromGif($sourceImg) {
+               t3lib_div::logDeprecatedFunction();
+
                return $this->imageCreateFromFile($sourceImg);
        }