function __construct($handlerName, $isGloballyEnabled, $outputRewriteType = self::REPLACE_SUFFIX, $conversionRules = false) { $supportedInputMIMETypes = array(); $supportedOutputMIMETypes = array(); $this->InputMap = array(); $this->OutputMap = array(); $this->OutputQualityMap = array(); $isEnabled = false; if (function_exists("imagetypes")) { $gdFunctions = array(array('mimetype' => 'image/gif', 'input' => 'imagecreatefromgif', 'output' => 'imagegif'), array('mimetype' => 'image/vnd.wap.wbmp', 'input' => 'imagecreatefromwbmp', 'output' => 'imagewbmp'), array('mimetype' => 'image/png', 'input' => 'imagecreatefrompng', 'output' => 'imagepng'), array('mimetype' => 'image/jpeg', 'input' => 'imagecreatefromjpeg', 'output' => 'imagejpeg', 'qualityparameter' => true)); foreach ($gdFunctions as $gdFunction) { $inputFunction = $gdFunction['input']; $outputFunction = $gdFunction['output']; if (function_exists($inputFunction) or function_exists($outputFunction)) { $isEnabled = true; $mimeType = $gdFunction['mimetype']; if (function_exists($inputFunction)) { $supportedInputMIMETypes[] = $mimeType; $this->InputMap[$mimeType] = $inputFunction; } if (function_exists($outputFunction)) { $this->OutputMap[$mimeType] = $outputFunction; $supportedOutputMIMETypes[] = $mimeType; } if (isset($gdFunction['qualityparameter'])) { $this->OutputQualityMap[$mimeType] = $gdFunction['qualityparameter']; } else { $this->OutputQualityMap[$mimeType] = false; } } } } if (!$isGloballyEnabled) { $isEnabled = false; } $this->FilterFunctionMap = array('geometry/scale' => 'scaleImage', 'geometry/scalewidth' => 'scaleImageWidth', 'geometry/scaleheight' => 'scaleImageHeight', 'geometry/scaledownonly' => 'scaleImageDownOnly', 'geometry/scalewidthdownonly' => 'scaleImageWidthDownOnly', 'geometry/scaleheightdownonly' => 'scaleImageHeightDownOnly', 'geometry/scaleexact' => 'scaleImageExact', 'geometry/scalepercent' => 'scaleImagePercent', 'geometry/crop' => 'cropImage', 'colorspace/gray' => 'setImageColorspaceGray', 'luminance' => 'setImageLuminance', 'luminance/gray' => 'setImageLuminanceNamed', 'luminance/sepia' => 'setImageLuminanceNamed', 'color/monochrome' => 'setImageColorThresholdName', 'border' => 'createImageBorder', 'border/color' => 'setImageBorderColor', 'border/width' => 'setImageBorderWidth'); $this->LuminanceColorScales = array('luminance/gray' => array(1.0, 1.0, 1.0), 'luminance/sepia' => array(1.0, 0.89, 0.74)); $this->ThresholdList = array('color/monochrome' => array(array('threshold' => 127, 'rgb' => array(0, 0, 0)), array('threshold' => 255, 'rgb' => array(255, 255, 255)))); $filters = array(); foreach ($this->FilterFunctionMap as $filterName => $filterFunction) { $filters[] = array('name' => $filterName); } parent::__construct($handlerName, $isEnabled, $outputRewriteType, $supportedInputMIMETypes, $supportedOutputMIMETypes, $conversionRules, $filters); }
/** * Performs the ezcImageConverter transformation * * @param string $src Source image * @param string $dst Destination image * @return void */ public function perform($src, $dst) { // fetch the input file locally $inClusterHandler = eZClusterFileHandler::instance($src); $inClusterHandler->fetch(); try { $this->converter->transform('transformation', $src, $dst); } catch (Exception $e) { $inClusterHandler->deleteLocal(); throw $e; } // store the output file to the cluster $outClusterHandler = eZClusterFileHandler::instance(); // @todo Check if the local output file can be deleted at that stage. Theorically yes. $outClusterHandler->fileStore($dst, true); // fixing the file permissions eZImageHandler::changeFilePermissions($dst); }
static function wildcardToRegexp( $wildcard, $separatorCharacter = false ) { return eZImageHandler::wildcardToRegexp( $wildcard, $separatorCharacter ); }
function outputMIMEType(&$manager, $currentMimeData, $wantedMimeData, $supportedFormatsOriginal, $aliasName = false) { if (is_array($this->conversionRules())) { $conversionRules = array_merge($manager->conversionRules(), $this->conversionRules()); } else { $conversionRules = $manager->conversionRules(); } $mimeData = false; $mimeType = false; if (!$this->isInputMIMETypeSupported($currentMimeData)) { return false; } if ($wantedMimeData) { $conversionRules = array_merge(array(array('from' => $currentMimeData['name'], 'to' => $wantedMimeData['name'])), $conversionRules); } $supportedFormats = array(); foreach ($supportedFormatsOriginal as $supportedFormat) { if ($this->isOutputMIMETypeSupported($supportedFormat)) { $supportedFormats[] = $supportedFormat; $conversionRules[] = array('from' => $supportedFormat, 'to' => $supportedFormat); } } if ($wantedMimeData and in_array($wantedMimeData['name'], $supportedFormats)) { $mimeType = $wantedMimeData['name']; } else { if (is_array($conversionRules)) { foreach ($conversionRules as $rule) { if (!$this->isOutputMIMETypeSupported($rule['to']) or !in_array($rule['to'], $supportedFormats)) { continue; } $matchRule = false; if (strpos($rule['from'], '*') !== false) { $matchString = eZImageHandler::wildcardToRegexp($rule['from']); if (preg_match("#^" . $matchString . "\$#", $currentMimeData['name'])) { $matchRule = $rule; } } else { if ($rule['from'] == $currentMimeData['name']) { $matchRule = $rule; } } if ($matchRule) { if ($mimeType) { if ($wantedMimeData and $matchRule['to'] == $wantedMimeData['name']) { $mimeType = $matchRule['to']; } } else { $mimeType = $matchRule['to']; } } } } } if ($mimeType) { $mimeData = eZMimeType::findByName($mimeType); $this->rewriteURL($currentMimeData, $mimeData, $this->outputRewriteType(), $aliasName); } return $mimeData; }
static function createFromINI($iniGroup, $iniFilename = false) { if (!$iniFilename) { $iniFilename = 'image.ini'; } $handler = false; $ini = eZINI::instance($iniFilename); if (!$ini) { eZDebug::writeError("Failed loading ini file {$iniFilename}", __METHOD__); return $handler; } if ($ini->hasGroup($iniGroup)) { $name = $iniGroup; if ($ini->hasVariable($iniGroup, 'Name')) { $name = $ini->variable($iniGroup, 'Name'); } $inputMimeList = false; $outputMimeList = false; if ($ini->hasVariable($iniGroup, 'InputMIMEList')) { $inputMimeList = $ini->variable($iniGroup, 'InputMIMEList'); } if ($ini->hasVariable($iniGroup, 'OutputMIMEList')) { $outputMimeList = $ini->variable($iniGroup, 'OutputMIMEList'); } $qualityParameters = false; if ($ini->hasVariable($iniGroup, 'QualityParameters')) { $qualityParametersRaw = $ini->variable($iniGroup, 'QualityParameters'); foreach ($qualityParametersRaw as $qualityParameterRaw) { $elements = explode(';', $qualityParameterRaw); $qualityParameters[$elements[0]] = $elements[1]; } } $frameRangeParameters = false; if ($ini->hasVariable($iniGroup, 'FrameRangeParameters')) { foreach ($ini->variable($iniGroup, 'FrameRangeParameters') as $frameRangeParameter) { $elements = explode(';', $frameRangeParameter); $frameRangeParameters[$elements[0]] = $elements[1]; } } $conversionRules = false; if ($ini->hasVariable($iniGroup, 'ConversionRules')) { $conversionRules = array(); $rules = $ini->variable($iniGroup, 'ConversionRules'); foreach ($rules as $ruleString) { $ruleItems = explode(';', $ruleString); if (count($ruleItems) >= 2) { $conversionRules[] = array('from' => $ruleItems[0], 'to' => $ruleItems[1]); } } } $isEnabled = $ini->variable($iniGroup, 'IsEnabled') == 'true'; $path = false; $executable = false; $preParameters = false; $postParameters = false; if ($ini->hasVariable($iniGroup, 'ExecutablePath')) { $path = $ini->variable($iniGroup, 'ExecutablePath'); } if (!$ini->hasVariable($iniGroup, 'Executable')) { eZDebug::writeError("No Executable setting for group {$iniGroup} in ini file {$iniFilename}", __METHOD__); return $handler; } $executable = $ini->variable($iniGroup, 'Executable'); $executableWin32 = false; $executableMac = false; $executableUnix = false; $ini->assign($iniGroup, 'ExecutableWin32', $executableWin32); $ini->assign($iniGroup, 'ExecutableMac', $executableMac); $ini->assign($iniGroup, 'ExecutableUnix', $executableUnix); if ($ini->hasVariable($iniGroup, 'ExecutablePath')) { $path = $ini->variable($iniGroup, 'ExecutablePath'); } if ($ini->hasVariable($iniGroup, 'PreParameters')) { $preParameters = $ini->variable($iniGroup, 'PreParameters'); } if ($ini->hasVariable($iniGroup, 'PostParameters')) { $postParameters = $ini->variable($iniGroup, 'PostParameters'); } $useTypeTag = false; if ($ini->hasVariable($iniGroup, 'UseTypeTag')) { $useTypeTag = $ini->variable($iniGroup, 'UseTypeTag'); } $outputRewriteType = self::REPLACE_SUFFIX; $filters = false; if ($ini->hasVariable($iniGroup, 'Filters')) { $filterRawList = $ini->variable($iniGroup, 'Filters'); $filters = array(); foreach ($filterRawList as $filterRawItem) { $filter = eZImageHandler::createFilterDefinitionFromINI($filterRawItem); $filters[] = $filter; } } $mimeTagMap = false; if ($ini->hasVariable($iniGroup, 'MIMETagMap')) { $mimeTagMapList = $ini->variable($iniGroup, 'MIMETagMap'); $mimeTagMap = array(); foreach ($mimeTagMapList as $mimeTagMapItem) { $mimeTagMapArray = explode(';', $mimeTagMapItem); if (count($mimeTagMapArray) >= 2) { $mimeTagMap[$mimeTagMapArray[0]] = $mimeTagMapArray[1]; } } } $handler = new eZImageShellHandler($name, $isEnabled, $outputRewriteType, $inputMimeList, $outputMimeList, $conversionRules, $filters, $mimeTagMap); $handler->Path = $path; $handler->Executable = $executable; $handler->ExecutableWin32 = $executableWin32; $handler->ExecutableMac = $executableMac; $handler->ExecutableUnix = $executableUnix; $handler->PreParameters = $preParameters; $handler->PostParameters = $postParameters; $handler->UseTypeTag = $useTypeTag; $handler->QualityParameters = $qualityParameters; $handler->FrameRangeParameters = $frameRangeParameters; return $handler; } return $handler; }