Project

General

Profile

Feature #14703 » 02_newWrapperFunction.diff

Administrator Admin, 2005-04-26 02:42

View differences:

typo3_src-3.8.0beta2.1/t3lib/class.t3lib_div.php 2005-04-25 02:20:33.000000000 +0200
}
return $str;
}
/**
* Compile the command for running ImageMagick/GraphicsMagick.
*
* @param string Command to be run
* @param string The parameters string
* @param string Override the default path
* @return string Compiled command that deals with IM6 & GraphicsMagick
*/
function imageMagickCommand($command, $parameters, $path='') {
$gfxConf = $GLOBALS['TYPO3_CONF_VARS']['GFX'];
$isExt = (TYPO3_OS=='WIN' ? '.exe' : '');
$switchCompositeParameters=false;
if(!$path) { $path = $gfxConf['im_path']; }
$im_version = $gfxConf['im_version_5'];
$combineScript = $gfxConf['im_combine_filename'] ? trim($gfxConf['im_combine_filename']) : 'combine';
if($command==='combine') { // This is only used internally, has no effect outside
$command = 'composite';
} elseif($command==='gm') { // Work-around for the install tool, trying to execute "gm gm"
$im_version = 'gm';
$command = 'identify';
} elseif($command==='__composite') { // One more work-around for the install tool, trying to find out if 'composite' exists
$command = 'composite';
$combineScript = 'composite';
}
// Compile the path & command
if($im_version==='gm') {
$switchCompositeParameters=true;
$path .= 'gm'.$isExt.' '.$command;
} else {
if($im_version==='im6') { $switchCompositeParameters=true; }
$path .= (($command=='composite') ? $combineScript : $command).$isExt;
}
$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
$paramsArr = t3lib_div::unQuoteFilenames($parameters);
if(count($paramsArr)==6) { // The mask image has been specified => swap the parameters
$tmp = $paramsArr[3];
$paramsArr[3] = $paramsArr[2];
$paramsArr[2] = $tmp;
}
$cmdLine = $path.' '.implode(' ', $paramsArr);
}
return $cmdLine;
}
/**
*
* Therefore the parameters need to be exploded, but they may be quoted (not in any case!)
*
* @param string The whole parameters string
* @return array Exploded parameters
*/
function unQuoteFilenames($parameters) {
$paramsArr = explode(' ', trim($parameters));
$quoteActive = -1; // Whenever a quoting character (") is found, $quoteActive is set to the element number inside of $params. A value of -1 means that there are not open quotes at the current position.
foreach($paramsArr as $k=>$v) {
if($quoteActive > -1) {
$paramsArr[$quoteActive] .= ' '.$v;
unset($paramsArr[$k]);
if(ereg('"$', $v)) { $quoteActive = -1; }
} elseif(!trim($v)) {
unset($paramsArr[$k]); // Remove empty elements
} elseif(ereg('^"', $v)) {
$quoteActive = $k;
}
}
return $paramsArr;
}
}
?>
(2-2/4)