/** * Open an image file for XMP data extraction. * * @param $file * File path. * * @return * Array with XMP file and metadata. */ function openXMP($file) { // Setup. SXMPFiles::Initialize(); $xmpfiles = new SXMPFiles(); $xmpmeta = new SXMPMeta(); // Open. $xmpfiles->OpenFile($file); // Get XMP metadata into the object. if ($xmpfiles->GetXMP($xmpmeta)) { // Sort metadata. $xmpmeta->Sort(); return array('files' => $xmpfiles, 'meta' => $xmpmeta); } // No XMP data available. return FALSE; }
/** * Read XMP data from an image file. * * @param $file * File path. * * @param $arTagNames * Available metadata fields. * * @return * XMP image metadata. * * @todo * Support for different array keys. */ public function readXMPTags($file, $enable_sections = TRUE) { SXMPFiles::Initialize(); // Get all available XMP tags and XMP data provided by current file $xmpTags = $this->getXMPFields(); $xmp = $this->openXMP($file); $info = array(); if ($xmp != FALSE) { // Iterate over XMP fields defined by CCK. foreach ($xmpTags as $tagName => $tag) { // Get XMP field. $config = $tag; $field = $this->readXMPItem($xmp, $config); $info[$tagName] = $field; } $this->closeXMP($xmp); } SXMPFiles::Terminate(); if ($enable_sections) { return array('xmp' => $info); } else { return $info; } }