[TASK] Deprecate GraphicalFunctions->init method
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Imaging / GraphicalFunctions.php
index 0ca004b..e60d637 100644 (file)
@@ -135,9 +135,10 @@ class GraphicalFunctions
     ];
 
     /**
+     * Whether ImageMagick/GraphicsMagick is enabled or not
      * @var bool
      */
-    protected $NO_IMAGE_MAGICK = false;
+    protected $processorEnabled;
 
     /**
      * @var bool
@@ -298,10 +299,10 @@ class GraphicalFunctions
     protected $im;
 
     /**
-     * Init function. Must always call this when using the class.
-     * This function will read the configuration information from $GLOBALS['TYPO3_CONF_VARS']['GFX'] can set some values in internal variables.
+     * Reads configuration information from $GLOBALS['TYPO3_CONF_VARS']['GFX']
+     * and sets some values in internal variables.
      */
-    public function init()
+    public function __construct()
     {
         $gfxConf = $GLOBALS['TYPO3_CONF_VARS']['GFX'];
         if (function_exists('imagecreatefromjpeg') && function_exists('imagejpeg')) {
@@ -319,9 +320,54 @@ class GraphicalFunctions
             $this->colorspace = $gfxConf['processor_colorspace'];
         }
 
-        if (!$gfxConf['processor_enabled']) {
-            $this->NO_IMAGE_MAGICK = true;
+        $this->processorEnabled = (bool)$gfxConf['processor_enabled'];
+        // Setting default JPG parameters:
+        $this->jpegQuality = MathUtility::forceIntegerInRange($gfxConf['jpg_quality'], 10, 100, 85);
+        $this->addFrameSelection = (bool)$gfxConf['processor_allowFrameSelection'];
+        if ($gfxConf['gdlib_png']) {
+            $this->gifExtension = 'png';
+        }
+        $this->imageFileExt = GeneralUtility::trimExplode(',', $gfxConf['imagefile_ext']);
+
+        // Boolean. This is necessary if using ImageMagick 5+.
+        // Effects in Imagemagick 5+ tends to render very slowly!!
+        // - therefore must be disabled in order not to perform sharpen, blurring and such.
+        $this->cmds['jpg'] = $this->cmds['jpeg'] = '-colorspace ' . $this->colorspace . ' -quality ' . $this->jpegQuality;
+
+        // ... but if 'processor_effects' is set, enable effects
+        if ($gfxConf['processor_effects']) {
+            $this->processorEffectsEnabled = true;
+            $this->cmds['jpg'] .= $this->v5_sharpen(10);
+            $this->cmds['jpeg'] .= $this->v5_sharpen(10);
+        }
+        // Secures that images are not scaled up.
+        $this->mayScaleUp = (bool)$gfxConf['processor_allowUpscaling'];
+        $this->csConvObj = GeneralUtility::makeInstance(CharsetConverter::class);
+    }
+
+    /**
+     * @deprecated will be removed in TYPO3 v10.0. As the constructor does everything directly
+     */
+    public function init()
+    {
+        trigger_error('GraphicalFunctions->init() will be removed in TYPO3 v10.0. Simply remove the call to the method, since this is now evaluted in the constructor.', E_USER_DEPRECATED);
+        $gfxConf = $GLOBALS['TYPO3_CONF_VARS']['GFX'];
+        if (function_exists('imagecreatefromjpeg') && function_exists('imagejpeg')) {
+            $this->gdlibExtensions[] = 'jpg';
+            $this->gdlibExtensions[] = 'jpeg';
+        }
+        if (function_exists('imagecreatefrompng') && function_exists('imagepng')) {
+            $this->gdlibExtensions[] = 'png';
+        }
+        if (function_exists('imagecreatefromgif') && function_exists('imagegif')) {
+            $this->gdlibExtensions[] = 'gif';
+        }
+
+        if ($gfxConf['processor_colorspace'] && in_array($gfxConf['processor_colorspace'], $this->allowedColorSpaceNames, true)) {
+            $this->colorspace = $gfxConf['processor_colorspace'];
         }
+
+        $this->processorEnabled = (bool)$gfxConf['processor_enabled'];
         // Setting default JPG parameters:
         $this->jpegQuality = MathUtility::forceIntegerInRange($gfxConf['jpg_quality'], 10, 100, 85);
         $this->addFrameSelection = (bool)$gfxConf['processor_allowFrameSelection'];
@@ -2053,7 +2099,7 @@ class GraphicalFunctions
      */
     public function imageMagickConvert($imagefile, $newExt = '', $w = '', $h = '', $params = '', $frame = '', $options = [], $mustCreate = false)
     {
-        if ($this->NO_IMAGE_MAGICK) {
+        if (!$this->processorEnabled) {
             // Returning file info right away
             return $this->getImageDimensions($imagefile);
         }
@@ -2406,7 +2452,7 @@ class GraphicalFunctions
      */
     public function imageMagickIdentify($imagefile)
     {
-        if ($this->NO_IMAGE_MAGICK) {
+        if (!$this->processorEnabled) {
             return null;
         }
 
@@ -2449,7 +2495,7 @@ class GraphicalFunctions
      */
     public function imageMagickExec($input, $output, $params, $frame = 0)
     {
-        if ($this->NO_IMAGE_MAGICK) {
+        if (!$this->processorEnabled) {
             return '';
         }
         // If addFrameSelection is set in the Install Tool, a frame number is added to
@@ -2475,7 +2521,7 @@ class GraphicalFunctions
      */
     public function combineExec($input, $overlay, $mask, $output)
     {
-        if ($this->NO_IMAGE_MAGICK) {
+        if (!$this->processorEnabled) {
             return '';
         }
         $theMask = $this->randomName() . '.' . $this->gifExtension;