[!!!][TASK] Remove option to generate PNGs limited to 64 colors
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Imaging / GraphicalFunctions.php
index cafb884..ae0391d 100644 (file)
@@ -52,13 +52,6 @@ class GraphicalFunctions
     public $gdlibExtensions = '';
 
     /**
-     * Set to TRUE if generated png's should be truecolor by default
-     *
-     * @var bool
-     */
-    public $png_truecolor = false;
-
-    /**
      * defines the RGB colorspace to use
      *
      * @var string
@@ -133,7 +126,7 @@ class GraphicalFunctions
         'jpg' => '',
         'jpeg' => '',
         'gif' => '',
-        'png' => '-colors 64'
+        'png' => ''
     ];
 
     /**
@@ -210,13 +203,6 @@ class GraphicalFunctions
     protected $saveAlphaLayer = false;
 
     /**
-     * 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 string
-     */
-    public $tempPath = 'typo3temp/';
-
-    /**
      * Prefix for relative paths. Used in "show_item.php" script. Is prefixed the output file name IN imageMagickConvert()
      *
      * @var string
@@ -285,7 +271,7 @@ class GraphicalFunctions
     /**
      * @var int
      */
-    public $jpegQuality = 75;
+    public $jpegQuality = 85;
 
     /**
      * @var string
@@ -336,9 +322,6 @@ class GraphicalFunctions
         if (function_exists('imagecreatefromgif') && function_exists('imagegif')) {
             $this->gdlibExtensions .= ',gif';
         }
-        if ($gfxConf['png_truecolor']) {
-            $this->png_truecolor = true;
-        }
 
         if ($gfxConf['processor_colorspace'] && in_array($gfxConf['processor_colorspace'], $this->allowedColorSpaceNames, true)) {
             $this->colorspace = $gfxConf['processor_colorspace'];
@@ -347,13 +330,8 @@ class GraphicalFunctions
         if (!$gfxConf['processor_enabled']) {
             $this->NO_IMAGE_MAGICK = 1;
         }
-        // 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:
-        $this->jpegQuality = MathUtility::forceIntegerInRange($gfxConf['jpg_quality'], 10, 100, 75);
+        $this->jpegQuality = MathUtility::forceIntegerInRange($gfxConf['jpg_quality'], 10, 100, 85);
         $this->addFrameSelection = (bool)$gfxConf['processor_allowFrameSelection'];
         if ($gfxConf['gdlib_png']) {
             $this->gifExtension = 'png';
@@ -935,25 +913,23 @@ class GraphicalFunctions
             // If any kind of spacing applys, we use this function:
             if ($spacing || $wordSpacing) {
                 return $conf['fontSize'];
-            } else {
-                do {
-                    // Determine bounding box.
-                    $bounds = $this->ImageTTFBBoxWrapper($conf['fontSize'], $conf['angle'], $conf['fontFile'], $conf['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]);
-                    }
-                    // Size is fine, exit:
-                    if ($pixelWidth <= $maxWidth) {
-                        break;
-                    } else {
-                        $conf['fontSize']--;
-                    }
-                } while ($conf['fontSize'] > 1);
             }
+            do {
+                // Determine bounding box.
+                $bounds = $this->ImageTTFBBoxWrapper($conf['fontSize'], $conf['angle'], $conf['fontFile'], $conf['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]);
+                }
+                // Size is fine, exit:
+                if ($pixelWidth <= $maxWidth) {
+                    break;
+                }
+                $conf['fontSize']--;
+            } while ($conf['fontSize'] > 1);
         }
         return $conf['fontSize'];
     }
@@ -1919,20 +1895,6 @@ class GraphicalFunctions
      *
      *********************************/
     /**
-     * Checks if the $fontFile is already at an absolute path and if not, prepends the PATH_site.
-     * Call it by \TYPO3\CMS\Core\Imaging\GraphicalFunctions::prependAbsolutePath()
-     *
-     * @param string $fontFile The font file
-     * @return string The font file with absolute path.
-     * @deprecated since TYPO3 v8, will be removed in TYPO3 v9 - use GeneralUtility::getFileAbsFileName()
-     */
-    public function prependAbsolutePath($fontFile)
-    {
-        GeneralUtility::logDeprecatedFunction();
-        return GeneralUtility::isAbsPath($fontFile) ? $fontFile : PATH_site . $fontFile;
-    }
-
-    /**
      * Returns the IM command for sharpening with ImageMagick 5
      * Uses $this->im5fx_sharpenSteps for translation of the factor to an actual command.
      *
@@ -1971,15 +1933,15 @@ class GraphicalFunctions
     }
 
     /**
-     * Returns a random filename prefixed with "temp_" and then 32 char md5 hash (without extension) from $this->tempPath.
+     * Returns a random filename prefixed with "temp_" and then 32 char md5 hash (without extension).
      * Used by functions in this class to create truly temporary files for the on-the-fly processing. These files will most likely be deleted right away.
      *
      * @return string
      */
     public function randomName()
     {
-        $this->createTempSubDir('var/transient/');
-        return $this->tempPath . 'var/transient/' . md5(uniqid('', true));
+        GeneralUtility::mkdir_deep(PATH_site . 'typo3temp/var/transient/');
+        return PATH_site . 'typo3temp/var/transient/' . md5(uniqid('', true));
     }
 
     /**
@@ -2192,8 +2154,8 @@ class GraphicalFunctions
             $this->imageMagickConvert_forceFileNameBody = '';
         }
         // Making the temporary filename:
-        $this->createTempSubDir('assets/images/');
-        $output = $this->absPrefix . $this->tempPath . 'assets/images/' . $this->filenamePrefix . $theOutputName . '.' . $newExt;
+        GeneralUtility::mkdir_deep(PATH_site . 'typo3temp/assets/images/');
+        $output = $this->absPrefix . 'typo3temp/assets/images/' . $this->filenamePrefix . $theOutputName . '.' . $newExt;
         if ($this->dontCheckForExistingTempFile || !file_exists($output)) {
             $this->imageMagickExec($imagefile, $output, $command, $frame);
         }
@@ -2226,16 +2188,15 @@ class GraphicalFunctions
         if (file_exists($imageFile) && GeneralUtility::inList($this->imageFileExt, strtolower($reg[0]))) {
             if ($returnArr = $this->getCachedImageDimensions($imageFile)) {
                 return $returnArr;
+            }
+            if ($temp = @getimagesize($imageFile)) {
+                $returnArr = [$temp[0], $temp[1], strtolower($reg[0]), $imageFile];
             } else {
-                if ($temp = @getimagesize($imageFile)) {
-                    $returnArr = [$temp[0], $temp[1], strtolower($reg[0]), $imageFile];
-                } else {
-                    $returnArr = $this->imageMagickIdentify($imageFile);
-                }
-                if ($returnArr) {
-                    $this->cacheImageDimensions($returnArr);
-                    return $returnArr;
-                }
+                $returnArr = $this->imageMagickIdentify($imageFile);
+            }
+            if ($returnArr) {
+                $this->cacheImageDimensions($returnArr);
+                return $returnArr;
             }
         }
         return null;
@@ -2634,7 +2595,9 @@ class GraphicalFunctions
         }
         $newFile = PATH_site . 'typo3temp/assets/images/' . md5($theFile . '|' . filemtime($theFile)) . ($output_png ? '.png' : '.gif');
         $cmd = CommandUtility::imageMagickCommand(
-            'convert', '"' . $theFile . '" "' . $newFile . '"', $GLOBALS['TYPO3_CONF_VARS']['GFX']['processor_path']
+            'convert',
+            '"' . $theFile . '" "' . $newFile . '"',
+            $GLOBALS['TYPO3_CONF_VARS']['GFX']['processor_path']
         );
         CommandUtility::exec($cmd);
         if (@is_file($newFile)) {
@@ -2651,28 +2614,6 @@ class GraphicalFunctions
      ***********************************/
 
     /**
-     * Creates subdirectory in typo3temp/ if not already found.
-     *
-     * @param string $dirName Name of sub directory
-     * @return bool Result of \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir(), TRUE if it went well.
-     */
-    public function createTempSubDir($dirName)
-    {
-        // Checking if the this->tempPath is already prefixed with PATH_site and if not, prefix it with that constant.
-        if (GeneralUtility::isFirstPartOfStr($this->tempPath, PATH_site)) {
-            $tmpPath = $this->tempPath;
-        } else {
-            $tmpPath = PATH_site . $this->tempPath;
-        }
-        // Making the temporary filename:
-        if (!@is_dir($tmpPath . $dirName)) {
-            GeneralUtility::mkdir_deep($tmpPath . $dirName);
-            return @is_dir($tmpPath . $dirName);
-        }
-        return false;
-    }
-
-    /**
      * Applies an ImageMagick parameter to a GDlib image pointer resource by writing the resource to file, performing an IM operation upon it and reading back the result into the ImagePointer.
      *
      * @param resource $im The image pointer (reference)
@@ -2709,9 +2650,8 @@ class GraphicalFunctions
     {
         if ($type === 'ai' || $w * $h < $this->pixelLimitGif) {
             return $this->gifExtension;
-        } else {
-            return 'jpg';
         }
+        return 'jpg';
     }
 
     /**
@@ -2731,11 +2671,10 @@ class GraphicalFunctions
             $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) {
+                        if ($this->setup['reduceColors']) {
                             $reduced = $this->IMreduceColors($file, MathUtility::forceIntegerInRange($this->setup['reduceColors'], 256, $this->truecolorColors, 256));
                             if ($reduced) {
                                 @copy($reduced, $file);
@@ -2748,15 +2687,13 @@ class GraphicalFunctions
                     }
                     break;
                 case 'jpg':
-
                 case 'jpeg':
                     // Use the default
                     $quality = 0;
                     if ($this->setup['quality']) {
                         $quality = MathUtility::forceIntegerInRange($this->setup['quality'], 10, 100);
                     }
-                    if ($this->ImageWrite($this->im, $file, $quality)) {
-                    }
+                    $this->ImageWrite($this->im, $file, $quality);
                     break;
             }
         }