예제 #1
0
 /**
  * Have a high offset to simulate a missing packet,
  * which should cause it to ignore the ExtendedXMP packet.
  *
  * @covers XMPReader::parseExtended
  */
 public function testExtendedXMPMissingPacket()
 {
     $xmpPath = __DIR__ . '/../../data/xmp/';
     $standardXMP = file_get_contents($xmpPath . 'xmpExt.xmp');
     $extendedXMP = file_get_contents($xmpPath . 'xmpExt2.xmp');
     $md5sum = '28C74E0AC2D796886759006FBE2E57B7';
     // of xmpExt2.xmp
     $length = pack('N', strlen($extendedXMP));
     $offset = pack('N', 2048);
     $extendedPacket = $md5sum . $length . $offset . $extendedXMP;
     $reader = new XMPReader();
     $reader->parse($standardXMP);
     $reader->parseExtended($extendedPacket);
     $actual = $reader->getResults();
     $expected = array('xmp-exif' => array('DigitalZoomRatio' => '0/10', 'Flash' => 9));
     $this->assertEquals($expected, $actual);
 }
예제 #2
0
 /** Main entry point for jpeg's.
  *
  * @param string $filename filename (with full path)
  * @return array metadata result array.
  * @throws MWException on invalid file.
  */
 static function Jpeg($filename)
 {
     $showXMP = function_exists('xml_parser_create_ns');
     $meta = new self();
     $seg = JpegMetadataExtractor::segmentSplitter($filename);
     if (isset($seg['COM']) && isset($seg['COM'][0])) {
         $meta->addMetadata(array('JPEGFileComment' => $seg['COM']), 'native');
     }
     if (isset($seg['PSIR']) && count($seg['PSIR']) > 0) {
         foreach ($seg['PSIR'] as $curPSIRValue) {
             $meta->doApp13($curPSIRValue);
         }
     }
     if (isset($seg['XMP']) && $showXMP) {
         $xmp = new XMPReader();
         $xmp->parse($seg['XMP']);
         foreach ($seg['XMP_ext'] as $xmpExt) {
             /* Support for extended xmp in jpeg files
              * is not well tested and a bit fragile.
              */
             $xmp->parseExtended($xmpExt);
         }
         $res = $xmp->getResults();
         foreach ($res as $type => $array) {
             $meta->addMetadata($array, $type);
         }
     }
     if (isset($seg['byteOrder'])) {
         $meta->getExif($filename, $seg['byteOrder']);
     }
     return $meta->getMetadataArray();
 }