Changeset 4998 for extensions/AMetaData
- Timestamp:
- Feb 28, 2010, 6:15:11 PM (14 years ago)
- Location:
- extensions/AMetaData/JpegMetaData
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/AMetaData/JpegMetaData/JpegMetaData.class.php
r4935 r4998 113 113 114 114 require_once(JPEG_METADATA_DIR."Readers/JpegReader.class.php"); 115 require_once(JPEG_METADATA_DIR."TagDefinitions/MagicTags.class.php"); 115 116 116 117 class JpegMetaData … … 123 124 const KEY_EXIF_EXIF = "exif.exif"; 124 125 const KEY_EXIF_GPS = "exif.gps"; 125 const KEY_EXIF = "exif"; 126 const KEY_IPTC = "iptc"; 127 const KEY_XMP = "xmp"; 126 const KEY_EXIF = "exif"; 127 const KEY_IPTC = "iptc"; 128 const KEY_XMP = "xmp"; 129 const KEY_MAGIC = "magic"; 128 130 129 131 private $jpeg = null; … … 157 159 * xmp | 158 160 * maker | maker => returns specifics tags from all the known 159 * 161 * magic | makers 160 162 * | 161 163 * ---------------------+--------------------------------------------------- … … 180 182 'iptc' => true, 181 183 'xmp' => true, 182 'maker' => true 184 'maker' => true, 185 'magic' => true, 183 186 ); 184 187 … … 211 214 $list[]="xmp"; 212 215 216 if($default['magic']) 217 $list[]="magic"; 218 213 219 foreach($list as $val) 214 220 { … … 232 238 $tmp=new XmpTags(); 233 239 $schema="xmp"; 240 break; 241 case "magic": 242 $tmp=new MagicTags(); 243 $schema="magic"; 234 244 break; 235 245 case MAKER_PENTAX: … … 281 291 } 282 292 } 293 294 ksort($returned); 283 295 284 296 return($returned); … … 332 344 * iptc | If set to true, the function returns all the tags 333 345 * xmp | known for the specified type tag 334 * 346 * magic | the exif parameter include the maker tags 335 347 * | 336 348 * ---------------------+--------------------------------------------------- … … 404 416 } 405 417 } 418 419 if($this->options['magic']) 420 { 421 $this->processMagicTags(); 422 } 423 424 ksort($this->tags); 406 425 } 407 426 } … … 468 487 'filter' => self::TAGFILTER_ALL, 469 488 'optimizeIptcDateTime' => false, 470 'exif' => true, 471 'iptc' => true, 472 'xmp' => true 489 'exif' => true, 490 'iptc' => true, 491 'xmp' => true, 492 'magic' => true 473 493 ); 474 494 … … 552 572 } 553 573 574 /** 575 * MagicTags are build with this function 576 */ 577 private function processMagicTags() 578 { 579 $magicTags=new MagicTags(); 580 581 foreach($magicTags->getTags() as $key => $val) 582 { 583 $tag=new Tag($key,0,$key); 584 585 for($i=0; $i<count($val['tagValues']); $i++) 586 { 587 $found=true; 588 preg_match_all('/{([a-z0-9:\.\s\/]*)(\[.*\])?}/i', $val['tagValues'][$i], $returned, PREG_PATTERN_ORDER); 589 foreach($returned[1] as $testKey) 590 { 591 $found=$found & array_key_exists($testKey, $this->tags); 592 } 593 if(count($returned[1])==0) $found=false; 594 595 if($found) 596 { 597 $returned=trim(preg_replace_callback( 598 '/{([a-z0-9:\.\s\/\[\]]*)}/i', 599 Array(&$this, "processMagicTagsCB"), 600 $val['tagValues'][$i] 601 )); 602 603 $tag->setValue($returned); 604 $tag->setLabel($returned); 605 $tag->setKnown(true); 606 $tag->setImplemented($val['implemented']); 607 $tag->setTranslatable($val['translatable']); 608 609 $i=count($val['tagValues']); 610 } 611 } 612 613 if($tag->isImplemented() and $found) 614 { 615 $this->tags["magic.".$key]=$tag; 616 } 617 618 unset($tag); 619 } 620 unset($magicTags); 621 } 622 623 /** 624 * this function is called by the processMagicTags to replace tagId by the 625 * tag values 626 * 627 * @param Array $matches : array[1] = the tagId 628 * @return String : the tag value 629 */ 630 private function processMagicTagsCB($matches) 631 { 632 $label=""; 633 preg_match_all('/([a-z0-9:\.\s\/]*)\[(.*)\]/i', $matches[1], $result, PREG_PATTERN_ORDER); 634 if(count($result[0])>0) 635 { 636 637 if(array_key_exists($result[1][0], $this->tags)) 638 { 639 $tag=$this->tags[$result[1][0]]->getLabel(); 640 641 preg_match_all('/([a-z0-9:\.\s\/]*)\[(.*)\]/i', $result[2][0], $result2, PREG_PATTERN_ORDER); 642 643 if(count($result2[0])>0) 644 { 645 if(array_key_exists($result2[2][0], $tag[$result2[1][0]] )) 646 $label=$tag[$result2[1][0]][$result2[2][0]]; 647 } 648 else 649 { 650 if(array_key_exists($result[2][0], $tag)) 651 $label=$tag[$result[2][0]]; 652 } 653 } 654 } 655 else 656 { 657 if(array_key_exists($matches[1], $this->tags)) 658 { 659 $label=$this->tags[$matches[1]]->getLabel(); 660 } 661 } 662 663 if($label instanceof DateTime) 664 return($label->format("Y-m-d H:i:s")); 665 666 $label=XmpTags::getAltValue($label, L10n::getLanguage()); 667 668 if(is_array($label)) 669 return(implode(", ", $label)); 670 671 return(trim($label)); 672 } 673 674 675 676 /** 677 * used by the destructor to clean variables 678 */ 554 679 private function unsetAll() 555 680 { -
extensions/AMetaData/JpegMetaData/Readers/IfdReader.class.php
r4904 r4998 496 496 $returned=Array( 497 497 "computed" => (isset($tag['tagValues.computed'][$values])?$tag['tagValues.computed'][$values]:"unknown"), 498 "detail" => Array() ); 499 foreach($tag['tagValues.specialNames'] as $key => $value) 500 { 501 $filter = $values & $key; 502 if(isset($tag['tagValues.specialValues'][$key][$filter])) 503 $returned["detail"][]=$tag['tagValues.specialValues'][$key][$filter]; 504 else 505 $returned["detail"][]="unknown"; 506 } 498 "detail" => Array() 499 ); 500 501 $value=$values & 0x0001; 502 $returned["detail"][]=$tag['tagValues.specialValues'][0x0001][$value]; 503 504 $value=($values & 0x0006)>>1; 505 $returned["detail"][]=$tag['tagValues.specialValues'][0x0006][$value]; 506 507 $value=($values & 0x0018)>>3; 508 $returned["detail"][]=$tag['tagValues.specialValues'][0x0018][$value]; 509 510 $value=($values & 0x0020)>>5; 511 $returned["detail"][]=$tag['tagValues.specialValues'][0x0020][$value]; 512 513 $value=($values & 0x0040)>>6; 514 $returned["detail"][]=$tag['tagValues.specialValues'][0x0040][$value]; 515 507 516 break; 508 517 case 0x920A: // FocalLength, tag 0x920A -
extensions/AMetaData/JpegMetaData/Readers/PentaxReader.class.php
r4931 r4998 148 148 case 0x000c: // "Flash", 149 149 $tag=$this->tagDef->getTagById(0x000c); 150 $returned= "";150 $returned=Array(); 151 151 if(array_key_exists($values[0], $tag['tagValues.special'][0])) 152 $returned .=$tag['tagValues.special'][0][$values[0]];152 $returned[]=$tag['tagValues.special'][0][$values[0]]; 153 153 if(array_key_exists($values[1], $tag['tagValues.special'][1])) 154 $returned .=";".$tag['tagValues.special'][1][$values[1]];154 $returned[]=";".$tag['tagValues.special'][1][$values[1]]; 155 155 unset($tag); 156 156 break; -
extensions/AMetaData/JpegMetaData/TagDefinitions/IfdTags.class.php
r4935 r4998 977 977 // flash, tag 0x9209, see EXIF 2.2 documentation 978 978 0x9209 => Array( 979 'tagName' => " flash",979 'tagName' => "Flash", 980 980 'schema' => "exif", 981 981 'translatable'=> true, … … 990 990 ), 991 991 'tagValues.specialValues' => Array( 992 0x000 0 => Array( // b00000001992 0x0001 => Array( // b00000001 => 'fired' 993 993 0x00 => "flash did not fire", 994 994 0x01 => "flash fired" 995 995 ), 996 0x0006 => Array( // b00000110 996 0x0006 => Array( // b00000110 => 'return' 997 997 0x00 => "no strobe", // 00 998 998 0x01 => "reserved", // 01 … … 1000 1000 0x03 => "strobe return light detected" // 11 1001 1001 ), 1002 0x0018 => Array( // b00011000 1002 0x0018 => Array( // b00011000 => 'mode' 1003 1003 0x00 => "unknown", 1004 1004 0x01 => "compulsory flash firing", 1005 0x 10=> "compulsory flash suppression",1006 0x 11=> "auto mode"1005 0x02 => "compulsory flash suppression", 1006 0x03 => "auto mode" 1007 1007 ), 1008 0x0020 => Array( // b00100000 1008 0x0020 => Array( // b00100000 => 'function' 1009 1009 0x00 => "flash function present", 1010 1010 0x01 => "no flash function" 1011 1011 ), 1012 0x0040 => Array( // b01000000 1012 0x0040 => Array( // b01000000 => 'red-eye' 1013 1013 0x00 => "no red-eye reduction mode or unknown", 1014 1014 0x01 => "red-eye reduction supported" -
extensions/AMetaData/JpegMetaData/TagDefinitions/XmpTags.class.php
r4972 r4998 48 48 class XmpTags extends KnownTags 49 49 { 50 /** 51 * this function extract from an Xmp Alt structure, the value in the given 52 * lang 53 * 54 * @param Array $tagValues : 55 * @param String $lang : the needed lang 56 * @return String : the value in the specified lang, or in the default lang 57 * if there is no specific value for the specified lang 58 */ 59 static public function getAltValue($tagValues, $lang="x-default") 60 { 61 /* 62 * test if the $tagValues is valid, otherwise return the $tagValues as 63 * result 64 */ 65 if(!is_array($tagValues)) return($tagValues); 66 if(!array_key_exists("type", $tagValues) or 67 !array_key_exists("values", $tagValues) ) 68 return($tagValues); 69 if($tagValues['type']!="alt") return($tagValues); 70 71 $returned=""; 72 foreach($tagValues['values'] as $key => $val) 73 { 74 if($val['type']['value']==$lang or 75 XmpTags::lang($val['type']['value'])==$lang or 76 $val['type']['value']=="x-default") 77 $returned=$val['value']; 78 } 79 return($returned); 80 } 81 82 /** 83 * this function tries to format the lang Id 84 * something like "fr-fr" is returned as "fr_FR" 85 */ 86 static private function lang($lang) 87 { 88 $result=preg_match("/([a-z]*)([-|_])([a-z]*)/i", $lang, $arr); 89 return($arr[1]."_".strtoupper($arr[3])); 90 } 91 50 92 const TYPE_SIMPLE = 0x00; 51 93 const TYPE_SEQ = 0x01; … … 1308 1350 /* 1309 1351 * The Flash is a sequence of Flash structure 1310 * Not yet implemented 1352 * Don't use the exif:Flash, but the associated tags : 1353 * exif:Fired, exif:Return, exif:Mode, exif:Function, exif:RedEyeMode 1311 1354 */ 1312 1355 'exif:Flash' => Array( … … 1317 1360 'schema' => "exif", 1318 1361 ), 1362 1363 'exif:Fired' => Array( 1364 'implemented' => true, 1365 'translatable' => true, 1366 'type' => self::TYPE_SIMPLE, 1367 'schema' => "exif", 1368 'tagValues' => Array( 1369 'False' => "flash did not fire", 1370 'True' => "flash fired" 1371 ), 1372 ), 1373 1374 'exif:Return' => Array( 1375 'implemented' => true, 1376 'translatable' => true, 1377 'type' => self::TYPE_SIMPLE, 1378 'schema' => "exif", 1379 'tagValues' => Array( 1380 0x00 => "no strobe", 1381 0x01 => "reserved", 1382 0x02 => "strobe return light not detected", 1383 0x03 => "strobe return light detected" 1384 ), 1385 ), 1386 1387 'exif:Mode' => Array( 1388 'implemented' => true, 1389 'translatable' => true, 1390 'type' => self::TYPE_SIMPLE, 1391 'schema' => "exif", 1392 'tagValues' => Array( 1393 0x00 => "unknown", 1394 0x01 => "compulsory flash firing", 1395 0x02 => "compulsory flash suppression", 1396 0x03 => "auto mode" 1397 ), 1398 ), 1399 1400 'exif:Function' => Array( 1401 'implemented' => true, 1402 'translatable' => true, 1403 'type' => self::TYPE_SIMPLE, 1404 'schema' => "exif", 1405 'tagValues' => Array( 1406 'False' => "flash function present", 1407 'True' => "no flash function" 1408 ), 1409 ), 1410 1411 'exif:RedEyeMode' => Array( 1412 'implemented' => true, 1413 'translatable' => true, 1414 'type' => self::TYPE_SIMPLE, 1415 'schema' => "exif", 1416 'tagValues' => Array( 1417 'False' => "no red-eye reduction mode or unknown", 1418 'True' => "red-eye reduction supported" 1419 ), 1420 ), 1421 1319 1422 'exif:FocalLength' => Array( 1320 1423 'exifTag' => 0x920A,
Note: See TracChangeset
for help on using the changeset viewer.