public function setUp() { parent::setUp(); exec(eZINI::instance("image.ini")->variable("ImageMagick", "Executable") . " -version 2>&1", $output, $returnValue); if ($returnValue !== 0) { $this->markTestSkipped('ImageMagick is not installed'); } $this->imageManager = eZImageManager::instance(); $this->imageManager->readINISettings(); ezpINIHelper::setINISetting('image.ini', 'ImageConverterSettings', 'ImageConverters', array('ImageMagick')); }
/** * Test scenario for image alias using filters from multiple image handlers * for issue #15773: Infinite loop in ImageManager when using filters from multiple image handlers * * Test Outline * ------------ * 1. Setup alias with filters from multiple image handlers * 2. Load image manager * 3. Backup max_execution_time, set it to 60 seconds * 4. Convert image * 5. Restore max_execution_time * * @result: * The operation times out after 60 seconds * @expected: * The conversion call returns true * @link http://issues.ez.no/15773 */ public function testMultiHandlerAlias() { if (!self::gdIsEnabled() && !self::imageMagickIsEnabled()) { $this->markTestSkipped('Neither GD nor ImageMagick are enabled'); } $aliasList = $this->imageIni->variable('AliasSettings', 'AliasList'); array_push($aliasList, 'multihandler'); $this->imageIni->setVariable('AliasSettings', 'AliasList', $aliasList); $this->imageIni->setVariable('multihandler', 'Reference', ''); $this->imageIni->setVariable('multihandler', 'Filters', array('luminance/gray', 'filter/swirl=210')); $sourcePath = 'tests/tests/lib/ezimage/data/andernach.jpg'; $targetPath = 'tests/tests/lib/ezimage/data/andernach_result.jpg'; $img = eZImageManager::instance(); $img->readINISettings(); $timeLimit = ini_get('max_execution_time'); set_time_limit(60); $result = $img->convert($sourcePath, $targetPath, 'multihandler'); set_time_limit($timeLimit); $this->assertEquals(true, $result); }
/** * Reset a shared instance of the eZImageManager class and factory variable. * As used by {@link eZImageManager::instance()} and {@link eZImageManager::factory()} * * @since 4.3 */ static function resetInstance() { self::$instance = null; self::$factory = false; }
/** * Function for insert image */ function callImage($info) { $params = array(); $leftMargin = false; $rightMargin = false; eZPDFTable::extractParameters($info['p'], 0, $params, true); $filename = rawurldecode($params['src']); $mimetype = eZMimeType::findByFileContents($filename); $this->transaction('start'); if (!isset($params['static'])) { $params['static'] = false; } if ($this->yOffset() - $params['height'] < $this->ez['bottomMargin']) { $this->ezNewPage(); } if (isset($params['dpi'])) { $newWidth = (int) ($params['width'] * ((int) $params['dpi'] / 72)); $newHeight = (int) ($params['height'] * ((int) $params['dpi'] / 72)); $newFilename = eZSys::cacheDirectory() . '/' . md5(mt_rand()) . '.jpg'; while (file_exists($newFilename)) { $newFilename = eZSys::cacheDirectory() . '/' . md5(mt_rand()) . '.jpg'; } $img = eZImageManager::factory(); $newImg = $img->convert($filename, $newFilename, false, array('filters' => array(array('name' => 'geometry/scaledownonly', 'data' => array($newWidth, $newHeight))))); $filename = $newFilename['url']; } $drawableAreaWidth = $this->ez['pageWidth'] - $this->ez['leftMargin'] - $this->ez['rightMargin']; switch ($params['align']) { case 'right': $xOffset = $this->ez['pageWidth'] - ($this->rightMargin() + $params['width']); $rightMargin = $this->rightMargin() + $params['width']; if ($rightMargin > $drawableAreaWidth + $this->rightMargin()) { // the image is equal or larger then width of the page(of the drawable area) => no point // to set $rightMargin and next object(text, image, ...) should be outputted below the image. $rightMargin = false; } break; case 'center': $xOffset = ($this->ez['pageWidth'] - $this->rightMargin() - $this->leftMargin()) / 2 + $this->leftMargin() - $params['width'] / 2; break; case 'left': default: $xOffset = $this->leftMargin(); $leftMargin = $this->leftMargin() + $params['width']; if ($leftMargin > $drawableAreaWidth + $this->leftMargin()) { // the image is equal or larger then width of the page(of the drawable area) => no point // to set $leftMargin and next object(text, image, ...) should be outputted below the image. $leftMargin = false; } break; } if (isset($params['x'])) { $xOffset = $params['x']; $leftMargin = false; $rightMargin = false; } $yOffset = $this->yOffset(); $whileCount = 0; if ($params['width'] < $drawableAreaWidth) { while ($this->leftMargin($yOffset) > $xOffset && ++$whileCount < 100) { $yOffset -= 10; } } $yOffset -= $params['height']; $yOffset += $this->lineHeight() / 2; if (isset($params['y'])) { $yOffset = $params['y']; } if ($leftMargin !== false) { $this->setLimitedLeftMargin($yOffset - 7, $yOffset + $params['height'] + 7, $leftMargin + 7); } if ($rightMargin !== false) { $this->setLimitedRightMargin($yOffset - 7, $yOffset + $params['height'] + 7, $rightMargin + 7); } switch ($mimetype['name']) { case 'image/gif': $newFilename = eZSys::cacheDirectory() . '/' . md5(mt_rand()) . '.jpg'; while (file_exists($newFilename)) { $newFilename = eZSys::cacheDirectory() . '/' . md5(mt_rand()) . '.jpg'; } $newMimetype = eZMimeType::findByURL($newFilename); $img = eZImageManager::factory(); $newImg = $img->convert($mimetype, $newMimetype, false, array()); $this->addJpegFromFile($newMimetype['url'], $xOffset, $yOffset, $params['width'], $params['height']); break; case 'image/jpeg': $this->addJpegFromFile($filename, $xOffset, $yOffset, $params['width'], $params['height']); break; case 'image/png': if ($this->addPngFromFile($filename, $xOffset, $yOffset, $params['width'], $params['height']) === false) { $this->transaction('abort'); return; } break; default: eZDebug::writeError('Unsupported image file type, ' . $mimetype['name'], __METHOD__); $this->transaction('abort'); return; break; } $this->transaction('commit'); if (!$leftMargin && !$rightMargin && !$params['static']) { $this->y -= $params['height'] + $this->lineHeight(); } return array('y' => $params['height'] + $this->lineHeight()); }
function generateXMLData() { $doc = new DOMDocument('1.0', 'utf-8'); $imageNode = $doc->createElement("ezimage"); $doc->appendChild($imageNode); $fileName = false; $imageManager = eZImageManager::factory(); $mimeData = eZMimeType::findByFileContents($fileName); $imageManager->analyzeImage($mimeData); $imageNode->setAttribute('serial_number', false); $imageNode->setAttribute('is_valid', false); $imageNode->setAttribute('filename', $fileName); $imageNode->setAttribute('suffix', false); $imageNode->setAttribute('basename', false); $imageNode->setAttribute('dirpath', false); $imageNode->setAttribute('url', false); $imageNode->setAttribute('original_filename', false); $imageNode->setAttribute('mime_type', false); $imageNode->setAttribute('width', false); $imageNode->setAttribute('height', false); $imageNode->setAttribute('alternative_text', false); $imageNode->setAttribute('alias_key', $imageManager->createImageAliasKey($imageManager->alias('original'))); $imageNode->setAttribute('timestamp', time()); $this->createImageInformationNode($imageNode, $mimeData); $this->storeDOMTree($doc, true, false); }
$scriptSettings['use-session'] = true; $scriptSettings['use-modules'] = false; $scriptSettings['use-extensions'] = true; $script = eZScript::instance($scriptSettings); $script->startup(); $config = ''; $argumentConfig = ''; $optionHelp = false; $arguments = false; $useStandardOptions = true; $options = $script->getOptions($config, $argumentConfig, $optionHelp, $arguments, $useStandardOptions); $script->initialize(); $script->setIterationData('.', '~'); $db = eZDB::instance(); $db->begin(); $imageManager = eZImageManager::factory(); $contentObjectAttributes = eZPersistentObject::fetchObjectList(eZContentObjectAttribute::definition(), null, array('data_type_string' => 'ezimage')); $script->resetIteration(count($contentObjectAttributes)); foreach ($contentObjectAttributes as $contentObjectAttribute) { $success = false; $xmlString = $contentObjectAttribute->attribute('data_text'); if ($xmlString != '') { $dom = new DOMDocument('1.0', 'UTF-8'); $success = $dom->loadXML($xmlString); unset($dom); } if (!$success) { // upgrade from old image system to the one introduced in eZ Publish 3.3 $imageAliasHandler = new eZImageAliasHandler($contentObjectAttribute); $attributeID = $contentObjectAttribute->attribute('id'); $attributeVersion = $contentObjectAttribute->attribute('version');
/** * Create image alias variation by contentObjectAttribute * * @param object $contentObjectAttribute object of class eZContentObjectAtribute * @param array $class Array of object class identifiers to create aliases for only these classes. Optional. Defaults to false * @param array $attributes Array of object image attribute identifiers to create aliases. Optional. Defaults to false * @param array $aliases Array of object image attribute image aliases to create. Optional. Defaults to false * * @return bool true if any image alias generation is called, false if not * @static */ static function createByAttribute($contentObjectAttribute = false, $classes = false, $attributes = false, $aliases = false) { if (!$contentObjectAttribute) { return false; } // Test that content object class attribute identifier matches provided classes if ($classes != false && is_array($classes) && !in_array($contentObjectAttribute->attribute('object')->attribute('class_identifier'), $classes)) { return false; } // Test that content object class attribute identifier matches provided classes if ($attributes != false && is_array($attributes) && !in_array($contentObjectAttribute->attribute('contentclass_attribute_identifier'), $attributes)) { return false; } $results = array(); $result = array(); $createAliases = array(); $executionOptions = self::executionOptions(); // Default image alias settings $relatedSiteAccesses = eZINI::instance('site.ini')->variable('SiteAccessSettings', 'RelatedSiteAccessList'); // Fetch aliases for current siteaccess if ($executionOptions['current-siteaccess']) { if (!$aliases) { // Default image alias settings $createAliases = eZINI::instance('image.ini')->variable('AliasSettings', 'AliasList'); } else { // Parameter image alias to create $createAliases = $aliases; } } else { if (!$aliases) { // Fetch aliases for current siteaccess relateded siteaccesses if (is_array($relatedSiteAccesses)) { foreach ($relatedSiteAccesses as $relatedSiteAccess) { $relatedSiteaccessImageINIOverrideFile = 'settings/siteaccess/' . $relatedSiteAccess . '/image.ini.append.php'; if (file_exists($relatedSiteaccessImageINIOverrideFile)) { // Optional debug output if ($executionOptions['troubleshoot']) { self::displayMessage('Fetching related siteaccess ' . "'" . $relatedSiteAccess . "'" . ' image.ini:[AliasSettings] AliasList[] image aliases defined', "\n"); } $siteaccessAliases = eZINI::getSiteAccessIni($relatedSiteAccess, 'image.ini')->variable('AliasSettings', 'AliasList'); // Test for siteaccesses if ($siteaccessAliases != false) { // Add siteaccess aliases into array foreach ($siteaccessAliases as $siteaccessAlias) { if (!in_array($siteaccessAlias, $aliases)) { $aliases[] = $siteaccessAlias; } } // Add default settings aliases into array foreach (eZINI::instance('image.ini', 'settings', null, null, false, true)->variable('AliasSettings', 'AliasList') as $defaultSettingAlias) { if (!in_array($defaultSettingAlias, $aliases)) { $aliases[] = $defaultSettingAlias; } } // Optional debug output if ($executionOptions['troubleshoot'] && $executionOptions['verboseLevel'] >= 2 && !$executionOptions['iterate']) { self::displayMessage('All siteaccess ' . "'" . $relatedSiteAccess . "'" . ' image.ini:[AliasSettings] AliasList[] image aliases defined'); print_r($aliases); self::displayMessage('', "\n"); } } } } } } else { // Parameter image alias to create $createAliases = $aliases; } } // Optional debug output if ($executionOptions['troubleshoot'] && $executionOptions['verboseLevel'] >= 2) { self::displayMessage('All related siteaccess image.ini:[AliasSettings] AliasList[] image aliases defined:'); print_r($createAliases); self::displayMessage('', "\n"); } // Don't try to create original image alias unset($createAliases['original']); // Default datatypes to create image alias variations $imageDataTypeStrings = eZINI::instance('bcimagealias.ini')->variable('BCImageAliasSettings', 'ImageDataTypeStringList'); // Check that content object attribute data type string matches allowed datatype settings if (!in_array($contentObjectAttribute->attribute('data_type_string'), $imageDataTypeStrings) || !$contentObjectAttribute->attribute('has_content')) { return false; } // Fetch content object attribute content the image alias handler object $imageHandler = $contentObjectAttribute->content(); // Fetch eZImageManager instance $imageManager = eZImageManager::factory(); // Fetch all related siteaccess image.ini:[AliasSettings] AliasList[] image aliases defined if (is_array($relatedSiteAccesses) && !$executionOptions['current-siteaccess'] && !$executionOptions['iterate']) { // Fetch all default image aliases for imageManager // $imageManager->readImageAliasesFromINI( 'settings/image.ini' ); // Fetch all siteaccess image aliases for imageManager foreach ($relatedSiteAccesses as $relatedsiteaccess) { $relatedSiteaccessImageINIFileFolder = 'settings/siteaccess/' . $relatedsiteaccess; $relatedSiteaccessImageINIFile = $relatedSiteaccessImageINIFileFolder . '/image.ini.append.php'; if (file_exists($relatedSiteaccessImageINIFile)) { // $imageManager->readImageAliasesFromOverrideINI( 'image.ini.append.php', $relatedSiteaccessImageINIFileFolder ); $imageManager->readImageAliasesFromOverrideINI($relatedsiteaccess, 'image.ini'); } } // Optional debug output if ($executionOptions['troubleshoot'] && $executionOptions['verboseLevel'] >= 2) { self::displayMessage("\n" . 'Image manager image aliases', "\n"); print_r(array_keys($imageManager->AliasList)); } } elseif (!$executionOptions['current-siteaccess'] && $executionOptions['iterate']) { $imageManager->readImageAliasesFromOriginalINI('image.ini'); } // Fetch the image alias handler object's alias list $aliasList = $imageHandler->aliasList(); $original = $aliasList['original']; $basename = $original['basename']; // Optional debug output if ($executionOptions['troubleshoot']) { if ($executionOptions['verboseLevel'] >= 4) { self::displayMessage('Current content object image attribute image alias list entries within attribute handler content:', "\n"); print_r($imageHandler->ContentObjectAttributeData['DataTypeCustom']['alias_list']); self::displayMessage('', "\n\n"); } elseif ($executionOptions['verboseLevel'] >= 3) { self::displayMessage('Current content object image attribute image alias list entries within attribute handler content:', "\n"); print_r(array_keys($imageHandler->ContentObjectAttributeData['DataTypeCustom']['alias_list'])); self::displayMessage('', "\n\n"); } else { self::displayMessage('', "\n"); } self::displayMessage('Number of ini image aliases: ' . count($createAliases), "\n\n"); } // Initialize alias foreach counter at one, 1 $aliasCounter = 1; // Iterate through image alias list from settings foreach ($createAliases as $aliasItem) { // Test $aliasItem from $createAliases is in $aliases array if ($aliases != false && is_array($aliases) && !in_array($aliasItem, $aliases)) { continue; } // Optional debug output if ($executionOptions['troubleshoot']) { self::displayMessage('Iteration ' . $aliasCounter . ' of ' . count($createAliases) . ' | Preparing to attempt to create the "' . $aliasItem . '" image alias variation', "\n"); } // Store a temporary record of the alias not yet created this iteration $result[$aliasItem] = false; // Iterate alias foreach counter $aliasCounter++; /** * Test image alias exists according to imageManager */ if (!$imageManager->hasAlias($aliasItem)) { // Optional debug output if ($executionOptions['troubleshoot']) { self::displayMessage("\n" . 'eZImageManger claims: ' . '"' . $aliasItem . '"' . ' does not exist in system', "\n\n"); } continue; } // Skip generating aliases which already exist if force option is false if (isset($aliasList[$aliasItem]) && !$executionOptions['regenerate']) { continue; } // Skip generation if force is not true and dry is true if (!$executionOptions['regenerate'] && $executionOptions['dry']) { // Optional debug output if ($executionOptions['troubleshoot']) { // Alert user of dry alias calculation $message = "Dry run: Calculating generation of datatype " . $contentObjectAttribute->attribute('data_type_string') . "type image alias " . '"' . $aliasItem . '"' . ' image variation' . "\n"; self::displayMessage($message); } continue; } // Create $aliasItem the image alias image variation image file on disk immediately if ($imageManager->createImageAlias($aliasItem, $aliasList, array('basename' => $basename))) { // Optional debug output if ($executionOptions['troubleshoot'] && $executionOptions['verboseLevel'] >= 3) { self::displayMessage('Specific alias added to aliasList (in attribute):'); print_r($aliasList[$aliasItem]); self::displayMessage('', "\n"); } // Store a record of the alias created this iteration $result[$aliasItem] = true; // Uncomment the following line to write a error log entry (for debug) // error_log( __CLASS__ . __METHOD__ . ": Created alias $aliasItem" ); } else { // Store a record of the alias not created this iteration $result[$aliasItem] = false; // Uncomment the following line to write a error log entry (for debug) // error_log( __CLASS__ . __METHOD__ . ": Fail creating alias $aliasItem" ); } // Optional debug output if ($executionOptions['troubleshoot'] && $executionOptions['verboseLevel'] >= 3) { self::displayMessage('Leaving create image alias if block'); self::displayMessage('Looping to next image alias from ini settings', "\n"); } } $aliasesCreated = array_keys($result, true); $aliasesCreatedCount = count($aliasesCreated); // Only prepare alias meta data when alias(s) have been created if (is_array($result) && in_array(true, array_keys($result, true))) { $aliasAlertnativeText = $imageHandler->displayText(isset($original['alertnative_text']) ? $original['alertnative_text'] : ''); $aliasOriginalFilename = $original['original_filename']; self::displayMessage('', "\n"); foreach ($aliasList as $aliasKey => $aliasListItem) { if ($aliases != false && is_array($aliases) && !in_array($aliasKey, $aliases)) { continue; } // Test for newly added alias // if( ( !isset( $aliasListItem['is_new'] ) or $aliasListItem['is_new'] == '' ) && $executionOptions[ 'regenerate' ] ) if ($executionOptions['regenerate']) { $aliasListItem['is_new'] = true; $aliasListItem['is_valid'] = true; } // Prepare meta data $aliasListItem['original_filename'] = $aliasOriginalFilename; $aliasListItem['text'] = $aliasAlertnativeText; // Test for alias file url and add meta data if ($aliasListItem['url']) { $aliasListItemFile = eZClusterFileHandler::instance($aliasListItem['url']); if ($aliasListItemFile->exists()) { $aliasListItem['filesize'] = $aliasListItemFile->size(); } } // Test for newly added alias if ($aliasListItem['is_new']) { eZImageFile::appendFilepath($imageHandler->ContentObjectAttributeData['id'], $aliasListItem['url']); } // Add alias image variation image file meta data back into aliasList $aliasList[$aliasKey] = $aliasListItem; // Track successful generation attempts if (isset($result[$aliasKey]) && $result[$aliasKey]) { $results[] = true; $message = "Created datatype " . $contentObjectAttribute->attribute('data_type_string') . "type image alias " . '"' . $aliasListItem['name'] . '"' . " image variation " . $aliasListItem['url']; self::scriptIterate($message, "\n"); } elseif (!isset($result[$aliasKey])) { $results[] = true; } else { $results[] = false; } } /** * Note: The following code replaces the use of this example private method unavailable at the time of publishing * * $imageHandler->setAliasList( $aliasList ); */ $imageHandler->ContentObjectAttributeData['DataTypeCustom']['alias_list'] = $aliasList; $imageHandler->addImageAliases($aliasList); // Optional debug output if ($executionOptions['troubleshoot'] && $executionOptions['verboseLevel'] >= 3) { self::displayMessage('Created image alias list array:'); print_r($aliasList); self::displayMessage('', "\n\n"); self::displayMessage('Created image alias handler object:'); print_r($imageHandler); self::displayMessage('', "\n\n"); } } // Optional debug output if ($executionOptions['troubleshoot']) { self::displayMessage("\n" . 'Content object attribute image alias image variation generation attempts completed', "\n\n"); $coaID = $contentObjectAttribute->attribute('id'); $coaVersion = (int) $contentObjectAttribute->attribute('version'); $contentObjectAttributeRefetched = eZContentObjectAttribute::fetch($coaID, $coaVersion); if ($executionOptions['verboseLevel'] >= 3) { self::displayMessage('Displaying saved re-feched data_text of attribute image handler. You should see this list fully populated with all created image alias file urls'); print_r($contentObjectAttributeRefetched->attribute('content')->aliasList()); self::displayMessage('', "\n"); $objectLookup = eZContentObject::fetch($contentObjectAttribute->attribute('contentobject_id')); $objectLookupDM = $objectLookup->dataMap(); self::displayMessage('Displaying saved re-feched object attribute aliasList from image handler. You should see this list fully populated with all created image alias file urls'); print_r($objectLookupDM['image']->content()->aliasList(true)); self::displayMessage('', "\n"); } if ($executionOptions['verboseLevel'] >= 3 && !$executionOptions['iterate']) { self::displayMessage('Here are the content object image attribute image alias generation attempt results:'); self::displayMessage('Created aliases will show up as a 1. Theses results do not affect workflow completion as image aliases will not always be created', "\n"); print_r($result); self::displayMessage('', "\n"); } elseif ($executionOptions['verboseLevel'] >= 2 && $executionOptions['iterate']) { self::displayMessage('Here are the content object image attribute image alias generation attempt results:'); self::displayMessage('Created aliases will show up as a 1. Theses results do not affect workflow completion as image aliases will not always be created', "\n"); print_r($result); self::displayMessage('', "\n"); } } // Calculate return results based on execution options and results comparison if (in_array(true, $results) && count($createAliases) == count($result) && !$executionOptions['dry'] && $executionOptions['regenerate']) { // Optional debug output if ($executionOptions['troubleshoot']) { self::displayMessage('Creation attempts calculate as successful, at least once. All aliases possible attempted'); self::displayMessage('Variation images created: ' . $aliasesCreatedCount . ' out of ' . count($result), "\n"); } return true; } elseif (in_array(true, $results) && !$executionOptions['dry'] && !$executionOptions['regenerate']) { // Optional debug output if ($executionOptions['troubleshoot']) { self::displayMessage('Creation attempts calculate as successful, at least once. All aliases possible attempted', "\n\n"); self::displayMessage('Variations images created: ' . $aliasesCreatedCount . ' out of ' . count($result), "\n\n"); } return true; } return false; }
/** * Image manager instance * * @package kernel * @deprecated Deprecated as of 4.3, use {@link eZImageManager::factory()} instead. */ function imageInit() { eZDebug::writeStrict( 'Function imageInit() has been deprecated in 4.3 in favor of eZImageManager::factory()', 'Deprecation' ); return eZImageManager::factory(); }
/** * Image manager instance * * @package kernel * @deprecated Deprecated as of 4.3, use {@link eZImageManager::factory()} instead. */ function imageInit() { return eZImageManager::factory(); }