Fixed bug #10025: ImageMagick generates larger than necessary files
authorSteffen Kamper <info@sk-typo3.de>
Fri, 27 Mar 2009 09:30:00 +0000 (09:30 +0000)
committerSteffen Kamper <info@sk-typo3.de>
Fri, 27 Mar 2009 09:30:00 +0000 (09:30 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@5233 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_div.php
t3lib/config_default.php
typo3/sysext/cms/tslib/class.tslib_content.php

index 2365f93..c222db2 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2009-03-27  Steffen Kamper  <info@sk-typo3.de>
+
+       * Fixed bug #10025: ImageMagick generates larger than necessary files
+
 2009-03-27  Michael Stucki  <michael@typo3.org>
 
        * AdminPanel: Indicate number of USER_INT objects used on a page
index 7601ae5..688de2e 100644 (file)
@@ -5337,6 +5337,18 @@ final class t3lib_div {
                        $path .= (($command=='composite') ? $combineScript : $command).$isExt;
                }
 
+                       // strip profile information for thumbnails and reduce their size
+               if ($gfxConf['im_useStripProfileByDefault'] && $gfxConf['im_stripProfileCommand'] != '') {
+                       if (strpos($parameters, $gfxConf['im_stripProfileCommand']) === false) {
+                                       // Determine whether the strip profile action has be disabled by TypoScript:
+                               if ($parameters !== '' && $parameters !== '-version' && strpos($parameters, '###SkipStripProfile###') === false) {
+                                       $parameters = $gfxConf['im_stripProfileCommand'] . ' ' . $parameters;
+                               } else {
+                                       $parameters = str_replace('###SkipStripProfile###', '', $parameters);
+                               }
+                       }
+               }
+
                $cmdLine = $path.' '.$parameters;
 
                if($command=='composite' && $switchCompositeParameters) {       // Because of some weird incompatibilities between ImageMagick 4 and 6 (plus GraphicsMagick), it is needed to change the parameters order under some preconditions
index eceeab8..fb014a3 100644 (file)
@@ -49,6 +49,8 @@ $TYPO3_CONF_VARS = Array(
                'im_noScaleUp' => 0,                                    // Boolean. If set, images are not being scaled up if told so (in t3lib/stdgraphics.php)
                'im_combine_filename' => 'combine',             // String. Latest ImageMagick versions has changed the name of combine to composite. Configure here if needed.
                'im_noFramePrepended' => 0,                             // Boolean. If set, the [x] frame indicator is NOT prepended to filenames in stdgraphic. Some IM5+ version didn't work at all with the typical [0]-prefix, which allow multipage pdf's and animated gif's to be scaled only for the first frame/page and that seriously cuts down rendering time. Set this flag only if your ImageMagick version cannot find the files. Notice that changing this flag causes temporary filenames to change, thus the server will begin scaling images again which were previously cached.
+               'im_stripProfileCommand' => '+profile \'*\'', // String. Specify the command to strip the profile information, which can reduce thumbnail size up to 60KB. Command can differ in IM/GM, IM also know the -strip command. See http://www.imagemagick.org/Usage/thumbnails/#profiles for details
+               'im_useStripProfileByDefault' => 0,             // Boolean. If set, the im_stripProfileCommand is used with all IM Image operations by default. See tsRef for setting this parameter explocit for IMAGE generation.
                'jpg_quality' => 70,                                    // Integer. Default JPEG generation quality
                'enable_typo3temp_db_tracking' => 0,    // Boolean. If set, then all files in typo3temp will be logged in a database table. In addition to being a log of the files with original filenames, it also serves to secure that the same image is not rendered simultaneously by two different processes.
                'TTFLocaleConv' => '',                                  // String. Enter locale conversion string used to recode input to TrueType functions. Eg. 'cp1250..UTF-8'. Deprecated from ver. 3.6.0 of TYPO3. Set up [BE][forceCharset] as strings are automatically converted from database charset to UTF-8.
index ded637d..fa61fdf 100644 (file)
@@ -4871,6 +4871,7 @@ class tslib_cObj {
                                                                                                //      Scaling:        ****
                                                                                        $tempScale=array();
                                                                                        $command = '-geometry '.$tempFileInfo[0].'x'.$tempFileInfo[1].'!';
+                                                                                       $command = $this->modifyImageMagickStripProfileParameters($command, $fileArray);
                                                                                        $tmpStr = $gifCreator->randomName();
 
                                                                                                //      m_mask
@@ -4914,6 +4915,7 @@ class tslib_cObj {
                                                                }
                                                                $GLOBALS['TSFE']->tmpl->fileCache[$hash]= $gifCreator->getImageDimensions($dest);
                                                        } else {                // Normal situation:
+                                                               $fileArray['params'] = $this->modifyImageMagickStripProfileParameters($fileArray['params'], $fileArray);
                                                                $GLOBALS['TSFE']->tmpl->fileCache[$hash]= $gifCreator->imageMagickConvert($theImage,$fileArray['ext'],$fileArray['width'],$fileArray['height'],$fileArray['params'],$fileArray['frame'],$options);
                                                                if (($fileArray['reduceColors'] || ($imgExt=='png' && !$gifCreator->png_truecolor)) && is_file($GLOBALS['TSFE']->tmpl->fileCache[$hash][3]))    {
                                                                        $reduced = $gifCreator->IMreduceColors($GLOBALS['TSFE']->tmpl->fileCache[$hash][3], t3lib_div::intInRange($fileArray['reduceColors'], 256, $gifCreator->truecolorColors, 256));
@@ -4944,6 +4946,25 @@ class tslib_cObj {
                }
        }
 
+       /**
+        * Modifies the parameters for ImageMagick for stripping of profile information.
+        *
+        * @param       string          $parameters: The parameters to be modified (if required)
+        * @param       array           $configuration: The TypoScript configuration of [IMAGE].file
+        * @param       string          The modified parameters
+        */
+       protected function modifyImageMagickStripProfileParameters($parameters, array $configuration) {
+                       // Strips profile information of image to save some space:
+               if (isset($configuration['stripProfile'])) {
+                       if ($configuration['stripProfile']) {
+                               $parameters = $gfxConf['im_stripProfileCommand'] . $parameters;
+                       } else {
+                               $parameters.= '###SkipStripProfile###';
+                       }
+               }
+               return $parameters;
+       }
+