[!!!][BUGFIX] Crop-Scaled images have wrong file content type 97/19397/2
authorOliver Hader <oliver@typo3.org>
Fri, 22 Mar 2013 09:35:53 +0000 (10:35 +0100)
committerOliver Hader <oliver.hader@typo3.org>
Thu, 28 Mar 2013 08:06:13 +0000 (09:06 +0100)
The following scenario is given:
* resize a 300dpi TIFF image to PNG using stdWrap/cObj
* the 'fileExtension' configuration is not set
* the processed file csm_... has the file extension PNG
* but the file content type is still TIFF, so the file
  was just renamed, but not converted to PNG

Since the processing task determines the accordant filename
and file extension of the processed file, the image processor
(e.g. ImageMagick) needs to know about that fact as well.

This change modifies the TaskInterface which is rarely to not
at all used in custom extensions implementing individual tasks
to process files.

Change-Id: I089edc01a39663ac91b1b9df168f659c32954fcb
Fixes: #46530
Releases: 6.0, 6.1
Reviewed-on: https://review.typo3.org/19169
Reviewed-by: Oliver Hader
Tested-by: Oliver Hader
Reviewed-on: https://review.typo3.org/19397

typo3/sysext/core/Classes/Resource/Processing/AbstractGraphicalTask.php
typo3/sysext/core/Classes/Resource/Processing/AbstractTask.php
typo3/sysext/core/Classes/Resource/Processing/LocalCropScaleMaskHelper.php
typo3/sysext/core/Classes/Resource/Processing/LocalPreviewHelper.php
typo3/sysext/core/Classes/Resource/Processing/TaskInterface.php

index 2b8fb0b..fe142a0 100644 (file)
@@ -40,6 +40,11 @@ use \TYPO3\CMS\Core\Resource, \TYPO3\CMS\Core\Utility;
 abstract class AbstractGraphicalTask extends AbstractTask {
 
        /**
+        * @var string
+        */
+       protected $targetFileExtension;
+
+       /**
         * Sets parameters needed in the checksum. Can be overridden to add additional parameters to the checksum.
         * This should include all parameters that could possibly vary between different task instances, e.g. the
         * TYPO3 image configuration in TYPO3_CONF_VARS[GFX] for graphic processing tasks.
@@ -54,23 +59,50 @@ abstract class AbstractGraphicalTask extends AbstractTask {
        }
 
        /**
-        * Returns the filename
+        * Returns the name the processed file should have
+        * in the filesystem.
         *
         * @return string
         */
        public function getTargetFilename() {
-               if ($this->targetFile->getOriginalFile()->getExtension() === 'jpg') {
+               return $this->targetFile->getOriginalFile()->getNameWithoutExtension()
+                       . '_' . $this->getConfigurationChecksum()
+                       . '.' . $this->getTargetFileExtension();
+       }
+
+       /**
+        * Determines the file extension the processed file
+        * should have in the filesystem.
+        *
+        * @return string
+        */
+       public function getTargetFileExtension() {
+               if (!isset($this->targetFileExtension)) {
+                       $this->targetFileExtension = $this->determineTargetFileExtension();
+               }
+
+               return $this->targetFileExtension;
+       }
+
+       /**
+        * Gets the file extension the processed file should
+        * have in the filesystem by either using the configuration
+        * setting, or the extension of the original file.
+        *
+        * @return string
+        */
+       protected function determineTargetFileExtension() {
+               if (!empty($this->configuration['fileExtension'])) {
+                       $targetFileExtension = $this->configuration['fileExtension'];
+               } elseif ($this->targetFile->getOriginalFile()->getExtension() === 'jpg') {
                        $targetFileExtension = 'jpg';
                } else {
                        $targetFileExtension = 'png';
                }
 
-               return $this->targetFile->getOriginalFile()->getNameWithoutExtension()
-                       . '_' . $this->getConfigurationChecksum()
-                       . '.' . $targetFileExtension;
+               return $targetFileExtension;
        }
 
-
 }
 
 ?>
\ No newline at end of file
index 9eb11e2..04e90e5 100644 (file)
@@ -115,7 +115,17 @@ abstract class AbstractTask implements TaskInterface {
        public function getTargetFilename() {
                return $this->targetFile->getNameWithoutExtension()
                        . '_' . $this->getConfigurationChecksum()
-                       . '.' . $this->targetFile->getExtension();
+                       . '.' . $this->getTargetFileExtension();
+       }
+
+       /**
+        * Gets the file extension the processed file should
+        * have in the filesystem.
+        *
+        * @return string
+        */
+       public function getTargetFileExtension() {
+               return $this->targetFile->getExtension();
        }
 
        /**
index 6e541f8..020f367 100644 (file)
@@ -69,6 +69,10 @@ class LocalCropScaleMaskHelper {
                $configuration = $targetFile->getProcessingConfiguration();
                $configuration['additionalParameters'] = $this->modifyImageMagickStripProfileParameters($configuration['additionalParameters'], $configuration);
 
+               if (empty($configuration['fileExtension'])) {
+                       $configuration['fileExtension'] = $task->getTargetFileExtension();
+               }
+
                $options = $this->getConfigurationForImageCropScaleMask($targetFile, $gifBuilder);
 
                // Normal situation (no masking)
index 03ff874..525b737 100644 (file)
@@ -66,15 +66,8 @@ class LocalPreviewHelper {
 
                $originalFileName = $targetFile->getOriginalFile()->getForLocalProcessing(FALSE);
 
-                       // Create a temporary file in typo3temp/
-               if ($targetFile->getOriginalFile()->getExtension() === 'jpg') {
-                       $targetFileExtension = '.jpg';
-               } else {
-                       $targetFileExtension = '.png';
-               }
-
                        // Create the thumb filename in typo3temp/preview_....jpg
-               $temporaryFileName = Utility\GeneralUtility::tempnam('preview_') . $targetFileExtension;
+               $temporaryFileName = Utility\GeneralUtility::tempnam('preview_') . '.' . $task->getTargetFileExtension();
                        // Check file extension
                if ($targetFile->getOriginalFile()->getType() != Resource\File::FILETYPE_IMAGE &&
                        !Utility\GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $targetFile->getOriginalFile()->getExtension())) {
index bdbab42..071bd89 100644 (file)
@@ -91,6 +91,13 @@ interface TaskInterface {
        public function getTargetFileName();
 
        /**
+        * Gets the file extension the processed file should have in the filesystem.
+        *
+        * @return string
+        */
+       public function getTargetFileExtension();
+
+       /**
         * Returns TRUE if the file has to be processed at all, such as e.g. the original file does.
         *
         * Note: This does not indicate if the concrete ProcessedFile attached to this task has to be (re)processed.