[!!!][TASK] Convert thumbnails only for non-image files 80/46480/15
authorEric Chavaillaz <eric@hemmer.ch>
Thu, 4 Feb 2016 10:43:48 +0000 (11:43 +0100)
committerBenni Mack <benni@typo3.org>
Fri, 4 Mar 2016 15:55:06 +0000 (16:55 +0100)
The global option "thumbnails_png" must only be taken
into account if the processed file is not an image.

Resolves: #73106
Releases: master
Change-Id: I9d806631331924f680d4d7834136e6860c6d95d8
Reviewed-on: https://review.typo3.org/46480
Reviewed-by: Jan Helke <typo3@helke.de>
Tested-by: Jan Helke <typo3@helke.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/core/Classes/Resource/Processing/AbstractGraphicalTask.php
typo3/sysext/core/Configuration/DefaultConfiguration.php
typo3/sysext/core/Documentation/Changelog/master/Breaking-73106-ConvertThumbnailsOnlyForNon-imageFiles.rst [new file with mode: 0644]
typo3/sysext/install/Classes/Service/SilentConfigurationUpgradeService.php

index 6eefd56..54f4ce4 100644 (file)
@@ -14,6 +14,9 @@ namespace TYPO3\CMS\Core\Resource\Processing;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Resource\AbstractFile;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
 /**
  * Abstract base implementation of a task.
  *
@@ -67,31 +70,14 @@ abstract class AbstractGraphicalTask extends AbstractTask
     {
         if (!empty($this->configuration['fileExtension'])) {
             $targetFileExtension = $this->configuration['fileExtension'];
+        } elseif ($this->getSourceFile()->getType() === AbstractFile::FILETYPE_IMAGE) {
+            $targetFileExtension = $this->getSourceFile()->getExtension();
+        // If true, thumbnails from non-image files will be converted to 'png', otherwise 'gif'
+        } elseif ($GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails_png']) {
+            $targetFileExtension = 'png';
         } else {
-            // explanation for "thumbnails_png"
-            // Bit0: If set, thumbnails from non-jpegs will be 'png', otherwise 'gif' (0=gif/1=png).
-            // Bit1: Even JPG's will be converted to png or gif (2=gif/3=png)
-
-            $targetFileExtensionConfiguration = $GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails_png'];
-            if ($this->getSourceFile()->getExtension() === 'jpg' || $this->getSourceFile()->getExtension() === 'jpeg') {
-                if ($targetFileExtensionConfiguration == 2) {
-                    $targetFileExtension = 'gif';
-                } elseif ($targetFileExtensionConfiguration == 3) {
-                    $targetFileExtension = 'png';
-                } else {
-                    $targetFileExtension = 'jpg';
-                }
-            } else {
-                // check if a png or a gif should be created
-                if ($targetFileExtensionConfiguration == 1 || $this->getSourceFile()->getExtension() === 'png') {
-                    $targetFileExtension = 'png';
-                } else {
-                    // thumbnails_png is "0"
-                    $targetFileExtension = 'gif';
-                }
-            }
+            $targetFileExtension = 'gif';
         }
-
         return $targetFileExtension;
     }
 }
index 4e7b644..57ba8b6 100644 (file)
@@ -20,7 +20,7 @@ return array(
     'GFX' => array(
         // Configuration of the image processing features in TYPO3. 'IM' and 'GD' are short for ImageMagick and GD library respectively.
         'thumbnails' => true,                            // Boolean: Enables the use of thumbnails in the backend interface.
-        'thumbnails_png' => 0,                            // Bits. Bit0: If set, thumbnails from non-jpegs will be 'png', otherwise 'gif' (0=gif/1=png). Bit1: Even JPG's will be converted to png or gif (2=gif/3=png)
+        'thumbnails_png' => true,                            // Boolean. If false, thumbnails from non-image files will be converted to 'gif', otherwise 'png' (default).
         'gif_compress' => true,                            // Boolean: Enables the use of the \TYPO3\CMS\Core\Utility\GeneralUtility::gifCompress() workaround function for compressing giffiles made with GD or IM, which probably use only RLE or no compression at all.
         'imagefile_ext' => 'gif,jpg,jpeg,tif,tiff,bmp,pcx,tga,png,pdf,ai,svg',// 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!
         'gdlib' => true,                                // Boolean: Enables the use of GD.
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Breaking-73106-ConvertThumbnailsOnlyForNon-imageFiles.rst b/typo3/sysext/core/Documentation/Changelog/master/Breaking-73106-ConvertThumbnailsOnlyForNon-imageFiles.rst
new file mode 100644 (file)
index 0000000..6ffa72a
--- /dev/null
@@ -0,0 +1,29 @@
+==============================================================
+Breaking: #73106 - Convert thumbnails only for non-image files
+==============================================================
+
+Description
+===========
+
+$TYPO3_CONF_VARS[GFX][thumbnails_png] must be taken into account only for non-image files.
+
+
+Impact
+======
+
+$TYPO3_CONF_VARS[GFX][thumbnails_png] is now a boolean value. If the value is true, the processed
+thumbnails that are not an image will be converted in png, otherwise these will be converted to gif.
+It is not possible anymore to convert the processed thumbnails that are png or gif to jpg files.
+
+
+Affected Installations
+======================
+
+Installations who have set the value of $TYPO3_CONF_VARS[GFX][thumbnails_png] to 2 or 3.
+
+
+Migration
+=========
+
+The install tool automatically sets the value of $TYPO3_CONF_VARS[GFX][thumbnails_png] to true,
+if it has been set to 1, 2 or 3 previously.
\ No newline at end of file
index c508e5c..cbf1b94 100755 (executable)
@@ -110,6 +110,7 @@ class SilentConfigurationUpgradeService
         $this->disableImageMagickDetailSettingsIfImageMagickIsDisabled();
         $this->setImageMagickDetailSettings();
         $this->removeObsoleteLocalConfigurationSettings();
+        $this->migrateThumbnailsPngSetting();
     }
 
     /**
@@ -488,4 +489,26 @@ class SilentConfigurationUpgradeService
             1379024938
         );
     }
+
+    /**
+     * Migrate the configuration value thumbnails_png to a boolean value.
+     *
+     * @return void
+     */
+    protected function migrateThumbnailsPngSetting() {
+        $changedValues = array();
+        try {
+            $currentThumbnailsPngValue = $this->configurationManager->getLocalConfigurationValueByPath('GFX/thumbnails_png');
+        } catch (\RuntimeException $e) {
+            $currentThumbnailsPngValue = $this->configurationManager->getDefaultConfigurationValueByPath('GFX/thumbnails_png');
+        }
+
+        if (is_int($currentThumbnailsPngValue) && $currentThumbnailsPngValue > 0) {
+            $changedValues['GFX/thumbnails_png'] = true;
+        }
+        if (!empty($changedValues)) {
+            $this->configurationManager->setLocalConfigurationValuesByPathValuePairs($changedValues);
+            $this->throwRedirectException();
+        }
+    }
 }