/** * Compile the command for running ImageMagick/GraphicsMagick. * * @param string $command Command to be run: identify, convert or combine/composite * @param string $parameters The parameters string * @param string $path Override the default path (e.g. used by the install tool) * @return string Compiled command that deals with IM6 & GraphicsMagick */ public static function imageMagickCommand($command, $parameters, $path = '') { $gfxConf = $GLOBALS['TYPO3_CONF_VARS']['GFX']; $isExt = TYPO3_OS == 'WIN' ? '.exe' : ''; $switchCompositeParameters = false; if (!$path) { $path = $gfxConf['im_path']; } $path = GeneralUtility::fixWindowsFilePath($path); $im_version = strtolower($gfxConf['im_version_5']); // This is only used internally, has no effect outside if ($command === 'combine') { $command = 'composite'; } // Compile the path & command if ($im_version === 'gm') { $switchCompositeParameters = true; $path = self::escapeShellArgument($path . 'gm' . $isExt) . ' ' . self::escapeShellArgument($command); } else { if ($im_version === 'im6') { $switchCompositeParameters = true; } $path = self::escapeShellArgument($path . ($command == 'composite' ? 'composite' : $command) . $isExt); } // strip profile information for thumbnails and reduce their size if ($parameters && $command != 'identify' && $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 !== '-version' && strpos($parameters, '###SkipStripProfile###') === false) { $parameters = $gfxConf['im_stripProfileCommand'] . ' ' . $parameters; } else { $parameters = str_replace('###SkipStripProfile###', '', $parameters); } } } $cmdLine = $path . ' ' . $parameters; // Because of some weird incompatibilities between ImageMagick 4 and 6 (plus GraphicsMagick), // it is needed to change the parameters order under some preconditions if ($command == 'composite' && $switchCompositeParameters) { $paramsArr = GeneralUtility::unQuoteFilenames($parameters); // The mask image has been specified => swap the parameters $paramsArrCount = count($paramsArr); if ($paramsArrCount > 5) { $tmp = $paramsArr[$paramsArrCount - 3]; $paramsArr[$paramsArrCount - 3] = $paramsArr[$paramsArrCount - 4]; $paramsArr[$paramsArrCount - 4] = $tmp; } $cmdLine = $path . ' ' . implode(' ', $paramsArr); } return $cmdLine; }
/** * Compile the command for running ImageMagick/GraphicsMagick. * * @param string $command Command to be run: identify, convert or combine/composite * @param string $parameters The parameters string * @param string $path Override the default path (e.g. used by the install tool) * @return string Compiled command that deals with ImageMagick & GraphicsMagick */ public static function imageMagickCommand($command, $parameters, $path = '') { $gfxConf = $GLOBALS['TYPO3_CONF_VARS']['GFX']; $isExt = TYPO3_OS === 'WIN' ? '.exe' : ''; if (!$path) { $path = $gfxConf['processor_path']; } $path = GeneralUtility::fixWindowsFilePath($path); // This is only used internally, has no effect outside if ($command === 'combine') { $command = 'composite'; } // Compile the path & command if ($gfxConf['processor'] === 'GraphicsMagick') { $path = self::escapeShellArgument($path . 'gm' . $isExt) . ' ' . self::escapeShellArgument($command); } else { $path = self::escapeShellArgument($path . $command . $isExt); } // strip profile information for thumbnails and reduce their size if ($parameters && $command !== 'identify' && $gfxConf['processor_stripColorProfileByDefault'] && $gfxConf['processor_stripColorProfileCommand'] !== '' && strpos($parameters, $gfxConf['processor_stripColorProfileCommand']) === false) { // Determine whether the strip profile action has be disabled by TypoScript: if ($parameters !== '-version' && strpos($parameters, '###SkipStripProfile###') === false) { $parameters = $gfxConf['processor_stripColorProfileCommand'] . ' ' . $parameters; } else { $parameters = str_replace('###SkipStripProfile###', '', $parameters); } } $cmdLine = $path . ' ' . $parameters; // It is needed to change the parameters order when a mask image has been specified if ($command === 'composite') { $paramsArr = GeneralUtility::unQuoteFilenames($parameters); $paramsArrCount = count($paramsArr); if ($paramsArrCount > 5) { $tmp = $paramsArr[$paramsArrCount - 3]; $paramsArr[$paramsArrCount - 3] = $paramsArr[$paramsArrCount - 4]; $paramsArr[$paramsArrCount - 4] = $tmp; } $cmdLine = $path . ' ' . implode(' ', $paramsArr); } return $cmdLine; }